From f1b638935c6b6d88ca73acc15723ffeb8c990b10 Mon Sep 17 00:00:00 2001 From: Tomas Mlcoch Date: Tue, 14 May 2013 11:20:15 +0200 Subject: [PATCH] sqlite: Add asserts. --- src/sqlite.c | 9 +++++++++ src/sqlite.h | 7 ++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/sqlite.c b/src/sqlite.c index b0da72c..87c623f 100644 --- a/src/sqlite.c +++ b/src/sqlite.c @@ -23,6 +23,7 @@ */ #include +#include #include #include #include "logging.h" @@ -470,6 +471,8 @@ cr_db_open(const char *path, cr_DatabaseType db_type, GError **err) GError *tmp_err = NULL; sqlite3 *db = NULL; + assert(db_type < CR_DB_SENTINEL); + if (!path || path[0] == '\0') return db; @@ -506,6 +509,8 @@ cr_db_open(const char *path, cr_DatabaseType db_type, GError **err) db_create_filelists_tables(db, &tmp_err); break; case CR_DB_OTHER: db_create_other_tables(db, &tmp_err); break; + default: + assert(0); } if (tmp_err) @@ -521,6 +526,8 @@ cr_db_close(sqlite3 *db, cr_DatabaseType db_type, GError **err) { GError *tmp_err = NULL; + assert(db_type < CR_DB_SENTINEL); + if (!db) return; @@ -531,6 +538,8 @@ cr_db_close(sqlite3 *db, cr_DatabaseType db_type, GError **err) db_index_filelists_tables(db, &tmp_err); break; case CR_DB_OTHER: db_index_other_tables(db, &tmp_err); break; + default: + assert(0); } if (tmp_err) diff --git a/src/sqlite.h b/src/sqlite.h index 0af0968..ff08949 100644 --- a/src/sqlite.h +++ b/src/sqlite.h @@ -69,9 +69,10 @@ typedef struct _DbOtherStatements * cr_DbOtherStatements; /** Database type. */ typedef enum { - CR_DB_PRIMARY, /*!< primary */ - CR_DB_FILELISTS, /*!< filelists */ - CR_DB_OTHER /*!< other */ + CR_DB_PRIMARY, /*!< primary */ + CR_DB_FILELISTS, /*!< filelists */ + CR_DB_OTHER, /*!< other */ + CR_DB_SENTINEL, /*!< sentinel of the list */ } cr_DatabaseType; /** Macro over cr_db_open function. Open (create new) primary sqlite sqlite db. -- 2.7.4