Advertisement
Guest User

XDK SQLIte Issue

a guest
Feb 12th, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var db;
  2. document.addEventListener("deviceready", onDeviceReady, false);
  3.  
  4. // Cordova is ready
  5. function onDeviceReady() {
  6.     alert ("device ready");
  7.     //This Enable/Disable the Screen Orientation
  8.     intel.xdk.device.setAutoRotate(true);
  9.     // This will create the Database.
  10.     //db = window.sqlitePlugin.openDatabase("Database", "1.0", "Demo", -1);
  11.     db = sqlitePlugin.openDatabase(
  12.         // options
  13.         {
  14.             name: "MyDatabase.db",
  15.             location: 0 // for iOS (0=Documents (default, visible in iTunes, backed up by iCloud), 1=Library (not visible in iTunes, backed up by iCloud, 2=Library/LocalDatabase (not visible in iTunes, not backed up by iCloud))
  16.         },
  17.         // success callback
  18.         function (msg) {
  19.             alert("success Creating DB: " + msg);
  20.         },
  21.         // error callback
  22.         function (msg) {
  23.             alert("error on Create DB: " + msg);
  24.         }
  25.     );
  26.  
  27.     createDB();
  28. }
  29.  
  30. function createDB(){
  31.     db.transaction(function(tx) {
  32.         //tx.executeSql('DROP TABLE IF EXISTS test_table');
  33.         tx.executeSql('CREATE TABLE IF NOT EXISTS test_table(UserID integer, UserName text)');
  34.         alert("table created");
  35.     }, function(e) {
  36.         alert("ERROR: " + e.message);
  37.     });
  38. }
  39.  
  40. //Call this function to insert:
  41. function InsertUserLog(pUserID, pUserName, pTechID, pBranchID, pBranchCode, pDeviceID, pPassword, pLogInDate, pTruckID){
  42.  
  43.     db.transaction(function(tx) {
  44.         tx.executeSql("INSERT INTO TblUserLog (UserID, UserName) VALUES (?,?)", [pUserID, pUserName], function(tx, res) {
  45.             //alert("insertId: " + res.insertId + " -- probably 1");
  46.             //alert("rowsAffected: " + res.rowsAffected + " -- should be 1");
  47.             updateProgressBar(50);
  48.         }, function(e) {
  49.             alert("ERROR: " + e.message);
  50.         });
  51.     });
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement