· 7 years ago · Jan 12, 2019, 06:06 AM
1Callback called before the processmethod
2var databaseVersion = 1;
3
4function createTable(tx, tableName, tableColumns){
5 var sqlStatement = 'CREATE TABLE IF NOT EXISTS '+tableName+' (_id unique, ' + tableColumns+')';
6 tx.executeSql('DROP TABLE IF EXISTS '+tableName);
7 tx.executeSql(sqlStatement);
8 console.log('now doInsertion (if successful should be called');
9}
10
11function createMenuDataBase(tx){
12 var tableName ="element";
13 var tableColumns = ["name", "resource","remoteData", "picture", "pageId", "type",
14 "localAction", "replaceText", "textSize", "textColor","background", "sortOrder"];
15 createTable(tx, tableName, tableColumns);
16}
17
18
19
20function insertIntoDB(tableName,json){
21 checkDatabaseVersion(doInsertion,tableName,json);
22}
23
24function doInsertion(dbName,json){
25 console.log('starting doInsertion');
26 var sqlStart = "INSERT INTO "+dbName+" (";
27 var sqlEnd =");"
28 $.each(json.list, function(i, object) {
29 var first = true;
30 var columns="";
31 var values = ") VALUES ("
32
33 for (property in object) {
34 // alert(property);
35 if(property!=undefined){
36
37 if(first){
38 columns +=property;
39 values +=object[property];
40 first=false;
41 } else {
42 columns += ', '+property;
43 values +=', '+object[property];
44 }
45 }
46 }
47 console.log(sqlStart+columns+values+sqlEnd);
48 });
49}
50
51function checkDatabaseVersion(callback,dbName,json){
52 var localDatabaseVersion = localStorage.getItem("localDatabaseVersion");
53 alert(localDatabaseVersion);
54 if(localDatabaseVersion == 'undefined' || localDatabaseVersion == null){
55 var db = window.openDatabase("Database", "1.0", "PhoneGap Demo", 200000);
56 db.transaction(createMenuDataBase, errorCB, callback(dbName,json));
57
58
59 //localStorage.setItem("localDatabaseVersion",databaseVersion);
60 }
61}
62
6308-01 12:09:02.857: D/DroidGap(24433): onMessage(spinner,stop)
6408-01 12:09:03.467: D/CordovaLog(24433): starting doInsertion
6508-01 12:09:03.467: D/CordovaLog(24433): file:///android_asset/www/js/Database.js: Line 24 : starting doInsertion
6608-01 12:09:03.472: D/CordovaLog(24433): INSERT INTO element (name, resource, id, type, appId, sortOrder, background, picture, textColor, remoteData, pageId, localAction, replaceText, active, textSize) VALUES (menu0.9747386311565038, null, 9765, img, 1, 0, null, /content/picture/menu/product, null, null, mainMenu.menu, showProductCatalog(product), null, Y, 0);
6708-01 12:09:03.477: D/CordovaLog(24433): file:///android_asset/www/js/Database.js: Line 46 : INSERT INTO element (name, resource, id, type, appId, sortOrder, background, picture, textColor, remoteData, pageId, localAction, replaceText, active, textSize) VALUES (menu0.9747386311565038, null, 9765, img, 1, 0, null, /content/picture/menu/product, null, null, mainMenu.menu, showProductCatalog(product), null, Y, 0);
6808-01 12:09:03.477: D/CordovaLog(24433): INSERT INTO element (name, resource, id, type, appId, sortOrder, background, picture, textColor, remoteData, pageId, localAction, replaceText, active, textSize) VALUES (menu0.9847155498013517, null, 9753, img, 1, 1, null, /content/picture/menu/social, null, null, mainMenu.menu, showSocialMedia(socialmedia), null, Y, 0);
6908-01 12:09:03.477: D/CordovaLog(24433): file:///android_asset/www/js/Database.js: Line 46 : INSERT INTO element (name, resource, id, type, appId, sortOrder, background, picture, textColor, remoteData, pageId, localAction, replaceText, active, textSize) VALUES (menu0.9847155498013517, null, 9753, img, 1, 1, null, /content/picture/menu/social, null, null, mainMenu.menu, showSocialMedia(socialmedia), null, Y, 0);
7008-01 12:09:03.482: D/CordovaLog(24433): INSERT INTO element (name, resource, id, type, appId, sortOrder, background, picture, textColor, remoteData, pageId, localAction, replaceText, active, textSize) VALUES (menu0.5451258043474583, null, 9759, img, 1, 2, null, /content/picture/menu/store, null, null, mainMenu.menu, menu(store), null, Y, 0);
7108-01 12:09:03.482: D/CordovaLog(24433): file:///android_asset/www/js/Database.js: Line 46 : INSERT INTO element (name, resource, id, type, appId, sortOrder, background, picture, textColor, remoteData, pageId, localAction, replaceText, active, textSize) VALUES (menu0.5451258043474583, null, 9759, img, 1, 2, null, /content/picture/menu/store, null, null, mainMenu.menu, menu(store), null, Y, 0);
7208-01 12:09:03.482: D/CordovaLog(24433): INSERT INTO element (name, resource, id, type, appId, sortOrder, background, picture, textColor, remoteData, pageId, localAction, replaceText, active, textSize) VALUES (menu0.6883956226802171, null, 9762, img, 1, 3, null, /content/picture/menu/showroom, null, null, mainMenu.menu, showCollection(collection), null, Y, 0);
7308-01 12:09:03.482: D/CordovaLog(24433): file:///android_asset/www/js/Database.js: Line 46 : INSERT INTO element (name, resource, id, type, appId, sortOrder, background, picture, textColor, remoteData, pageId, localAction, replaceText, active, textSize) VALUES (menu0.6883956226802171, null, 9762, img, 1, 3, null, /content/picture/menu/showroom, null, null, mainMenu.menu, showCollection(collection), null, Y, 0);
7408-01 12:09:03.487: D/CordovaLog(24433): INSERT INTO element (name, resource, id, type, appId, sortOrder, background, picture, textColor, remoteData, pageId, localAction, replaceText, active, textSize) VALUES (menu0.21612715546682493, null, 9768, img, 1, 4, null, /content/picture/menu/beskeder, null, null, mainMenu.menu, showNotificationList(notificationList), null, Y, 0);
7508-01 12:09:03.487: D/CordovaLog(24433): file:///android_asset/www/js/Database.js: Line 46 : INSERT INTO element (name, resource, id, type, appId, sortOrder, background, picture, textColor, remoteData, pageId, localAction, replaceText, active, textSize) VALUES (menu0.21612715546682493, null, 9768, img, 1, 4, null, /content/picture/menu/beskeder, null, null, mainMenu.menu, showNotificationList(notificationList), null, Y, 0);
7608-01 12:09:03.497: D/CordovaLog(24433): now doInsertion (if successful should be called
7708-01 12:09:03.497: D/CordovaLog(24433): file:///android_asset/www/js/Database.js: Line 7 : now doInsertion (if successful should be called
78
79db.transaction(createMenuDataBase, errorCB, callback(dbName,json));
80
81callback(dbName,json) //Calls the function and passes the result to `db.transaction` as callback but it's not a function since the result is not a function.
82
83db.transaction(createMenuDataBase, errorCB, callback);
84
85db.transaction(createMenuDataBase, errorCB, callback.bind( null, dbName, json ));