void rsdb_transaction(rsdb_transtype type) { if(type == RSDB_TRANS_START) rsdb_exec(NULL, "BEGIN TRANSACTION"); else if(type == RSDB_TRANS_END) rsdb_exec(NULL, "COMMIT TRANSACTION"); }
static void parse_unban(bandb_type type, char *parv[], int parc) { const char *mask1 = NULL; const char *mask2 = NULL; if(type == BANDB_KLINE) { if(parc != 3) return; } else if(parc != 2) return; mask1 = parv[1]; if(type == BANDB_KLINE) mask2 = parv[2]; if(!in_transaction) { rsdb_transaction(RSDB_TRANS_START); in_transaction = 1; rb_event_addonce("bandb_commit", bandb_commit, NULL, COMMIT_INTERVAL); } rsdb_exec(NULL, "DELETE FROM %s WHERE mask1='%Q' AND mask2='%Q'", bandb_table[type], mask1, mask2 ? mask2 : ""); }
static void check_schema(void) { struct rsdb_table table; int i; rsdb_exec(NULL, "PRAGMA auto_vacuum=FULL"); for(i = 0; i < LAST_BANDB_TYPE; i++) { rsdb_exec_fetch(&table, "SELECT name FROM sqlite_master WHERE type='table' AND name='%s'", bandb_table[i]); rsdb_exec_fetch_end(&table); if(!table.row_count) rsdb_exec(NULL, "CREATE TABLE IF NOT EXISTS %s (mask1 TEXT, mask2 TEXT, oper TEXT, time INTEGER, perm INTEGER, reason TEXT)", bandb_table[i]); } }
static void check_schema(void) { struct rsdb_table table; int i; for(i = 0; i < BANDB_LAST_TYPE; i++) { rsdb_exec_fetch(dbconn, &table, "SELECT name FROM sqlite_master WHERE type='table' AND name='%s'", bandb_table[i]); rsdb_exec_fetch_end(dbconn, &table); if(!table.row_count) rsdb_exec(dbconn, NULL, "CREATE TABLE %s (mask1 TEXT, mask2 TEXT, oper TEXT, time INTEGER, perm INTEGER, reason TEXT)", bandb_table[i]); } }
static void parse_ban(bandb_type type, char *parv[], int parc) { const char *mask1 = NULL; const char *mask2 = NULL; const char *oper = NULL; const char *curtime = NULL; const char *reason = NULL; const char *perm = NULL; int para = 1; if(type == BANDB_KLINE) { if(parc != 7) return; } else if(parc != 6) return; mask1 = parv[para++]; if(type == BANDB_KLINE) mask2 = parv[para++]; oper = parv[para++]; curtime = parv[para++]; perm = parv[para++]; reason = parv[para++]; if(!in_transaction) { rsdb_transaction(RSDB_TRANS_START); in_transaction = 1; rb_event_addonce("bandb_commit", bandb_commit, NULL, COMMIT_INTERVAL); } rsdb_exec(NULL, "INSERT INTO %s (mask1, mask2, oper, time, perm, reason) VALUES('%Q', '%Q', '%Q', %s, %s, '%Q')", bandb_table[type], mask1, mask2 ? mask2 : "", oper, curtime, perm, reason); }
static void parse_unban(bandb_type type, char *parv[], int parc) { char *mask1 = NULL; char *mask2 = NULL; if(type == BANDB_KLINE) { if(parc != 3) return; } else if(parc != 2) return; mask1 = parv[1]; if(type == BANDB_KLINE) mask2 = parv[2]; rsdb_exec(dbconn, NULL, "DELETE FROM %s WHERE mask1=%Q AND mask2=%Q", bandb_table[type], mask1, mask2 ? mask2 : ""); }
static void parse_ban(bandb_type type, char *parv[], int parc) { const char *mask1 = NULL; const char *mask2 = NULL; const char *oper = NULL; const char *curtime = NULL; const char *reason = NULL; const char *perm = NULL; int para = 1; if(type == BANDB_KLINE) { if(parc != 7) return; } else if(parc != 6) return; mask1 = parv[para++]; if(type == BANDB_KLINE) mask2 = parv[para++]; oper = parv[para++]; curtime = parv[para++]; perm = parv[para++]; reason = parv[para++]; rsdb_exec(dbconn, NULL, "INSERT INTO %s (mask1, mask2, oper, time, perm, reason) VALUES(%Q, %Q, %Q, %s, %s, %Q)", bandb_table[type], mask1, mask2, oper, curtime, perm, reason); }