本文实例讲述了javascript封装的sqlite操作类。分享给大家供大家参考。具体如下:
sql(name,v,desc,size,tables){
this.db=null;
this.name=name;
this.v=v;
this.desc=desc;
this.size=size;
this.tables=tables;
this.ini();
}
sql.prototype.ini=function(){
var self=this;
self.db=openDatabase(self.name,self.v,self.desc,self.size);
self.db.transaction(function(tx){
self.tables.forEach(function(s){
tx.executesql(s,[]);
});
});
};
sql.prototype.query=function(sql,opt,rs,err){
var opt=opt || [];
var rs =rs || function(){};
var err=err || function(tx,e){G.alert(e.message);};
this.db.transaction(function(tx){
if(typeof(sql)=='object'){
sql.forEach(function(s){
tx.executesql(s,err);
});
}else{
tx.executesql(sql,err);
}
});
};
demo:
sql('imdata'+z,'1.0','user data',1048576,tbs);
db.query('insert into cliao (id,uid,nr,ct,ty,ismy) values (?,?,?)',['afasdf','asdfa','saadf','eeee','rrrr',1]);
db.query('select * from cliao where uid=? order by ct desc limit ?,10',['22',50],function(tx,rs){
var l=rs.rows.length;
});
希望本文所述对大家的javascript程序设计有所帮助。
原文链接:/js/53370.html