X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=src%2Fcokebank_sqlite%2Fmain.c;h=ef87b7bdd5c053b089a27139c0ca7bda07d39bb3;hb=1c2e62ab45f3dc08a8a2b823ebc896381af5b3b0;hp=0d5e1396a88460c35c9889b58013277b2bdebe91;hpb=df71d48cc0082a5333203384cfbce040cf54a155;p=tpg%2Fopendispense2.git diff --git a/src/cokebank_sqlite/main.c b/src/cokebank_sqlite/main.c index 0d5e139..ef87b7b 100644 --- a/src/cokebank_sqlite/main.c +++ b/src/cokebank_sqlite/main.c @@ -15,6 +15,8 @@ #include "../cokebank.h" #include +#define DEBUG 1 + const char * const csBank_DatabaseSetup = "CREATE TABLE IF NOT EXISTS accounts (" " acct_id INTEGER PRIMARY KEY NOT NULL," @@ -35,6 +37,14 @@ const char * const csBank_DatabaseSetup = " FOREIGN KEY (acct_id) REFERENCES accounts (acct_id) ON DELETE CASCADE" // Deletion of the account frees the card ^ ^ ^ ");" +"CREATE TABLE IF NOT EXISTS items (" +" item_id INTEGER PRIMARY KEY NOT NULL," +" item_handler STRING NOT NULL," +" item_index INTEGER NOT NULL," +" item_name STRING NOT NULL," +" item_price INTEGER NOT NULL," +" item_is_enabled BOOLEAN NOT NULL DEFAULT true" +");" "INSERT INTO accounts (acct_name,acct_is_admin,acct_uid) VALUES ('root',1,0);" "INSERT INTO accounts (acct_name,acct_is_internal,acct_uid) VALUES ('"COKEBANK_SALES_ACCT"',1,-1);" "INSERT INTO accounts (acct_name,acct_is_internal,acct_uid) VALUES ('"COKEBANK_DEBT_ACCT"',1,-2);" @@ -210,6 +220,10 @@ int Bank_SetFlags(int UserID, int Mask, int Value) ); #undef MAP_FLAG + #if DEBUG + printf("Bank_SetFlags: query=\"%s\"\n", query); + #endif + // Execute Query rv = sqlite3_exec(gBank_Database, query, NULL, NULL, &errmsg); if( rv != SQLITE_OK ) @@ -286,9 +300,9 @@ int Bank_GetAcctByName(const char *Name) if( !statement ) return -1; ret = sqlite3_column_int(statement, 0); - if( ret == 0 ) return -1; - sqlite3_finalize(statement); + + if( ret == 0 ) return -1; return ret; } @@ -538,14 +552,28 @@ sqlite3_stmt *Bank_int_QuerySingle(sqlite3 *Database, const char *Query) sqlite3_stmt *ret; int rv; + #if DEBUG + printf("Bank_int_QuerySingle: (Query='%s')\n", Query); + #endif + // Prepare query ret = Bank_int_MakeStatemnt(Database, Query); - if( !ret ) return NULL; + if( !ret ) { + #if DEBUG >= 2 + printf("Bank_int_QuerySingle: RETURN NULL ret=NULL\n"); + #endif + return NULL; + } // Get row rv = sqlite3_step(ret); // - Empty result set - if( rv == SQLITE_DONE ) return NULL; + if( rv == SQLITE_DONE ) { + #if DEBUG >= 2 + printf("Bank_int_QuerySingle: RETURN NULL (rv == SQLITE_DONE)\n"); + #endif + return NULL; + } // - Other error if( rv != SQLITE_ROW ) { fprintf(stderr, "SQLite Error: %s\n", sqlite3_errmsg(gBank_Database)); @@ -553,6 +581,9 @@ sqlite3_stmt *Bank_int_QuerySingle(sqlite3 *Database, const char *Query) return NULL; } + #if DEBUG >= 2 + printf("Bank_int_QuerySingle: RETURN %p\n", ret); + #endif return ret; }