Advertisement
captmicro

Unknown

Oct 3rd, 2010
338
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.50 KB | None | 0 0
  1. public GetClientData(Handle:db, client)
  2. {
  3.     if (db == INVALID_HANDLE) { PrintToServer("[GetClientData] Database not valid!"); return -1; }
  4.    
  5.     new String:steamid[64];
  6.     if (!GetClientAuthString(client, steamid, sizeof(steamid))) {
  7.         PrintToServer("[GetClientData] GetClientAuthString failed!");
  8.     }
  9.    
  10.     new String:qstr[128];
  11.     Format(qstr, sizeof(qstr), "SELECT data FROM client_table WHERE steamid='%s'", steamid);
  12.     SQL_LockDatabase(db); new Handle:query = SQL_Query(db, qstr); SQL_UnlockDatabase(db);
  13.     if (query == INVALID_HANDLE) { PrintToServer("[GetClientData] SQL_Query failed!"); return -1; }
  14.    
  15.     if (SQL_GetRowCount(query) != 1) {
  16.         PrintToServer("[GetClientData] SteamID has zero OR multiple entires!");
  17.         CloseHandle(query);
  18.         return -1;
  19.     } else {
  20.         if (SQL_FetchRow(query) == false) {
  21.        
  22.         } else {
  23.             new val = SQL_FetchInt(query, 1);
  24.             CloseHandle(query);
  25.             return val;
  26.         }
  27.     }
  28. }
  29.  
  30. public SetClientData(Handle:db, client, val)
  31. {
  32.     if (db == INVALID_HANDLE) { PrintToServer("[SetClientData] Database not valid!"); return; }
  33.    
  34.     new String:steamid[64];
  35.     if (!GetClientAuthString(client, steamid, sizeof(steamid))) {
  36.         PrintToServer("[SetClientData] GetClientAuthString failed!");
  37.     }
  38.    
  39.     new String:qstr[128];
  40.     Format(qstr, sizeof(qstr), "SELECT data FROM client_table WHERE steamid='%s'", steamid);
  41.     SQL_LockDatabase(db); new Handle:query = SQL_Query(db, qstr); SQL_UnlockDatabase(db);
  42.     if (query == INVALID_HANDLE) { PrintToServer("[SetClientData] SQL_Query failed!"); return; }
  43.    
  44.     if (SQL_GetRowCount(query) == 1) {
  45.         CloseHandle(query);
  46.         Format(qstr, sizeof(qstr), "UPDATE client_table SET data=%d WHERE steamid='%s'", val, steamid);
  47.         if (!SQL_FastQuery(db, qstr)) {
  48.             PrintToServer("[SetClientData] SQL_FastQuery failed (UPDATE)!");
  49.             CloseHandle(query);
  50.             return;
  51.         }
  52.     } else {
  53.         CloseHandle(query);
  54.         Format(qstr, sizeof(qstr), "INSTERT INTO client_table VALUES('%s', %d)", steamid, val);
  55.         if (!SQL_FastQuery(db, qstr)) {
  56.             PrintToServer("[SetClientData] SQL_FastQuery failed! (INSTERT)");
  57.             CloseHandle(query);
  58.             return;
  59.         }
  60.     }
  61.    
  62.     return;
  63. }
  64.  
  65. public CreateClientDataTable(Handle:db)
  66. {
  67.     if (db == INVALID_HANDLE) { PrintToServer("[CreateClientDataTable] Database not valid!"); return; }
  68.     if (!SQL_FastQuery(db, "CREATE TABLE client_table (steamid TEXT, data INTEGER)"))
  69.     {
  70.         PrintToServer("[CreateClientDataTable] Failed to create client_table table (already exists?)!");
  71.         return;
  72.     }
  73.     PrintToServer("[CreateClientDataTable] Created client_table table!");
  74.     return;
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement