Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Thank you all again for your feedback. This time I'm reporting how I solved the problem with the help of the indications provided here. Hopefully this will help others in the future.</p> <p>As suggested by the first three posters, I did use prepared statements &mdash; additionally because I was also interested in getting the columns' data types, and a simple <code>sqlite3_get_table()</code> wouldn't do.</p> <p>After preparing the SQL statement in the form of the following constant string:</p> <pre><code>INSERT INTO table VALUES(?,?,?,?); </code></pre> <p>it remains the <i>binding</i> of the corresponding values. This is done by issuing as many <code>sqlite3_bind_blob()</code> calls as the columns. (I also resorted to <code>sqlite3_bind_text()</code> for other "simple" data types because the API I'm working on can translate integers/doubles/etc into a string). So:</p> <pre><code>void* blobvalue[4]; int blobsize[4]; char *tail, *sql="INSERT INTO table VALUES(?,?,?,?)"; sqlite3_stmt *stmt=0; sqlite3 *db; /* ... */ db=sqlite3_open("sqlite.db"); sqlite3_prepare_v2(db, sql, strlen(sql)+1, &amp;stmt, &amp;tail); for(int i=0; i&lt;4; i++) sqlite3_ bind_ blob(stmt, i+1, blobvalue[i], blobsize[i], SQLITE_TRANSIENT); if(sqlite3_step(stmt)!=SQLITE_DONE) printf("Error message: %s\n", sqlite3_errmsg(db)); sqlite3_finalize(stmt); sqlite3_close(db); </code></pre> <p>Note also that some functions (<code>sqlite3_open_v2()</code>, <code>sqlite3_prepare_v2()</code>) appear on the later SQLite versions (I suppose 3.5.x and later).</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload