网站导航网学 原创论文 原创专题 网站设计 最新系统 原创论文 论文降重 发表论文 论文发表 UI设计定制 论文答辩PPT格式排版 期刊发表 论文专题
返回网学首页
网学原创论文
最新论文 推荐专题 热门论文 论文专题
当前位置: 网学 > 交易代码 > ASP精品代码 > 正文

一个ASP(JScript)简单SQL语句构建“类”

论文降重修改服务、格式排版等 获取论文 论文降重及排版 论文发表 相关服务

  <%@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 += "(" + Fields.toString() + ") VALUES(" + Values.toString() + ")";

  }else{

  strTemp = getError(2);

  }

  }else{

  strTemp = getError(0); // 要求输入表名

  }

  return strTemp;

  break;

  }

  };

  var processValue = function(unknow){

  var inputType = typeof(unknow);

  switch(inputType){

  case "string":

  return "'"+unknow+"'";

  break;

  case "number":

  return unknow;

  break;

  case "boolean":

  return unknow;

  break;

  }

  };

  var processField = function(unknow){

  return "["+unknow+"]";

  };

  var process = function(aField,aValue){

  var aTemp = [];

  for(i=0;i<aField.length;i++){

  aTemp.push(aField[i]+"="+aValue[i]);

  }

  return aTemp.toString();

  }

  var getError = function(intError){

  if(typeof(intError)=="number"){

  switch(intError){

  case 0:

  State = false;

  return "Need Quest TableName, Please using method Table input one TableName!";

  break;

  case 1:

  State = false;

  return "Need One Condition! Please using method addCField add Condition!";

  break;

  case 2:

  State = false;

  return "Need Insert values!";

  break;

  }

  }

  };

  };

  var sql = new QuestStringBuilder();

  sql.Table("MyTable");

  sql.addField("Test","1");

  sql.addField("test1",23);

  sql.addCField("id",93);

  sql.PKey("id");

  sql.PKeyDesc();

  //sql.clear();

  Response.Write(sql.getDelete()+"<br>"+sql.ActionState());

  %>

  • 下一篇资讯: ASP在线发E-mail的2个函数
  • 设为首页 | 加入收藏 | 网学首页 | 原创论文 | 计算机原创
    版权所有 网学网 [Myeducs.cn] 您电脑的分辨率是 像素
    Copyright 2008-2020 myeducs.Cn www.myeducs.Cn All Rights Reserved 湘ICP备09003080号 常年法律顾问:王律师