Re: Multiple Statement Queries and issues.
Posted by: Katsu Katayama
Date: March 05, 2010 05:38PM

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...
}

Options: ReplyQuote


Subject
Views
Written By
Posted
Re: Multiple Statement Queries and issues.
361
March 05, 2010 05:38PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.