0

我的代码是这样的:

db.run(`begin transaction;
  replace into players (user_id, role) values ($id, $role);
  update signed_up_users set finalised = 1 where user_id = $id;
  commit;`, { $id: id, $role: role}, err=>{
    if (err) {throw err;}
  });

我收到以下错误:

Error: SQLITE_RANGE: bind or column index out of range
--> in Database#run('begin transaction;\n      replace into players (user_id, role) values (?, ?);\n      update signed_up_users set finalised = 1 where user_id = ?;\n      commit;', [ '123', 'INNOCENT', '123' ], [Function])
    at Object.exports.finalise_user (C:\whatever\file.js)
    at user.resolve_to_id.then.id (C:\whatever\file.js:52:14)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)

如果我正确理解了文档,我的声明中就有适量的参数和占位符。那么我做错了什么?谢谢。

4

1 回答 1

0

文档实际上说:

数据库#run(sql, [param, ...], [callback])

运行 SQL 查询 […]

数据库#exec(sql, [回调])

运行提供的字符串中的所有 SQL 查询。

于 2018-01-21T16:24:27.063 回答