From 2e7765f468c46728df16faa903d1f4b8a17f76fd Mon Sep 17 00:00:00 2001 From: Guo Wenxue <guowenxue@gmail.com> Date: Wed, 21 Sep 2022 23:09:27 +0800 Subject: [PATCH] update sqlite_blob.c --- apue/project_socket/src/sqlite_blob.c | 51 ++++++++++++++++++++++++++------------------------- 1 files changed, 26 insertions(+), 25 deletions(-) diff --git a/apue/project_socket/src/sqlite_blob.c b/apue/project_socket/src/sqlite_blob.c index 07a95f1..be70c59 100644 --- a/apue/project_socket/src/sqlite_blob.c +++ b/apue/project_socket/src/sqlite_blob.c @@ -27,9 +27,9 @@ static sqlite3 *s_clidb = NULL; -/* description: open or create sqlite database if not exist - * input args: - * $db_file: sqlite database file name +/* description: open or create sqlite database if not exist + * input args: + * $db_file: sqlite database file name * return value: <0: failure 0:ok * */ int database_init(const char *db_file) @@ -73,7 +73,7 @@ /* enable full auto vacuum, Auto increase/decrease */ sqlite3_exec(s_clidb, "pragma auto_vacuum = 2 ; ", NULL, NULL, NULL); - /* Create firehost table in the database */ + /* Create firehost table in the database */ snprintf(sql, sizeof(sql), "CREATE TABLE %s(packet BLOB);", TABLE_NAME); if( SQLITE_OK != sqlite3_exec(s_clidb, sql, NULL, NULL, &errmsg) ) { @@ -81,6 +81,7 @@ sqlite3_free(errmsg); /* free errmsg */ sqlite3_close(s_clidb); /* close databse */ unlink(db_file); /* remove database file */ + return -3; } log_info("create and init database file '%s' ok\n", db_file); @@ -88,7 +89,7 @@ } -/* description: close sqlite database handler +/* description: close sqlite database handler * return value: none */ void database_term(void) @@ -100,10 +101,10 @@ } -/* description: push a blob packet into database - * input args: - * $pack: blob packet data address - * $size: blob packet data bytes +/* description: push a blob packet into database + * input args: + * $pack: blob packet data address + * $size: blob packet data bytes * return value: <0: failure 0:ok */ int blobdb_push_packet(void *pack, int size) @@ -125,7 +126,7 @@ return -2; } - snprintf(sql, sizeof(sql), "insert into %s(packet) values(?)", TABLE_NAME); + snprintf(sql, sizeof(sql), "insert into %s(packet) values(?)", TABLE_NAME); rv = sqlite3_prepare_v2(s_clidb, sql, -1, &stat, NULL); if(SQLITE_OK!=rv || !stat) { @@ -161,11 +162,11 @@ } -/* description: pop the first blob packet from database - * input args: - * $pack: blob packet output buffer address - * $size: blob packet output buffer size - * $byte: blob packet bytes +/* description: pop the first blob packet from database + * input args: + * $pack: blob packet output buffer address + * $size: blob packet output buffer size + * $byte: blob packet bytes * return value: <0: failure 0:ok */ int blobdb_pop_packet(void *pack, int size, int *bytes) @@ -213,17 +214,17 @@ goto out; } - *bytes = sqlite3_column_bytes(stat, 0); + *bytes = sqlite3_column_bytes(stat, 0); - if( *bytes > size ) - { - log_error("blob packet bytes[%d] larger than bufsize[%d]\n", *bytes, size); - *bytes = 0; - rv = -1; - } + if( *bytes > size ) + { + log_error("blob packet bytes[%d] larger than bufsize[%d]\n", *bytes, size); + *bytes = 0; + rv = -1; + } memcpy(pack, blob_ptr, *bytes); - rv = 0; + rv = 0; out: sqlite3_finalize(stat); @@ -231,8 +232,8 @@ } -/* description: remove the first blob packet from database - * input args: none +/* description: remove the first blob packet from database + * input args: none * return value: <0: failure 0:ok */ int blobdb_del_packet(void) -- Gitblit v1.9.1