Is Field Exists - SQLite - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Is Field Exists - SQLite (
/showthread.php?tid=488756)
Is Field Exists - SQLite -
Quis - 19.01.2014
Hello
Does anyone have a way to check that is field exists in sqlite database?
@EDIT
Is there faster way?
Код:
new DBResult:fieldsCheck = db_query(serverDB, "SELECT * FROM `"PREFIX"players` LIMIT 1"),
numFields = db_num_fields(fieldsCheck),
bool:dataExists = false;
for(new field=0; field<numFields; field++)
{
new fieldName[64];
db_field_name(fieldsCheck, field, fieldName, sizeof(fieldName));
if(!strlen(fieldName))
continue;
if(!strcmp(fieldName, data, true))
dataExists = true;
}
}
db_free_result(fieldsCheck);
Re: Is Field Exists - SQLite -
SyntaxQ - 19.01.2014
pawn Код:
new DB: Result, query[128], str[128];
format(query, sizeof(query), "SELECT * FROM players WHERE username = '%s' LIMIT 0, 1", PlayerInfo[playerid][Name]); // You need to get the player name On Player Connect & save it in PlayerInfo[playerid][Name]..
Result = db_query(Database, query);
if (db_num_rows(Result)) // If something came up..
{
db_get_field_assoc(Result, "admin", query, 3); // It will get the data in the field 'admin'..
PlayerInfo[playerid][pAdmin] = strval(query); // Converting it to integer..
format(str, sizeof(str), "Your admin level is: %d", PlayerInfo[playerid][pAdmin]);
SendClientMessage(playerid, -1, str); // It will show the player his admin level
}
db_free_result(Result);
This is just an example. I'm not sure that this is the right or there is any faster way to get data...
(+ I'm not a professional.)