#include #include #include #include #include #include long long moveFrog(MYSQL *mysql); my_bool move_neutrals_init(UDF_INIT *initid,UDF_ARGS *args,char *message); void move_neutrals_deinit(UDF_INIT *initid); long long move_neutrals(UDF_INIT *initid,UDF_ARGS *args,char *is_null,char *error); my_bool move_neutrals_init( UDF_INIT *initid , UDF_ARGS *args , char *message ){ my_bool status; if(args->arg_count!=2){ strcpy( message , "Expect exactly 2 argument" ); status = 1; } else if(*((longlong*)args->args[1])<10){ strcpy( message , "Not neutral's player_num <10." ); status = 1; } else { status = 0; } return status; } void move_neutrals_deinit( UDF_INIT *initid ){ } long long move_neutrals( UDF_INIT *initid , UDF_ARGS *args , char *is_null , char *error ){ //vars MYSQL* mysql = NULL; longlong retval = 0; //init mysql mysql = mysql_init( mysql ); if ( !mysql ) { fprintf( stderr, "Error on Init: %s\n", mysql_error( mysql )); *error = 1; return 0; } //connect if ( !mysql_real_connect( mysql, "127.0.0.1", "root", "", "test", 13000, NULL, CLIENT_MULTI_RESULTS ) ) { fprintf( stderr, "Error on Connect: %s\n", mysql_error( mysql )); *error = 1; return 0; } moveFrog(mysql); //close mysql_close( mysql ); return 1; } long long moveFrog(MYSQL *mysql){ char query[450]; int i; char ci[10]; MYSQL_RES *qryResult; int status; for (i=0;i<2;i++) { query[0] = 0; //itoa(i,ci,10); strcpy(query,"CALL player_move_unit('10')"); fprintf( stderr, "<<>>: %s\n", query); if ( mysql_real_query( mysql, query, strlen(query) ) ) { fprintf( stderr, "Error on Query: %s\n", mysql_error( mysql )); return -1; } do { // did current statement return data? qryResult = mysql_store_result(mysql); if (qryResult) { // yes; process rows and free the result set while(mysql_fetch_row(qryResult)); mysql_free_result(qryResult); } else // no result set or error { if (mysql_field_count(mysql) == 0) { fprintf( stderr,"%lld rows affected\n", mysql_affected_rows(mysql)); } else // some error occurred { fprintf( stderr,"Could not retrieve result set\n"); break; } } // more results? -1 = no, >0 = error, 0 = yes (keep looping) mysql_next_result(mysql); status = -1; if (status > 0) fprintf( stderr,"Could not execute statement\n"); } while (status == 0); } return 1; }