-
Notifications
You must be signed in to change notification settings - Fork 53
OUT_BIN
Jurek Muszyński edited this page May 13, 2019
·
4 revisions
Writes binary data to output buffer. Typical usage would be to serve an image from the database.
Initially output buffers are of OUT_BUFSIZE size (memory model-dependent) and they may or may not be resized if necessary, depending on OUTxxx compilation switch.
None
int show_image(int ci, long user_id, long img_id)
{
int ret=OK;
char sql_query[1024];
MYSQL_RES *result;
MYSQL_ROW sql_row;
unsigned long *lengths;
DBG("show_image");
sprintf(sql_query, "SELECT fname, bcontent FROM images WHERE user_id=%ld AND img_id=%ld", user_id, img_id);
DBG("sql_query: %s", sql_query);
mysql_query(G_dbconn, sql_query);
result = mysql_store_result(G_dbconn);
if ( !result )
{
ERR("Error %u: %s", mysql_errno(G_dbconn), mysql_error(G_dbconn));
return ERR_INT_SERVER_ERROR;
}
if ( !mysql_num_rows(result) ) /* no such entry */
{
mysql_free_result(result);
return ERR_NOT_FOUND;
}
sql_row = mysql_fetch_row(result);
lengths = mysql_fetch_lengths(result);
OUT_BIN(sql_row[1], lengths[1]);
DBG("File: [%s], size = %ul", sql_row[0], lengths[1]);
mysql_free_result(result);
return OK;
}