On 2017/09/14 3:20 AM, Papa wrote:
I think the problem with this function is my lack of good understanding of the SQL. What I intend to do is to write one int64_t to the database, but I don't know how to write the proper sql statement, making sqlite3_prepare_v2 return a non SQLITE_OK value.
Any help is much appreciated.

void write(const std::string& table_name, const int pos, const int64_t data) {
    ...
    std::string apstr = "INSERT INTO (";
    apstr += table_name.data();
    apstr += ", ";
    apstr += data;
    apstr += ");";
    rc = sqlite3_prepare_v2(db, apstr.data(), -1, &binary_sql_statement, NULL);
    ...
}


The problem is your string builds an invalid SQL statement. You should dump the complete string after it is built, inspecting that will teach you very quick where the problem is.

From what I can see, your code will build a string that looks something like this:

INSERT INTO (table_name, 1234);

You will want to remake it so that the SQL that it builds look something like this (I don't know your schema so I am guessing some identifiers... but you should see the answer):

INSERT INTO table_name (name_of_int64_column) VALUES (1234);


Hope that helps, but if you don't find the solution from this, please post the DB schema and teh string that gets built with your code.
Cheers,
Ryan


_______________________________________________
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to