Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 10th, 2012  |  syntax: None  |  size: 2.50 KB  |  hits: 9  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Phonegap. Null value being inserted into database table. Datatype conflict?
  2. function addSession(tx){
  3.   var locationID = $('#location').val();
  4.   var gameID = $('#game').val();
  5.   if ($('#location').val() == '0'){
  6.     tx.executeSql(
  7.       'INSERT INTO locations (lTitle) VALUES (?)',
  8.       [$('#newLocation').val()],
  9.       function(tx, results){
  10.         locationID = results.insertId;
  11.       },
  12.       errorCB
  13.     );
  14.   }
  15.   if ($('#game').val() == '0'){
  16.     tx.executeSql(
  17.       'INSERT INTO games (lTitle) VALUES (?)',
  18.       [$('#newGame').val()],
  19.       function(tx, results){
  20.         gameID = results.insertId;
  21.       },
  22.       errorCB
  23.     );
  24.   }
  25.   var sSQL = 'INSERT INTO sessions (date, duration, location, game, notes) VALUES '
  26.     + '("'+$('#date').val()+' '+$('#time').val()+':00.000"'
  27.     +',2.5,'+locationID+','+gameID+',"'+$('#notes').val()+'")';
  28.   tx.executeSql(
  29.     sSQL,
  30.     [],
  31.     function(tx,results){
  32.       //todo after successful entry
  33.     },
  34.     errorCB
  35.   );
  36. }
  37.        
  38. tx.executeSql(
  39.   'CREATE TABLE IF NOT EXISTS sessions ' +
  40.   '(id INTEGER PRIMARY KEY , ' +
  41.   'date TEXT, ' +
  42.   'duration REAL, ' +
  43.   'game INTEGER, ' +
  44.   'location INTEGER, ' +
  45.   'notes TEXT' +
  46.   ')'
  47. );
  48.        
  49. //FUNCTION TO ADD NEW LOCATIONS
  50. function addLocation(tx){
  51.     tx.executeSql(
  52.         'INSERT INTO locations (lTitle) VALUES (?)',
  53.         [$('#newLocation').val()],
  54.         function(tx, results){
  55.             locationID = results.insertId;
  56.         },
  57.         errorCB
  58.     );
  59. }
  60.  
  61. //FUNCTION TO ADD NEW GAMES
  62. function addGame(tx){
  63.     tx.executeSql(
  64.         'INSERT INTO games (gTitle) VALUES (?)',
  65.         [$('#newGame').val()],
  66.         function(tx, results){
  67.             gameID = results.insertId;
  68.         },
  69.         errorCB
  70.     );
  71. }
  72.  
  73. //FUNCTION TO ADD NEW SESSION
  74. function addSessionGo(tx){
  75.     var sSQL = 'INSERT INTO sessions (date, game, location, notes) VALUES ' +
  76.         '("'+$('#date').val()+' '+$('#time').val()+':00.000"' +
  77.         ','+gameID+','+locationID+',"'+$('#notes').val()+'")';
  78.     //alert(sSQL);
  79.  
  80.     tx.executeSql(
  81.         sSQL,
  82.         [],
  83.         function(tx,results){
  84.             //todo after successful entry
  85.             //alert('Added new session');
  86.         },
  87.         errorCB
  88.     );
  89. }
  90.  
  91.  
  92. //FUNCTION TO START ADDING THE NEW SESSION
  93. function addSession(tx){
  94.     locationID = $('#location').val();
  95.     gameID = $('#game').val();
  96.  
  97.     if ($('#location').val() == '0'){
  98.         db.transaction(addLocation, errorCB);
  99.     }
  100.  
  101.     if ($('#game').val() == '0'){
  102.         db.transaction(addGame, errorCB);
  103.     }
  104.  
  105.     db.transaction(addSessionGo, errorCB);
  106. }