On Friday, 12 April, 2019 14:48, Jim Dossey <[email protected]> wrote:
>On Apr 12, 2019, at 3:27 PM, Keith Medcalf <[email protected]> wrote: >>> To be a little more specific, the problem happens when I try to do >>> sqlite3_bind_int() on the prepared statement using the new rowid. >It >>> doesn't use the rowid it uses NULL. >>> >>> The prepared statement is "SELECT * FROM sessiond WHERE rowid=?;" >>> Then I call sqlite3_bind_int(ppStmt, 1, rowid) and the resulting >>> SELECT command is >>> SELECT * FROM "sessiond" WHERE "rowid"=NULL; >>> Which is obtained by calling sqlite3_expanded_sql(). >> >> This does not make sense. It indicates that you did not actually >bind a value to the parameter in question >> > >It may not make sense, but that is what happened. I tried it >repeatedly with different values for rowid. In every case, if the >rowid did not exist in the table, sqlite3_bind_int() would insert >NULL in place of the '?' Instead of the rowid. The rowid's I was >using were in the range of 10 to 25, so there were no extreme values. Interesting because it works for me. Everytime. And there does not even need to be any records in the table at all (you just need a table definition that allows the prepare to succeed): #include <stdlib.h> #include <string.h> #include <stdio.h> #include <sqlite3.h> int main(int argc, char **argv) { sqlite3 *db; sqlite3_stmt * stmt; char *exp; int rc; rc = sqlite3_open("test.db", &db); if (rc != SQLITE_OK) return 1; rc = sqlite3_prepare_v2(db, "select * from t where rowid=?;", -1, &stmt, 0); if (rc != SQLITE_OK) return 1; rc = sqlite3_bind_int(stmt, 1, atoi(argv[1])); if (rc != SQLITE_OK) return 1; exp = sqlite3_expanded_sql(stmt); printf("%s\n", exp); return 0; } >test 1 select * from t where rowid=1; >test 42 select * from t where rowid=42; >test 57 select * from t where rowid=57; >test 0 select * from t where rowid=0; >test -5 select * from t where rowid=-5; The only way I can get "where rowid=NULL" is if I do not bind anything at all to parameter 1 ... --- The fact that there's a Highway to Hell but only a Stairway to Heaven says a lot about anticipated traffic volume. _______________________________________________ sqlite-users mailing list [email protected] http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

