Skip to content

Binding ORDER BY #1132

Closed Answered by JoshuaWise
amiralitaheri asked this question in Q&A
Discussion options

You must be logged in to vote

SQLite only allows binding parameters for data values. A table/column name is not a data value, so it doesn't work the way you expect. This isn't an issue with better-sqlite3, it's just how SQLite is designed.

The number of tables/columns in your database is theoretically static (i.e., it doesn't change rapidly while an application is running; it only changes at intentional, predictable moments). Therefore, the optimal solution is to create one prepared statement per column that you might want to order by, and then choose the correct prepared statement dynamically (without running db.prepare() for each query).

Alternatively, if you want to just run db.prepare() for each query, there's no …

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by JoshuaWise
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants