一個ASP(JScript)簡單SQL語句構建“類”,同時支援用戶端和伺服器端執行的

來源:互聯網
上載者:User
js|jscript|伺服器|用戶端|語句|執行|js|jscript|伺服器|用戶端 <%@LANGUAGE="JAVASCRIPT" CODEPAGE="936"%>
<%
var QuestStringBuilder = function(){
// 1->查詢語句, 2->更新語句, 3->刪除語句, 4->插入語句
var QuestType = 0;
var Fields = [];
var Values = [];
var Condition;
var PK;
var PkeySort;
var TableName;
var State = false;
var CLogic = " AND ";
var COperator = "=";
this.addField = function(Field,Value){
Fields.push(processField(Field));
Values.push(processValue(Value));
};
this.addCField = function(CField,CValue){
var sTemp = [];
if(Condition!=undefined&&Condition!=""){ sTemp.push(Condition); }
if(COperator!="LIKE"){
sTemp.push(processField(CField)+COperator+processValue(CValue));
}else{
sTemp.push(processField(CField)+" LIKE '%"+CValue+"%'");
}
Condition = sTemp.join(CLogic);
if(Condition==""){ Condition=sTemp.toString();}
};
this.Table = function(s){TableName = s;};
this.PKey = function(s){PK = processField(s);};
this.PKeyAsc = function(){PkeySort="ASC";};
this.PKeyDesc = function(){PkeySort="DESC";};
this.getSelect = function(){
QuestType = 1;
return result();
};
this.getUpdate = function(){
QuestType = 2;
return result();
};
this.getDelete = function(){
QuestType = 3;
return result();
};
this.getInsert = function(){
QuestType = 4;
return result();
};
this.clear = function(){
Fields = [];
Values = [];
PK = undefined;
PkeySort = undefined;
TableName = undefined;
State = false;
};
this.ActionState = function(){ return State;};
this.ChangeLogic = function(s){ CLogic = " "+s.toUpperCase()+" ";};
this.ChangeOperator = function(s){COperator = s.toUpperCase();};
var result = function(){
var strTemp;
if(Fields.length==0) Fields.push("*");
switch(QuestType){
case 1:
if(TableName!=undefined&&TableName!=""){
strTemp = "SELECT " + Fields.toString() + " FROM " + TableName;
if(Condition!=undefined){ strTemp += " WHERE " + Condition;}
if(PkeySort!=undefined&&PK!=undefined){ strTemp += " ORDER BY " + PK + " " + PkeySort;}
State = true;
}else{
strTemp = getError(0); // 要求輸入表名
}
return strTemp;
break;
case 2:
if(TableName!=undefined&&TableName!=""){
strTemp = "UPDATE " + TableName + " SET " + process(Fields,Values) ;
if(Condition!=undefined){
State = true;
strTemp += " WHERE " + Condition;
}else{
strTemp = getError(1);
}
}else{
strTemp = getError(0); // 要求輸入表名
}
return strTemp;
break;
case 3:
if(TableName!=undefined&&TableName!=""){
strTemp = "DELETE FROM " + TableName ;
if(Condition!=undefined){
State = true;
strTemp += " WHERE " + Condition;
}else{
strTemp = getError(1);
}
}else{
strTemp = getError(0); // 要求輸入表名
}
return strTemp;
break;
case 4:
if(TableName!=undefined&&TableName!=""){
strTemp = "INSERT INTO " + TableName ;
if(Fields.length!=0){
State = true;
strTemp



相關文章

Beyond APAC's No.1 Cloud

19.6% IaaS Market Share in Asia Pacific - Gartner IT Service report, 2018

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。