Is Field Exists - SQLite
#1

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);
Reply
#2

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.)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)