Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use LIMIT in SQLite3 together as a bound parameter?

Tags:

sqlite

Is a statement like

SELECT Name FROM Persons WHERE Name LIKE ?1 LIMIT ?2

possible in SQLite3? For ?1 I can bind a parameter after the statement is prepared, using https://www.sqlite.org/c3ref/bind_blob.html. But is this also possible for ?2? I could not get it to work and now I fear that I have to create a prepare a separate statement for each value of LIMIT, say 1, 10, 100, 1000, etc.

like image 824
Fabian Avatar asked Oct 16 '25 19:10

Fabian


1 Answers

The answer is yes. It works for ?2 the same way as for ?1.

int iReturn = sqlite3_bind_text(pStmt, index, acValue, -1, SQLITE_TRANSIENT);

For limit, index is 2 and acValue is a string which evaluates to an integer. I recommend setting SQLITE_TRANSIENT so that SQLite makes a copy of acValue. Otherwise one has to ensure that acValue does not go out of scope.

like image 170
Fabian Avatar answered Oct 18 '25 17:10

Fabian