Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 外键的HTML5 Web SQL值_Javascript_Sql_Database_Html_Sqlite - Fatal编程技术网

Javascript 外键的HTML5 Web SQL值

Javascript 外键的HTML5 Web SQL值,javascript,sql,database,html,sqlite,Javascript,Sql,Database,Html,Sqlite,我正在使用HTML5WebSQL和Javascript来设置我的表。我有两张桌子:游戏和框架。我需要从games表中提取最后一条记录(最近的)id,并将其用作frames表中的外键 function createGame (tx) { tx.executeSql('CREATE TABLE IF NOT EXISTS games(id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, created unique, alle

我正在使用HTML5WebSQL和Javascript来设置我的表。我有两张桌子:游戏和框架。我需要从games表中提取最后一条记录(最近的)id,并将其用作frames表中的外键

 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]);
           }
“我的创建”、“巷”、“日期”和“权重”值是在上述函数之外定义的

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]);
           }
我的问题是,我不知道如何获取games表中最后一条(最近一条)记录的id值,并将其用于frames表中的外键

 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]);
           }
将其定义为如下所示的变量并没有给我带来好运:

db.transaction(function(tx) {
            tx.executeSql('SELECT LAST(id) FROM games', [], function(transaction,output) {
                var gameID = output.id;
                console.log(output);
            });
          });
有人能告诉我获取games表中最后一个id值的最佳方法,以便将其用作frames表的外键吗


提前谢谢

要获得最大值,请使用:

要获取属于该游戏的帧,请搜索该查询返回的值,或者直接使用子查询进行计算:

SELECT * FROM frames WHERE gameID = (SELECT MAX(id) FROM games)

首先,如果你要进行最后一场比赛。。。不要试图每帧查询最后一场比赛

      SELECT id FROM games ORDER BY ID DESC LIMIT 1;
这将返回最后一个游戏的id

然后将results.row.id保存在localstorage中,这样您就可以轻松访问它,而无需继续执行多个表查询(手机内存有限)。并将其用作帧的变量

或者,如果您更喜欢将其作为子查询执行

SELECT * FROM frames WHERE gameID = (SELECT id FROM games ORDER BY ID DESC LIMIT 1)

“WebSQL”不再是一个东西了。它死了,你不应该编写使用它的新软件。考虑索引XDB作为一种选择。@ MeGar许多移动设备的HTML5框架使用WebSQL作为唯一的数据库机制。@ CL。没有提到任何框架,只有手工滚动的WebSQL。