Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public GetClientData(Handle:db, client)
- {
- if (db == INVALID_HANDLE) { PrintToServer("[GetClientData] Database not valid!"); return -1; }
- new String:steamid[64];
- if (!GetClientAuthString(client, steamid, sizeof(steamid))) {
- PrintToServer("[GetClientData] GetClientAuthString failed!");
- }
- new String:qstr[128];
- Format(qstr, sizeof(qstr), "SELECT data FROM client_table WHERE steamid='%s'", steamid);
- SQL_LockDatabase(db); new Handle:query = SQL_Query(db, qstr); SQL_UnlockDatabase(db);
- if (query == INVALID_HANDLE) { PrintToServer("[GetClientData] SQL_Query failed!"); return -1; }
- if (SQL_GetRowCount(query) != 1) {
- PrintToServer("[GetClientData] SteamID has zero OR multiple entires!");
- CloseHandle(query);
- return -1;
- } else {
- if (SQL_FetchRow(query) == false) {
- } else {
- new val = SQL_FetchInt(query, 1);
- CloseHandle(query);
- return val;
- }
- }
- }
- public SetClientData(Handle:db, client, val)
- {
- if (db == INVALID_HANDLE) { PrintToServer("[SetClientData] Database not valid!"); return; }
- new String:steamid[64];
- if (!GetClientAuthString(client, steamid, sizeof(steamid))) {
- PrintToServer("[SetClientData] GetClientAuthString failed!");
- }
- new String:qstr[128];
- Format(qstr, sizeof(qstr), "SELECT data FROM client_table WHERE steamid='%s'", steamid);
- SQL_LockDatabase(db); new Handle:query = SQL_Query(db, qstr); SQL_UnlockDatabase(db);
- if (query == INVALID_HANDLE) { PrintToServer("[SetClientData] SQL_Query failed!"); return; }
- if (SQL_GetRowCount(query) == 1) {
- CloseHandle(query);
- Format(qstr, sizeof(qstr), "UPDATE client_table SET data=%d WHERE steamid='%s'", val, steamid);
- if (!SQL_FastQuery(db, qstr)) {
- PrintToServer("[SetClientData] SQL_FastQuery failed (UPDATE)!");
- CloseHandle(query);
- return;
- }
- } else {
- CloseHandle(query);
- Format(qstr, sizeof(qstr), "INSTERT INTO client_table VALUES('%s', %d)", steamid, val);
- if (!SQL_FastQuery(db, qstr)) {
- PrintToServer("[SetClientData] SQL_FastQuery failed! (INSTERT)");
- CloseHandle(query);
- return;
- }
- }
- return;
- }
- public CreateClientDataTable(Handle:db)
- {
- if (db == INVALID_HANDLE) { PrintToServer("[CreateClientDataTable] Database not valid!"); return; }
- if (!SQL_FastQuery(db, "CREATE TABLE client_table (steamid TEXT, data INTEGER)"))
- {
- PrintToServer("[CreateClientDataTable] Failed to create client_table table (already exists?)!");
- return;
- }
- PrintToServer("[CreateClientDataTable] Created client_table table!");
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement