Android SQLite Problem

2 posts, 0 answers
  1. Harry
    Harry avatar
    3 posts
    Member since:
    Jul 2013

    Posted 10 Oct 2013 Link to this post


    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 = = || {};
        app.db = null;

        // Wait for device API libraries to load
        document.addEventListener("deviceready", onDeviceReady, false);

        // device APIs are available
        function onDeviceReady() {
            app.application = new, {
                    layout: "tabstrip-layout",
                    loading: '<h1 class="loaderHeading">Loading...</h1>',
                    transition: 'slide',

        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.onClickDoThis = function () {
            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() {
  2. Steve
    Steve avatar
    10941 posts

    Posted 11 Oct 2013 Link to this post

    Hello Harry,

    We have not encountered such problem and your code looks correct. The same code executed correctly in our SqLite sample demo on both Android and iOS. Are you building against Cordova 3.0 and is cordova.js registered as the first script reference on your page? Try to debug the app by adding console.log all over the problematic code and check out the device logs in Graphite's output pane.

    You can also setup Fiddler to intercept your device's traffic and see if that gives you a clue what's going on by reviewing the requests/responses.

    You've missed the Icenium Visual Studio Integration keynote? It has been recorded and posted here.
    Looking for tips & tricks directly from the Icenium team? Check out our blog!
    Share feedback and vote for features on our Feedback Portal.
Back to Top