<%
__header("Content-Type","text/html; charset=gb2312");
var serr="{\"op\":\"op err\"}";
if (op=="")
  write(serr);
else
{
var sql;
var iupd=-1;
db_Open("/NandFlash/dbCfg.db3");
if (op=="qry")
  db_QryAdv("select * from tbSM");
if (op=="qryby")
  db_QryAdv("select * from tbSM where SID="+sid);
if (op=="del")
{
  iupd=db_UpdAdv("delete from tbSM where SID="+sid);
  db_UpdAdv("delete from tbSMDefVal where SID="+sid);
}
if (op=="aid")
  iupd=db_UpdAdv("update tbSM set AID="+aid+" where SID="+sid);
if (op=="ins")
{
  sql = "insert into tbSM(Kind,Type,Name,Note,State,DataMode,SerKind,SerType,SerDef,SerAddr,AID,Tag1,Tag2,Ext1,Ext2,ASubSys)";
  sql = sql+" values("+kind+","+type+",'"+name+"','"+note+"',"+state+","+datamode+","+serkind+","+sertype;
  sql = sql+",'"+serdef+"',"+seraddr+",0,"+tag1+","+tag2+","+ext1+","+ext2+","+subsys+")";
  iupd=db_UpdAdv(sql,1);
}
if (op=="upd")
{
  sql = "update tbSM set Kind="+kind+",Type="+type+",Name='"+name+"',Note='"+note+"',State="+state;
  sql = sql+",DataMode="+datamode+",SerKind="+serkind+",SerType="+sertype+",SerDef='"+serdef+"',SerAddr="+seraddr;
  sql = sql+",Tag1="+tag1+",Tag2="+tag2+",Ext1="+ext1+",Ext2="+ext2+",ASubSys="+subsys+" where SID="+sid;
  iupd=db_UpdAdv(sql,1);
}

if (iupd<0 && iupd!=-1)
  write(serr);
if (iupd>=0)
{
  var lastId = db_QryLastRowId();
  write("{\"op\":\"ok\",\"sid\":"+lastId+"}");
}
db_Close();
}
%>