This question is locked. New answers and comments are not allowed.
Hi,
I am having some trouble with SQLite on Android. For example the below works fine on the simulator and on iPhone/iPad but doesn't work on Android at all - I'm hoping it is something really dum that I am doing.
On device ready I open the database - then on a button press I create some tables (I then do alot more but have only posted the code for the first bit as this is where Android falls over). On Android the tables are created but it doesn't call the errorCB or the app.buildsuccessCB function at all so doesn't move onto the next step....
var app = global.app = global.app || {};
app.db = null;
// Wait for device API libraries to load
//
document.addEventListener("deviceready", onDeviceReady, false);
// device APIs are available
//
function onDeviceReady() {
app.application = new kendo.mobile.Application(document.body, {
layout: "tabstrip-layout",
loading: '<h1 class="loaderHeading">Loading...</h1>',
transition: 'slide',
skin:'flat'
});
navigator.splashscreen.hide();
app.showLoader("Initializing...");
app.openDb();
}
app.openDb = function() {
if(window.sqlitePlugin !== undefined) {
app.db = window.sqlitePlugin.openDatabase("DCS");
} else {
// For debugin in simulator fallback to native SQL Lite
console.log("Use built in SQL Lite");
app.db = window.openDatabase("DCS", "1.0", "DCS DB", 200000);
}
app.hideLoader();
}
app.onClickDoThis = function () {
app.showLoader("Initializing...");
app.db.transaction(app.buildDB, errorCB, app.buildsuccessCB);
}
app.buildDB = function(tx) {
tx.executeSql("CREATE TABLE IF NOT EXISTS connectionInfo(connectionState TEXT PRIMARY KEY, displayName TEXT, allowUpdate INT, show INT, dateLastUpdated DATETIME)");
console.log("Build Tables: categories");
tx.executeSql("CREATE TABLE IF NOT EXISTS categories(stk_SCID INT PRIMARY KEY, stk_CID INT, stk_SID INT, stk_Sector TEXT, stk_Category TEXT, stk_SubCategory TEXT, stk_Deleted INT, DateLastUpdated DATETIME)");
console.log("Build Tables: products");
tx.executeSql("CREATE TABLE IF NOT EXISTS products(stk_ItemNo TEXT PRIMARY KEY, stk_ItemDescription TEXT, stk_QtyPerPack INT, stk_Size TEXT, stk_Weight TEXT, stk_RSP TEXT, stk_PallQty INT, stk_LayQty INT, stk_Brand TEXT, stk_Sector INT, stk_Category INT, stk_SubCategory INT, stk_BarcodeOuter TEXT, stk_BarcodeInner TEXT, stk_BarcodeUnit TEXT, StockLevel INT, photo TEXT, stk_Deleted INT, stk_CoreRange TEXT, DateLastUpdated DATETIME, stk_Price REAL)");
console.log("Build Tables: customers");
tx.executeSql("CREATE TABLE IF NOT EXISTS customers(cus_AccountNo TEXT PRIMARY KEY, cus_AccountName TEXT, cus_ID INT, cus_Priceband INT, cus_Deleted INT, DateLastUpdated DATETIME, selectedAccount INT DEFAULT 0)");
console.log("Build Tables: deliveryAddresses");
tx.executeSql("CREATE TABLE IF NOT EXISTS deliveryAddresses(cus_DAID INT PRIMARY KEY, cus_AccountNo TEXT, cus_Description TEXT, cus_AddressLine1 TEXT, cus_AddressLine2 TEXT, cus_AddressLine3 TEXT, cus_AddressLine4 TEXT, cus_PostCode TEXT, cus_Sage200ID TEXT, cus_Deleted INT, DateLastUpdated DATETIME)");
console.log("Build Tables: priceBands");
tx.executeSql("CREATE TABLE IF NOT EXISTS priceBands(prb_ID TEXT PRIMARY KEY, stk_ItemNo TEXT, prb_Priceband INT, prb_CurrentPrice REAL, prb_NormalPrice REAL, prb_Deleted INT, DateLastUpdated DATETIME)");
}
app.buildsuccessCB = function() {
alert("successfull");
}
I am having some trouble with SQLite on Android. For example the below works fine on the simulator and on iPhone/iPad but doesn't work on Android at all - I'm hoping it is something really dum that I am doing.
On device ready I open the database - then on a button press I create some tables (I then do alot more but have only posted the code for the first bit as this is where Android falls over). On Android the tables are created but it doesn't call the errorCB or the app.buildsuccessCB function at all so doesn't move onto the next step....
var app = global.app = global.app || {};
app.db = null;
// Wait for device API libraries to load
//
document.addEventListener("deviceready", onDeviceReady, false);
// device APIs are available
//
function onDeviceReady() {
app.application = new kendo.mobile.Application(document.body, {
layout: "tabstrip-layout",
loading: '<h1 class="loaderHeading">Loading...</h1>',
transition: 'slide',
skin:'flat'
});
navigator.splashscreen.hide();
app.showLoader("Initializing...");
app.openDb();
}
app.openDb = function() {
if(window.sqlitePlugin !== undefined) {
app.db = window.sqlitePlugin.openDatabase("DCS");
} else {
// For debugin in simulator fallback to native SQL Lite
console.log("Use built in SQL Lite");
app.db = window.openDatabase("DCS", "1.0", "DCS DB", 200000);
}
app.hideLoader();
}
app.onClickDoThis = function () {
app.showLoader("Initializing...");
app.db.transaction(app.buildDB, errorCB, app.buildsuccessCB);
}
app.buildDB = function(tx) {
tx.executeSql("CREATE TABLE IF NOT EXISTS connectionInfo(connectionState TEXT PRIMARY KEY, displayName TEXT, allowUpdate INT, show INT, dateLastUpdated DATETIME)");
console.log("Build Tables: categories");
tx.executeSql("CREATE TABLE IF NOT EXISTS categories(stk_SCID INT PRIMARY KEY, stk_CID INT, stk_SID INT, stk_Sector TEXT, stk_Category TEXT, stk_SubCategory TEXT, stk_Deleted INT, DateLastUpdated DATETIME)");
console.log("Build Tables: products");
tx.executeSql("CREATE TABLE IF NOT EXISTS products(stk_ItemNo TEXT PRIMARY KEY, stk_ItemDescription TEXT, stk_QtyPerPack INT, stk_Size TEXT, stk_Weight TEXT, stk_RSP TEXT, stk_PallQty INT, stk_LayQty INT, stk_Brand TEXT, stk_Sector INT, stk_Category INT, stk_SubCategory INT, stk_BarcodeOuter TEXT, stk_BarcodeInner TEXT, stk_BarcodeUnit TEXT, StockLevel INT, photo TEXT, stk_Deleted INT, stk_CoreRange TEXT, DateLastUpdated DATETIME, stk_Price REAL)");
console.log("Build Tables: customers");
tx.executeSql("CREATE TABLE IF NOT EXISTS customers(cus_AccountNo TEXT PRIMARY KEY, cus_AccountName TEXT, cus_ID INT, cus_Priceband INT, cus_Deleted INT, DateLastUpdated DATETIME, selectedAccount INT DEFAULT 0)");
console.log("Build Tables: deliveryAddresses");
tx.executeSql("CREATE TABLE IF NOT EXISTS deliveryAddresses(cus_DAID INT PRIMARY KEY, cus_AccountNo TEXT, cus_Description TEXT, cus_AddressLine1 TEXT, cus_AddressLine2 TEXT, cus_AddressLine3 TEXT, cus_AddressLine4 TEXT, cus_PostCode TEXT, cus_Sage200ID TEXT, cus_Deleted INT, DateLastUpdated DATETIME)");
console.log("Build Tables: priceBands");
tx.executeSql("CREATE TABLE IF NOT EXISTS priceBands(prb_ID TEXT PRIMARY KEY, stk_ItemNo TEXT, prb_Priceband INT, prb_CurrentPrice REAL, prb_NormalPrice REAL, prb_Deleted INT, DateLastUpdated DATETIME)");
}
app.buildsuccessCB = function() {
alert("successfull");
}