Re: Multiple Statement Queries and issues.
my initializer:
void cql_init(){
int opt_flags;
opt_flags |= CLIENT_MULTI_STATEMENTS;
db = mysql_init(NULL);
if(!mysql_real_connect(db,NULL,"root","password","wake",0,NULL,opt_flags)){
log_f("cql_init() Error: %s", mysql_error(db));
return;
}
}
My loader:
void cql_load_db(){
MYSQL_RES *res;
MYSQL_ROW row;
int i = 0,finished = false,status;
for(int n = 0;n < MAX_GUILD;n++)
init_blankguild(n);
log_f("Loading dbs.");
if(mysql_query(db,"SELECT * FROM table1; SELECT * FROM table2;")){
//change the above to if(mysql_query(db,"SELECT * FROM table1;")){
//and no crashes occur
log_f("cql_load_db() Error: %s",mysql_error(db));
return;
}
do{
log_f("1");
res = mysql_store_result(db);
if(res){
cql_process_set(res);
mysql_free_result(res);
}
else{
if(!mysql_field_count(db))
log_f("cql_load_db() : Number of rows affected: %lu\n",(unsigned long)mysql_affected_rows(db));
else{
log_f("cql_load_db() : Could not retrieve result set.");
finished = true;
}
}
status = mysql_next_result(db);
if(status != 0){
finished = true;
if(status > 0)
log_f("cql_load_db() : Could not execute statement.");
}
}while(!finished);
}
The processing function is basically:
void cql_process_set(MYSQL_RES *res){
MYSQL_FIELD *field = mysql_fetch_field(res);
if(!str_cmp(field->table,"table1"))
cql_process_table1(res,field);
else if(!str_cmp(field->table,"table2"))
cql_process_table2(res,field);
}
void cql_process_table1(MYSQL_RES *res,MYSQL_FIELD *field){
while((row = mysql_fetch_row(res))){
structa.name = str_dup(row[1]);
etc...
}