You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Even a simple db.prepare('CREATE TABLE test (?)'); gives me an error on better-sqlite3 ^11.3.0.
return this[cppdb].prepare(sql, this, false);
^
SqliteError: near "?": syntax error
at Database.prepare (C:\Users\aceki\Desktop\nitrite\node_modules\better-sqlite3\lib\methods\wrappers.js:5:21)
at Object.createIfNotExists (C:\Users\aceki\Desktop\nitrite\migrate-table-sqlite.js:47:12)
at module.exports (C:\Users\aceki\Desktop\nitrite\test\app\database\0_create_users_table.up.js:2:11)
at C:\Users\aceki\Desktop\nitrite\index.js:134:28
at FSReqCallback.oncomplete (node:fs:188:23) {
code: 'SQLITE_ERROR'
}
Node.js v22.3.0
The text was updated successfully, but these errors were encountered:
You cannot use a binding parameter to "replace" the column definition.
I know I'm late and that this issue has been closed now, but why can I not do that though? Why would that not work, but db.prepare('INSERT INTO people VALUES (?, ?, ?)') would? (I'm not 100% sure if that works, I just copied that from the docs).
It would not work for replacing a complete column definition, because binding parameters, aka dynamic parameters or dynamic variables, are used to replace the actual values within a statement but not for changing / defining structure.
While your insert statement could work using the binding parameters, it may fail if those parameters are not in the exact order of column definitions of the table. I strongly suggest to write verbose SQL statements and include column names at all times, e.g. db.prepare('INSERT INTO people (<name of column 1>, <name of column 2>, <name of column 3>) VALUES (?, ?, ?)').
While there might be some databases out there, that also allow for doing such things, like binding table or column names to a paramter, SQlite3 (the actual database used by this lib) does not.
Even a simple
db.prepare('CREATE TABLE test (?)');
gives me an error on better-sqlite3 ^11.3.0.The text was updated successfully, but these errors were encountered: