An ASP (JSCRIPT) Simple SQL statement constructs a "class" that supports both client and server-side execution of the

Source: Internet
Author: User
Tags execution insert sql table name tostring client
Js|jscript| Server | client | statement | Execute |js|jscript| server | client <% @LANGUAGE = "JAVASCRIPT" codepage= "936"%>
<%
var queststringbuilder = function () {
1-> query statements, 2-> UPDATE statements, 3-> DELETE statements, 4-> INSERT statements
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); Enter table name required
}
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); Enter table name required
}
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); Enter table name required
}
return strtemp;
Break
Case 4:
if (tablename!=undefined&&tablename!= "") {
strtemp = "INSERT into" + tablename;
if (fields.length!=0) {
state = true;
strtemp



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.