Skip to content Skip to sidebar Skip to footer

Can Not Prepare Insert Statement In Sqlite, C Api

/* DATABASE INIT */ ret = sqlite3_open_v2(dbfile, &DB, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL); if (SQLITE_OK != ret) { printf('Could not open database.\n');

Solution 1:

I think you should try

constchar* zSql = 
    "INSERT INTO abc (moderation_status, phonenumber, email) VALUES(?,?,?)";

assuming moderation_statusphonenumber and email are the names of the fields in your table.

or:

constchar* zSql = "INSERT INTO abc VALUES(?,?,?)";

The ? is the placeholder for where the arguments will be inserted.

Solution 2:

You haven't supplied a list of values; you've supplied a list of names (presumably column names) where a list of values is needed.

You might need:

char* zSql = "INSERT INTO abc(moderation_status, phonenumber, email) ""VALUES('U', '212-234-6678', 'example@example.com')";

Or you might not bother with the column names:

char* zSql = "INSERT INTO abc VALUES('U', '212-234-6678',""'example@example.com')";

Or you might use placeholders:

char* zSql = "INSERT INTO abc VALUES(?, ?, ?)";

If you use placeholders, you'll have to provide the corresponding values when you execute the statement. (But placeholders are generally the best solution - they avoid SQL Injection problems.)

Post a Comment for "Can Not Prepare Insert Statement In Sqlite, C Api"