1
我使用Cordova
創建了一個使用Sqlite
數據庫的Android項目。我的數據庫將是隻讀的,因爲只能使用從表中讀取數據。所以我的Sqlite
數據庫在用戶手機上安裝時必須包含一些數據。如何在Cordova Android項目中使用預填充的Sqlite數據庫
如何在我的.apk
文件中使用預填充的數據庫?
我使用Cordova
創建了一個使用Sqlite
數據庫的Android項目。我的數據庫將是隻讀的,因爲只能使用從表中讀取數據。所以我的Sqlite
數據庫在用戶手機上安裝時必須包含一些數據。如何在Cordova Android項目中使用預填充的Sqlite數據庫
如何在我的.apk
文件中使用預填充的數據庫?
添加插件
科爾多瓦插件添加https://github.com/millerjames01/Cordova-SQLitePlugin.git
HTML
<input id="show" type="button" value="Show">
JS
function globalError(tx, error)
{
alert("Error: " + error.message);
}
var db = window.openDatabase('TabOrder', '', 'Bar Tab Orders', 2500000);
db.transaction(function(tx) {
tx.executeSql('DROP TABLE IF EXISTS SubmiteData;', null, null, globalError);
tx.executeSql('CREATE TABLE IF NOT EXISTS SubmiteData (SubmiteDataId integer
primary key, UserId text, AuthNo number, LocId number,ProdId number,
CardId number, OrgLat text, OrgLng text, OrgTime text)',
null,
function()
{
SubmiteData("USER1",12345678,23434, 21212, 220232,
"9", "45", "23/06/2014");
},
globalError);
});
function SubmiteData(UserId, AuthNo, LocId,ProdId, CardId, OrgLat, OrgLng, OrgTime){
db.transaction(function(tx){
tx.executeSql('INSERT INTO SubmiteData(UserId, AuthNo, LocId, ProdId, CardId,
OrgLat, OrgLng, OrgTime) VALUES (?,?,?,?,?,?,?,?)', [UserId, AuthNo, LocId,
ProdId, CardId, OrgLat, OrgLng, OrgTime],
null,
globalError
);
});
}
function read(UserId, AuthNo, LocId,ProdId, CardId, OrgLat, OrgLng, OrgTime){
db.transaction(function(tx) {
tx.executeSql('SELECT * FROM SubmiteData',
[],
function(tx, results)
{
for (var i=0; i<results.rows.length; i++)
{
var row=results.rows.item(i);
// alert("Id: " + row['UserId']);
var stringout = "LocId: " + row['LocId'] + "\n";
alert(stringout);
}
},
globalError
);
});
};
$(function()
{
$('#show').click(read);
});
請不要重複答案,要麼將問題標記爲重複,要麼提供個別問題個別答案。 – Flexo 2014-11-17 10:26:05