- Phonegap. Null value being inserted into database table. Datatype conflict?
- function addSession(tx){
- var locationID = $('#location').val();
- var gameID = $('#game').val();
- if ($('#location').val() == '0'){
- tx.executeSql(
- 'INSERT INTO locations (lTitle) VALUES (?)',
- [$('#newLocation').val()],
- function(tx, results){
- locationID = results.insertId;
- },
- errorCB
- );
- }
- if ($('#game').val() == '0'){
- tx.executeSql(
- 'INSERT INTO games (lTitle) VALUES (?)',
- [$('#newGame').val()],
- function(tx, results){
- gameID = results.insertId;
- },
- errorCB
- );
- }
- var sSQL = 'INSERT INTO sessions (date, duration, location, game, notes) VALUES '
- + '("'+$('#date').val()+' '+$('#time').val()+':00.000"'
- +',2.5,'+locationID+','+gameID+',"'+$('#notes').val()+'")';
- tx.executeSql(
- sSQL,
- [],
- function(tx,results){
- //todo after successful entry
- },
- errorCB
- );
- }
- tx.executeSql(
- 'CREATE TABLE IF NOT EXISTS sessions ' +
- '(id INTEGER PRIMARY KEY , ' +
- 'date TEXT, ' +
- 'duration REAL, ' +
- 'game INTEGER, ' +
- 'location INTEGER, ' +
- 'notes TEXT' +
- ')'
- );
- //FUNCTION TO ADD NEW LOCATIONS
- function addLocation(tx){
- tx.executeSql(
- 'INSERT INTO locations (lTitle) VALUES (?)',
- [$('#newLocation').val()],
- function(tx, results){
- locationID = results.insertId;
- },
- errorCB
- );
- }
- //FUNCTION TO ADD NEW GAMES
- function addGame(tx){
- tx.executeSql(
- 'INSERT INTO games (gTitle) VALUES (?)',
- [$('#newGame').val()],
- function(tx, results){
- gameID = results.insertId;
- },
- errorCB
- );
- }
- //FUNCTION TO ADD NEW SESSION
- function addSessionGo(tx){
- var sSQL = 'INSERT INTO sessions (date, game, location, notes) VALUES ' +
- '("'+$('#date').val()+' '+$('#time').val()+':00.000"' +
- ','+gameID+','+locationID+',"'+$('#notes').val()+'")';
- //alert(sSQL);
- tx.executeSql(
- sSQL,
- [],
- function(tx,results){
- //todo after successful entry
- //alert('Added new session');
- },
- errorCB
- );
- }
- //FUNCTION TO START ADDING THE NEW SESSION
- function addSession(tx){
- locationID = $('#location').val();
- gameID = $('#game').val();
- if ($('#location').val() == '0'){
- db.transaction(addLocation, errorCB);
- }
- if ($('#game').val() == '0'){
- db.transaction(addGame, errorCB);
- }
- db.transaction(addSessionGo, errorCB);
- }