Switch and symbol already defined -
Misiur - 11.02.2013
pawn Код:
switch(var) {
case 0: {
new tmp[3][32];
}
case 1: {
new tmp[5][16];
}
}
This gives me warning about redefinition of symbol tmp. This would make sense if tmp value was exactly the same, but for diffrent cases I need diffrent string-array size. How can I solve this?
Re: Switch and symbol already defined -
LarzI - 11.02.2013
What exactly do you intend to achieve?
Re: Switch and symbol already defined -
Misiur - 11.02.2013
Simple handling of a sql query with single callback for few selects. I know that I could simply move biggest tmp array before switch, but I assumed that I don't want the biggest array created on every query
Re: Switch and symbol already defined -
Misiur - 11.02.2013
This is some dull initial dataload, so I don't need additional logic for processing
pawn Код:
#define _NS_: Database__
#define DB_HOST "localhost"
#define DB_USER "root"
#define DB_PASS ""
#define DB_NAME "trucking"
#define DB_PREFIX ""
#include <YSI\y_hooks>
enum {
TB_USERS,
TB_TRUCKS,
TB_CARGOS,
TB_PLACES
}
static const dbtables[][32] = {
DB_PREFIX"users",
DB_PREFIX"trucks",
DB_PREFIX"cargos",
DB_PREFIX"places"
};
enum {
THREAD_DATALOAD,
THREAD_TRUCKLOAD,
THREAD_CARGOLOAD,
THREAD_PLACESLOAD
}
static dbhandle;
forward OnDataLoadFinish(resultid);
hook OnGameModeInit() {
dbhandle = mysql_connect(DB_HOST, DB_USER, DB_NAME, DB_PASS);
if(1 == mysql_ping()) {
mysql_debug(DEBUG);
Debug("Mysql connection succeeded");
mysql_set_charset("utf8_unicode_ci", dbhandle);
new tmp[32];
mysql_format(dbhandle, tmp, "SELECT * FROM `%s`", dbtables[TB_TRUCKS]);
mysql_function_query(dbhandle, tmp, true, "OnDataLoadFinish", "i", THREAD_TRUCKLOAD);
mysql_format(dbhandle, tmp, "SELECT * FROM `%s`", dbtables[TB_CARGOS]);
mysql_function_query(dbhandle, tmp, true, "OnDataLoadFinish", "i", THREAD_CARGOLOAD);
mysql_format(dbhandle, tmp, "SELECT * FROM `%s`", dbtables[TB_PLACES]);
mysql_function_query(dbhandle, tmp, true, "OnDataLoadFinish", "i", THREAD_PLACESLOAD);
} else {
printf("Mysql connection error!");
}
return 1;
}
hook OnGameModeExit() {
mysql_close(dbhandle);
return 1;
}
public OnDataLoadFinish(resultid) {
new rows, fields, i;
cache_get_data(rows, fields, dbhandle);
switch(resultid) {
case THREAD_TRUCKLOAD: {
new data[6][21];
for(; i != rows; i++) {
cache_get_row(i, 0, data[0], dbhandle);
cache_get_row(i, 1, data[1], dbhandle);
cache_get_row(i, 2, data[2], dbhandle);
cache_get_row(i, 3, data[3], dbhandle);
cache_get_row(i, 4, data[4], dbhandle);
cache_get_row(i, 5, data[5], dbhandle);
Modules__Vehicles__VehicleTypes[i][typeId] = strval(data[0]);
Modules__Vehicles__VehicleTypes[i][carType] = strval(data[2]);
Modules__Vehicles__VehicleTypes[i][modelId] = strval(data[3]);
Modules__Vehicles__VehicleTypes[i][maxFuel] = strval(data[4]);
Modules__Vehicles__VehicleTypes[i][maxLoad] = strval(data[5]);
Modules__Vehicles__VehicleTypes[i][price] = strval(data[5]);
}
}
case THREAD_CARGOLOAD: {
new data[5][32];
for(; i != rows; i++) {
cache_get_row(i, 0, data[0], dbhandle);
cache_get_row(i, 1, data[1], dbhandle);
cache_get_row(i, 2, data[2], dbhandle);
cache_get_row(i, 3, data[3], dbhandle);
cache_get_row(i, 4, data[4], dbhandle);
Modules__Cargo__Cargos[i][id] = strval(data[0]);
strcpy(Modules__Cargo__Cargos[i][name], data[1]);
Modules__Cargo__Cargos[i][weightRange][0] = strval(data[2]);
Modules__Cargo__Cargos[i][weightRange][1] = strval(data[3]);
//Fix teh constant
sscanf(data[4], "p<,>A<i>["MAX_VEHICLE_TYPES"]", Modules__Cargo__Cargos[i][carsPermitted]);
}
}
}
return 1;
}
#undef _NS_
Re: Switch and symbol already defined -
Misiur - 11.02.2013
So multiple public functions are better than additional switch during execution of single one?
Re: Switch and symbol already defined -
Misiur - 11.02.2013
I don't have much experience with mysql in pawn. Does this mean that I have to use non-cached queries and parse them with sscanf?
Re: Switch and symbol already defined -
Misiur - 11.02.2013
I reread the caching tutorial and this post got my attention
http://forum.sa-mp.com/showpost.php?...54&postcount=6 won't this be a performance problem when I'll get >~200 rows of data?