sqliteUtil.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. var sqlite = {
  2. db: undefined,
  3. //开启数据库连接
  4. open: function(name, vesion, desc, size){
  5. sqlite.db = openDatabase( name, vesion, desc, size );
  6. return sqlite.db;
  7. },
  8. //执行语句
  9. executeSql: function( sql, params, successHandle, errorHandle ){
  10. sqlite.db.transaction(function(tx){
  11. tx.executeSql( sql, params, successHandle, errorHandle);
  12. })
  13. },
  14. //新增
  15. insert: function(sql, list, successHandle, errorHandle){
  16. sqlite.db.transaction(function(tx){
  17. for(var i=0; i<list.length; i++){
  18. tx.executeSql( sql, list[i] , function(tx, rs){
  19. console.log(rs)
  20. }, function(tx, rs){
  21. console.log(rs)
  22. });
  23. }
  24. }, errorHandle, successHandle)
  25. },
  26. //删除
  27. delete: function( sql, params, successHandle, errorHandle ){
  28. sqlite.db.transaction(function(tx){
  29. tx.executeSql( sql, params, successHandle, errorHandle );
  30. })
  31. },
  32. //查询
  33. search: function( sql, params, successHandle, errorHandle ){
  34. sqlite.db.transaction(function(tx){
  35. tx.executeSql( sql, params, successHandle, errorHandle);
  36. })
  37. }
  38. }