Sqlite doesn't find row _only_ when binding takes places in another function

前端 未结 2 1283
Happy的楠姐
Happy的楠姐 2021-01-25 15:37

So I wrote myself a little wrapper function to make a prepared statement for me:

sqlite3_stmt* Gladiateur::run_query_unfinalized(string query, vector

        
相关标签:
2条回答
  • 2021-01-25 16:09

    Gladiateur::run_query_unfinalized(string query, vector<string> inputs)

    The vector<string> inputs is a copy, and it ceases to exist when the function returns.

    Perhaps you should change it to:

    Gladiateur::run_query_unfinalized(const string& query, const vector<string>& inputs)
    

    With a reference, the c_str should survive to do what you want to get done.

    0 讨论(0)
  • 2021-01-25 16:10

    The last parameter of the sqlite3_bind_text function cannot be NULL:

    The fifth argument to the BLOB and string binding interfaces is a destructor used to dispose of the BLOB or string after SQLite has finished with it. The destructor is called to dispose of the BLOB or string even if the call to bind API fails. If the fifth argument is the special value SQLITE_STATIC, then SQLite assumes that the information is in static, unmanaged space and does not need to be freed. If the fifth argument has the value SQLITE_TRANSIENT, then SQLite makes its own private copy of the data immediately, before the sqlite3_bind_*() routine returns.

    In this case, you need SQLITE_TRANSIENT.

    0 讨论(0)
提交回复
热议问题