title: HTML5 Web SQL value for foreign key
body: <p>I am using HTML5 Web SQL and Javascript to set up my tables. I have two tables: games &amp; frames. I need to pull the last record (most recent) id from the games table and use it as a foreign key in the frames table. </p>
  
  <pre><code> function createGame (tx) {
                  tx.executeSql('CREATE TABLE IF NOT EXISTS games(id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, created unique, alley, date DATETIME, weight)');
                  tx.executeSql('INSERT INTO games(created, alley, date, weight) VALUES(?, ?, ?, ?)', [created, alley, date, weight]);
             }
  </code></pre>
  
  <p>My created, alley, date, and weight values are being defined outside of the function above. </p>
  
  <pre><code>function createFrame (tx) {
                  tx.executeSql("PRAGMA foreign_keys = ON;");
                  tx.executeSql('CREATE TABLE IF NOT EXISTS frames(id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, frame, pins, comments, FOREIGN KEY (gameID) REFERENCES games(id))');
                  tx.executeSql("INSERT INTO frames(frame, pins, comments, gameID) VALUES(?, ?, ?, ?)", [frame, pins, comments, gameID]);
             }
  </code></pre>
  
  <p>My problem is I don't know how to get the value for the last (most recent) record's id in the games table and use it for the foreign key in the frames table. </p>
  
  <p>Defining it as a variable like below has given me no luck:</p>
  
  <pre><code>db.transaction(function(tx) {
              tx.executeSql('SELECT LAST(id) FROM games', [], function(transaction,output) {
                  var gameID = output.id;
                  console.log(output);
              });
            });
  </code></pre>
  
  <p>Could someone tell me the best way to get the value of the last id in the games table to use it as a foreign key for the frames table? </p>
  
  <p>Thanks in advance. </p>