Advertisement
S4T3K

Untitled

Sep 1st, 2014
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.42 KB | None | 0 0
  1. // native mysql_query_file(conHandle, const file[])
  2.  
  3. AMX_DECLARE_NATIVE(Native::mysql_query_file)
  4. {
  5.     const char
  6.         *dir = NULL;
  7.  
  8.     const unsigned int connection_handle = params[1];
  9.     amx_StrParam(amx, params[2], dir);
  10.  
  11.     if (!CMySQLHandle::IsValid(connection_handle))
  12.         return ERROR_INVALID_CONNECTION_HANDLE("mysql_query_file", connection_handle);
  13.  
  14.     std::ifstream file(dir);
  15.     if ((!file) && (CLog::Get()->IsLogLevel(LOG_DEBUG)))
  16.         return CLog::Get()->LogFunction(LOG_ERROR, "mysql_query_file", "cannot open directory \"%s\"", dir);
  17.  
  18.     string line;
  19.     bool done = false;
  20.  
  21.     CMySQLHandle *Handle = CMySQLHandle::GetHandle(connection_handle);
  22.     CMySQLQuery query;
  23.     query.Handle = Handle;
  24.  
  25.     while (getline(file, line))
  26.     {
  27.         for (unsigned int i(0); i < line.length(); ++i)
  28.         {
  29.             if (line[i] == ';')
  30.             {
  31.                 string toAssign(line.substr(0, i));
  32.                 query.Query + toAssign;
  33.                 query.Unthreaded = true;
  34.                 query.Execute(Handle->GetMainConnection()->GetMysqlPtr());
  35.                 query.Query.clear();
  36.                 done = true;
  37.                 if (CLog::Get()->IsLogLevel(LOG_DEBUG))
  38.                 {
  39.                     string short_query(query.Query);
  40.                     if (MySQLOptions.Log_TruncateData)
  41.                         short_query.resize(64);
  42.                     CLog::Get()->LogFunction(LOG_DEBUG, "mysql_query_file", "connection: %d, query: \"%s\"", connection_handle, short_query.c_str());
  43.                 }
  44.                 break;
  45.             }
  46.         }
  47.         if (done)
  48.         {
  49.             done = false;
  50.             continue;
  51.         }
  52.         query.Query + line;
  53.     }
  54.     return 1;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement