Advertisement
Guest User

Untitled

a guest
Mar 21st, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.94 KB | None | 0 0
  1. bool C_MetaverseManager::LoadSQLKevValues(const char* tableName, const char* id, KeyValues* kv, sqlite3* pDb)
  2. {
  3.     if (!pDb)
  4.         pDb = m_db;
  5.  
  6.     sqlite3_stmt *stmt = NULL;
  7.     //DevMsg("loading from table name: %s _id %s\n", tableName, id);
  8.     int rc = sqlite3_prepare(pDb, VarArgs("SELECT * from %s WHERE id = \"%s\"", tableName, id), -1, &stmt, NULL);
  9.     if (rc != SQLITE_OK)
  10.         DevMsg("prepare failed: %s\n", sqlite3_errmsg(pDb));
  11.  
  12.     bool bSuccess = false;
  13.     int length;
  14.     if (sqlite3_step(stmt) == SQLITE_ROW)   // THIS IS WHERE THE LOOP CAN BE BROKEN UP AT!!
  15.     {
  16.         length = sqlite3_column_bytes(stmt, 1);
  17.  
  18.         if (length > 0)
  19.         {
  20.             CUtlBuffer buf(0, length, 0);
  21.             buf.CopyBuffer(sqlite3_column_blob(stmt, 1), length);
  22.             if (kv->ReadAsBinary(buf))
  23.                 bSuccess = true;
  24.             buf.Purge();
  25.         }
  26.         else
  27.             bSuccess = false;
  28.     }
  29.     sqlite3_finalize(stmt); // TODO: error checking?  Maybe not needed, if this is like a close() operation.
  30.  
  31.     return bSuccess;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement