cordova sqlite
来源:互联网 发布:中国透析患者数据 编辑:程序博客网 时间:2024/06/08 16:02
感谢插件SQLitePlugin的提供者,插件地址:https://github.com/brodysoft/Cordova-SQLitePlugin。
下面是我的测试代码:
<!DOCTYPE html><html> <head> <meta charset="utf-8" /> <meta name="format-detection" content="telephone=no" /> <!-- WARNING: for iOS 7, remove the width=device-width and height=device-height attributes. See https://issues.apache.org/jira/browse/CB-4323 --> <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" /> <link rel="stylesheet" type="text/css" href="css/index.css" /> <meta name="msapplication-tap-highlight" content="no" /> <script type="text/javascript" src="cordova.js"></script> <script type="text/javascript" src="js/index.js"></script> <script type="text/javascript"> // Wait for Cordova to load document.addEventListener("deviceready", onDeviceReady, false); var db; // Cordova is ready function onDeviceReady() { //var db = window.sqlitePlugin.openDatabase("Database", "1.0", "Demo", -1); db = window.sqlitePlugin.openDatabase({name: "my.db"}); db.transaction(function(tx) { tx.executeSql('DROP TABLE IF EXISTS test_table'); tx.executeSql('CREATE TABLE IF NOT EXISTS test_table (id integer primary key, name text, age integer)'); }); db.transaction(function(tx) {//主键自增长 console.log("事务:begiin"); console.log("插入insert:begin"); tx.executeSql('INSERT INTO test_table (name, age) VALUES (?,?)',["john",26]); tx.executeSql('INSERT INTO test_table (name, age) VALUES (?,?)',["smith",27]); console.log("插入insert:end"); console.log("查询insert:begin"); tx.executeSql("select id,name,age from test_table", [], function(tx, res) { console.log("第一次:begiin"); for (var i = 0; i < res.rows.length; i++) { console.log("查看结果:第一次: id="+res.rows.item(i).id+"; name=" +res.rows.item(i).name + "; age=" + res.rows.item(i).age); } console.log("第一次:begiin"); }, function(e) { }); console.log("查询insert:end"); try{ jkdljlksjkld; }catch(e){ } tx.executeSql('update test_table set age=? where name=?',[266,"john"]); tx.executeSql('update test_table set age=? where name=?',[267,"smith"]); tx.executeSql("select id,name,age from test_table", [], function(tx, res) { for (var i = 0; i < res.rows.length; i++) { console.log("查看结果:第二次: id="+res.rows.item(i).id+"; name=" +res.rows.item(i).name + "; age=" + res.rows.item(i).age); } }, function(e) { }); console.log("事务:end"); }); // setTimeout(function(){ db.transaction(function(tx) { tx.executeSql("select id,name,age from test_table", [], function(tx, res) { console.log("最终次是否到达?begin"); for (var i = 0; i < res.rows.length; i++) { console.log("查看结果:最终次: id="+res.rows.item(i).id+"; name=" +res.rows.item(i).name + "; age=" + res.rows.item(i).age); } console.log("最终次是否到达?end"); }, function(e) { }); }); db.transaction(function(tx) { tx.executeSql('INSERT INTO test_table (id, name, age) VALUES (?,?,?)',[3,"帅哥",24]); tx.executeSql('INSERT INTO test_table (id, name, age) VALUES (?,?,?)',[4,"美女",23]); }); //},15000); } function selectMe(){ db.transaction(function(tx) { console.log("查看结果:db begin"); tx.executeSql("select id,name,age from test_table", [], function(tx, res) { for (var i = 0; i < res.rows.length; i++) { console.log("查看结果:db: id="+res.rows.item(i).id+"; name=" +res.rows.item(i).name + "; age=" + res.rows.item(i).age); } }, function(e) { }); console.log("查看结果:db end"); }); } </script> <title>sqlite</title> </head> <body> <header> 头 </header> <div class="content"> <input type="button" name="select" onclick="selectMe();" /> </div> <footer> 尾 </footer> </body></html>
0 0
- cordova sqlite
- cordova sqlite 手势密码
- cordova sqlite的链接
- Cordova 8 架构使用sqlite
- ionic添加cordova插件-SQLite
- cordova(phonegap)搭建和使用sqlite数据库
- cordova调用本地SQLite数据库的方法
- Cordova
- cordova
- Cordova
- Cordova
- cordova
- cordova
- Cordova
- Cordova
- cordova
- Cordova
- Cordova
- 通过音视频工程学习回调函数
- 工作要有“做好”的态度
- 查找低劣的SQL方法
- Jquery同时设置多个css的值
- 炎症性肠病
- cordova sqlite
- 地址的不同性与机器与程序的运行时间有关
- 在windows8中,不翻墙更新android sdk
- 基于NFS系统搭建discuz实现负载均衡
- JavaScript判断浏览器类型及版本
- 飞鸽传书源码分析-程序启动过程
- 工作要有“做好”的态度
- [leetcode]Single Number II 详解
- 如何实现在手指按下3秒后执行某个方法