简体   繁体   English

我是否必须在第一批sqlite db中创建所有表?

[英]Do I have to create all tables at first population of sqlite db?

I'm creating a Sqlite DB & I have many pages that I want to access the db from. 我正在创建一个Sqlite数据库,我有很多页面,我想从中访问数据库。

If I have a new table that I want to create do I have to execute the entire db again ? 如果我有一个我要创建的新表,我是否必须再次执行整个数据库?

And If I have a statement like (Delete, insert, ... ).. Can I just access the db from any where within the code & call the "db.executesql()" whenever I need it? 如果我有一个声明(删除,插入,...)..我可以从代码中的任何位置访问数据库并在需要时调用“db.executesql()”吗?

As PhoneGap's documentation at http://docs.phonegap.com/en/1.9.0/cordova_storage_storage.md.html#Storage says, you can do it this way: 正如http://docs.phonegap.com/en/1.9.0/cordova_storage_storage.md.html#Storage上的 PhoneGap文档所述,您可以这样做:

// Cordova is ready
function onDeviceReady() {
    var db = window.openDatabase("Database", "1.0", "Cordova Demo", 200000);
    db.transaction(populateDB, errorCB, successCB);
}

// Populate the database 
function populateDB(tx) {
     tx.executeSql('DROP TABLE IF EXISTS DEMO');
     tx.executeSql('CREATE TABLE IF NOT EXISTS DEMO (id unique, data)');
     tx.executeSql('INSERT INTO DEMO (id, data) VALUES (1, "First row")');
     tx.executeSql('INSERT INTO DEMO (id, data) VALUES (2, "Second row")');
}

// Transaction error callback
function errorCB(tx, err) {
    alert("Error processing SQL: "+err);
}

// Transaction success callback
function successCB() {
    alert("success!");
}

So, you will need to open the database first, and then execute sql, like in the example: 因此,您需要先打开数据库,然后执行sql,如下例所示:

var db = window.openDatabase("Database", "1.0", "Cordova Demo", 200000);
db.transaction(populateDB, errorCB, successCB);

For different purposes just create different functions with different sql execution code, just as populateDB above. 出于不同的目的,只需使用不同的sql执行代码创建不同的函数,就像上面的populateDB

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我想将长文本文档解析为一个SQLite数据库。 如何转义所有不受支持的字符? - I want to parse long text documents into an SQLite DB. How do I escape all unsupported characters? 使所有表的列具有与第一个表相同的宽度 - Make all tables' columns have the same widths as the first table's 禁用第一个表单并打开另一个表单以插入数据..我必须在同一页面上完成所有这些操作? - Disable first form and open another form to insert data.. all this i have to do in same page? 当我有一个空数组作为我的 check.bind 时,如何创建一个 select 全部复选框 - How do I create a select all checkbox when I have an empty array as my checked.bind 使用JQuery将XML解析为SQLite DB时出错:所有行都具有相同的值 - Error parsing XML into SQLite DB with JQuery: all rows have same values 如何在 Vue 中创建具有相同名称的 keep-alive 组件? - How do I create keep-alive components that all have the same name in Vue? 在Sqlite中创建表之前必须删除表吗? - Do I have to drop the table before creating it in Sqlite? 我第一次创建了spring maven项目css,js,图片没有加载我试过这里给出的所有解决方案仍然没有工作 - I have create spring maven project for the first time css,js,images are not loading i have tried all solutions given here still not working 当我需要 quick.db 时,我有一个 Better_sqlite3.node 错误 - I have a better_sqlite3.node error when i require quick.db 我如何遍历与多个表有关系的子表 - How do i traverse a children table that have relationship with multiple tables
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM