Note that there are some explanatory texts on larger screens.

plurals
  1. POSQLite Blob insertion c++
    text
    copied!<p>After visiting dozens of websites containing info about SQLite I still cannot find a solution to fix an error while binding a blob. Here is the table decleration:</p> <pre><code>CREATE TABLE ONE ( ID INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, NAME CHAR( 50 ) NOT NULL, LABEL CHAR( 50 ), GRP CHAR( 50 ), FILE BLOB ); </code></pre> <p>And here is the code for insertion:</p> <pre><code>int InsertFile(string name) { const char* dbname = name.c_str(); sqlite3 *database; int rc = sqlite3_open(dbname, &amp;database); char *zErrMsg = 0; unsigned char *buffer = (unsigned char*) malloc(sizeof(char)*MAX); ifstream file; file.open("Sql.pdf", ios::in|ios::binary); if ( ! file ) { cout &lt;&lt; "An error occurred opening the file" &lt;&lt; endl; } int count = 0; const void* fileptr = NULL; fileptr = buffer; while(file.good()) { char c=file.get(); buffer[count]=c; count++; } file.close(); sqlite3_stmt *stmt = NULL; char* statement = "INSERT INTO ONE( ID, NAME, LABEL, GRP, FILE ) VALUES ( NULL, 'fedfsdfss', NULL, NULL, ?);"; rc = sqlite3_prepare_v2(database, statement, 0, &amp;stmt, NULL); rc = sqlite3_bind_blob(stmt, 1, fileptr, sizeof(char)*count, SQLITE_TRANSIENT); const char* result = sqlite3_errmsg(database); rc = sqlite3_step(stmt); result = sqlite3_errmsg(database); sqlite3_close(database); free(buffer); fileptr=NULL; return 0; </code></pre> <p>} EDIT: Pasted full function, the amount of characters im trying to insert is about 350K.</p> <p>The result from binb_blob is always 21, error code contains nothing. buffer contains binary file data, which most probably isn't too big hence the error code. Any hints would be apprieciated. </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