" 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);"
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;
}
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 ) {
+ printf("Bank_int_QuerySingle: RETURN NULL ret=NULL\n");
+ return NULL;
+ }
// Get row
rv = sqlite3_step(ret);
// - Empty result set
- if( rv == SQLITE_DONE ) return NULL;
+ if( rv == SQLITE_DONE ) {
+ printf("Bank_int_QuerySingle: RETURN NULL (rv == SQLITE_DONE)\n");
+ return NULL;
+ }
// - Other error
if( rv != SQLITE_ROW ) {
fprintf(stderr, "SQLite Error: %s\n", sqlite3_errmsg(gBank_Database));
return NULL;
}
+ printf("Bank_int_QuerySingle: RETURN %p\n", ret);
return ret;
}
printf("Coke_CanDispense: Flushing\n");
#endif
- // Flush the input buffer
- {
- char tmpbuf[512];
- read(giCoke_SerialFD, tmpbuf, sizeof(tmpbuf));
- }
// Wait for a prompt
ret = 0;
- do {
+ while( WaitForColon() && ret < 3 )
+ {
+ // Flush the input buffer
+ char tmpbuf[512];
+ read(giCoke_SerialFD, tmpbuf, sizeof(tmpbuf));
#if TRACE_COKE
- printf("Coke_DoDispense: sending 'd7'\n");
+ printf("Coke_CanDispense: sending 'd7'\n");
#endif
write(giCoke_SerialFD, "d7\r\n", 4);
- } while( WaitForColon() && ret++ < 3 );
+ ret ++;
+ }
- if( ret == 3 ) {
+ if( !(ret < 3) ) {
fprintf(stderr, "Coke machine timed out\n");
return -2; // -EMYBAD
}
#if TRACE_COKE
printf("Coke_DoDispense: flushing input\n");
#endif
- // Flush the input buffer
+
+ // Wait for prompt
+ ret = 0;
+ while( WaitForColon() && ret < 3 )
{
+ // Flush the input buffer
char tmpbuf[512];
read(giCoke_SerialFD, tmpbuf, sizeof(tmpbuf));
- }
-
- // Wait for prompt
- i = 0;
- do {
#if TRACE_COKE
printf("Coke_DoDispense: sending 'd7'\n");
#endif
write(Item, "d7\r\n", 4);
- } while( WaitForColon() && i++ < 3 );
+ }
#if TRACE_COKE
printf("Coke_DoDispense: sending 'd%i'\n", Item);