Bernardo
I use the sqlite3_bind_blob function from the blob interface. My blob is 16K
Below my code snippet for inserting the row:
int insert_user(char *name, char *number, bool admin, unsigned char *data) {
int rc;
char sql[MAX_SQL];
int size = MAX_ENROLLDATA_SIZE;
uint64_t hash;
sqlite3_stmt *pStmt = NULL;
hash = MurmurHash64A(data,size,0);
rc = snprintf(sql, MAX_SQL, "INSERT INTO Users ( Id, Name, Number, Admin, Hash, Bir ) VALUES( NULL, '%s', '%s', %d, %ld, ?)", name, number, admin, hash);
if(rc >= (int) sizeof(sql)) {
syslog (LOG_ERR, "%s: SQL statement to big: '%s'\n", __FUNCTION__, sql);
return 1;
}
rc = sqlite3_prepare (sql_db, sql, -1, &pStmt, 0);
if (rc != SQLITE_OK || pStmt == NULL) {
syslog (LOG_ERR, "%s: cannot prepare statement: %s\n", __FUNCTION__, sqlite3_errmsg (sql_db));
return 1;
}
sqlite3_bind_blob (pStmt, 1, data, size, SQLITE_STATIC);
rc = sqlite3_step (pStmt);
if (rc != SQLITE_DONE) {
syslog (LOG_ERR, "%s: execution failed: %s", __FUNCTION__, sqlite3_errmsg (sql_db));
}
sqlite3_finalize (pStmt);
return rc;
}