I retrieved binary data from sqlite database and now I have pointer to binary data (sqlite3_column_blob). How output this data to client with C cgi script?
char *sql = "SELECT Data FROM Images WHERE Id = 1";
sqlite3_stmt *pStmt;
rc = sqlite3_prepare_v2(db, sql, -1, &pStmt, 0);
if (rc != SQLITE_OK ) {
fprintf(stderr, "Failed to prepare statement\n");
fprintf(stderr, "Cannot open database: %s\n", sqlite3_errmsg(db));
sqlite3_close(db);
return 1;
}
rc = sqlite3_step(pStmt);
int bytes = 0;
if (rc == SQLITE_ROW) {
bytes = sqlite3_column_bytes(pStmt, 0);
}
// >>>>next row is function to save file but I want output binary data to client<<<<
fwrite(sqlite3_column_blob(pStmt, 0), bytes, 1, fp);
Ok, thanks to all for the support. Below the code I'm looking for, simply send "sqlite3_column_blob" to stdout...easy!