<%
__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")
{
  if (db_QryInt("SELECT COUNT(*) FROM sqlite_master where type='table' and name='tbCardDef'",1)==0)
	db_UpdAdv("create table tbCardDef(DID INTEGER PRIMARY KEY, Card INTEGER NOT NULL UNIQUE, Name VARCHAR(32) NOT NULL, Note VARCHAR(64), Mask1 INTEGER, Mask2 INTEGER, Mask3 INTEGER)", 1);
  db_QryAdv("select * from tbCardDef", 1);
}
if (op=="qry1")
{
  if (db_QryInt("SELECT COUNT(*) FROM sqlite_master where type='table' and name='tbCardDef'",1)==0)
	db_UpdAdv("create table tbCardDef(DID INTEGER PRIMARY KEY, Card INTEGER NOT NULL UNIQUE, Name VARCHAR(32) NOT NULL, Note VARCHAR(64), Mask1 INTEGER, Mask2 INTEGER, Mask3 INTEGER)", 1);
  db_QryAdv("select * from tbCardDef where Card="+card, 1);
}
else if (op=="del")
{
	iupd=db_UpdAdv("delete from tbCardDef where Card="+card);
}
else if (op=="upd")
{
  iupd=db_UpdAdv("update tbCardDef set Name="+name+", Note="+note+" where Card="+card,1);
}
else if (op=="add")
{
  if (db_QryInt("select count(*) from tbCardDef where Card="+card,1)==0)
    iupd=db_UpdAdv("insert into tbCardDef(Card, Name, Note, Mask1, Mask2, Mask3) values("+card+","+name+","+note+",0,0,0)", 1);
  else
    iupd=65535;
}

if (iupd<0 && iupd!=-1)
  write(serr);
else if (iupd==65535)
  write(serr);
else if (iupd>=0)
{
  write("{\"op\":\"ok\"}");
}
db_Close();
}
%>