diff --git a/dlls/mysqlx/basic_sql.cpp b/dlls/mysqlx/basic_sql.cpp index 3155ddbe..08f9ff9b 100644 --- a/dlls/mysqlx/basic_sql.cpp +++ b/dlls/mysqlx/basic_sql.cpp @@ -408,6 +408,11 @@ static cell AMX_NATIVE_CALL SQL_SetAffinity(AMX *amx, cell *params) int len; char *str = MF_GetAmxString(amx, params[1], 0, &len); + if (!str[0]) + { + return 1; + } + if (stricmp(str, g_Mysql.NameString()) == 0) { return 1; diff --git a/dlls/mysqlx/module.cpp b/dlls/mysqlx/module.cpp index f02442d6..f96bcae8 100644 --- a/dlls/mysqlx/module.cpp +++ b/dlls/mysqlx/module.cpp @@ -25,8 +25,7 @@ void OnAmxxAttach() MF_AddNatives(g_ThreadSqlNatives); g_MysqlFuncs.prev = (SqlFunctions *)MF_RegisterFunctionEx(&g_MysqlFuncs, SQL_DRIVER_FUNC); if (!MF_RequestFunction("GetDbDriver") - && !MF_FindLibrary("SQLITE", LibType_Library) - && !MF_FindLibrary("sqlitex", LibType_Library)) + && !MF_FindLibrary("SQLITE", LibType_Library)) { MF_AddNatives(g_OldCompatNatives); MF_AddLibraries("dbi", LibType_Class, &g_ident); diff --git a/dlls/mysqlx/mysql2.vcproj b/dlls/mysqlx/mysql2.vcproj index bbb4a6e8..282f694c 100644 --- a/dlls/mysqlx/mysql2.vcproj +++ b/dlls/mysqlx/mysql2.vcproj @@ -33,7 +33,7 @@ g_ThreadQueue; CStack g_FreeThreads; @@ -264,11 +263,11 @@ void OnPluginsLoaded() return; } - if (!g_StringPool.IsThreadable()) + if (!g_QueueLock) { - g_StringPool.SetMutex(g_Threader.MakeMutex()); g_QueueLock = g_Threader.MakeMutex(); } + g_pWorker = new ThreadWorker(&g_Threader, 250); if (!g_pWorker->Start()) { @@ -327,11 +326,10 @@ void OnPluginsUnloading() AtomicResult::AtomicResult() { m_IsFree = true; - m_CurRow = 0; - m_AllocFields = 0; - m_AllocRows = 0; - m_Rows = NULL; - m_Fields = NULL; + m_CurRow = 1; + m_RowCount = NULL; + m_Table = NULL; + m_AllocSize = 0; } AtomicResult::~AtomicResult() @@ -341,20 +339,15 @@ AtomicResult::~AtomicResult() FreeHandle(); } - if (m_AllocFields) + for (size_t i=0; i<=m_AllocSize; i++) { - delete [] m_Fields; - m_AllocFields = 0; - m_Fields = NULL; - } - if (m_AllocRows) - { - for (unsigned int i=0; ic_str(), name) == 0) { - if (*columnId) + if (columnId) + { *columnId = i; + } return true; } } + if (columnId) + { + *columnId = -1; + } + return false; } @@ -392,7 +393,9 @@ const char *AtomicResult::FieldNumToName(unsigned int num) if (num >= m_FieldCount) return NULL; - return g_StringPool.GetString(m_Fields[num]); + assert(m_Table[num] != NULL); + + return m_Table[num]->c_str(); } double AtomicResult::GetDouble(unsigned int columnId) @@ -429,7 +432,11 @@ const char *AtomicResult::GetString(unsigned int columnId) if (columnId >= m_FieldCount) return NULL; - return g_StringPool.GetString(m_Rows[m_CurRow][columnId]); + size_t idx = (m_CurRow * m_FieldCount) + columnId; + + assert(m_Table[idx] != NULL); + + return m_Table[idx]->c_str(); } IResultRow *AtomicResult::GetRow() @@ -439,7 +446,7 @@ IResultRow *AtomicResult::GetRow() bool AtomicResult::IsDone() { - if (m_CurRow >= m_RowCount) + if (m_CurRow > m_RowCount) return true; return false; @@ -456,19 +463,6 @@ void AtomicResult::_InternalClear() return; m_IsFree = true; - - g_StringPool.StartHardLock(); - - for (unsigned int i=0; iFieldCount(); m_RowCount = rs->RowCount(); - if (m_RowCount > m_AllocRows) + m_CurRow = 1; + + size_t newTotal = (m_RowCount * m_FieldCount) + m_FieldCount; + if (newTotal > m_AllocSize) { - /** allocate new array, zero it */ - stridx_t **newRows = new stridx_t *[m_RowCount]; - memset(newRows, 0, m_RowCount * sizeof(stridx_t *)); - /** if we have a new field count, just delete all the old stuff. */ - if (m_FieldCount > m_AllocFields) + SourceHook::String **table = new SourceHook::String *[newTotal]; + memset(table, 0, newTotal * sizeof(SourceHook::String *)); + if (m_Table) { - for (unsigned int i=0; i m_AllocFields) - { - delete [] m_Fields; - m_Fields = new stridx_t[m_FieldCount]; - m_AllocFields = m_FieldCount; - } - m_CurRow = 0; - - g_StringPool.StartHardLock(); - - IResultRow *row; - unsigned int idx = 0; - while (!rs->IsDone()) - { - row = rs->GetRow(); - for (size_t i=0; iGetString(i)); - rs->NextRow(); - idx++; + m_Table = table; + m_AllocSize = newTotal; } for (unsigned int i=0; iFieldNumToName(i)); - - g_StringPool.StopHardLock(); -} - -/********************* - * STRING POOL STUFF * - *********************/ - -StringPool::StringPool() -{ - m_mutex = NULL; - m_stoplock = false; -} - -StringPool::~StringPool() -{ - if (m_stoplock) - StopHardLock(); - - if (m_mutex) - UnsetMutex(); - - for (size_t i=0; i= (int)m_Strings.size() || !m_UseTable[idx]) - return NULL; - - return m_Strings[idx]->c_str(); -} - -void StringPool::FreeString(stridx_t idx) -{ - if (idx < 0 || idx >= (int)m_Strings.size()) - return; - - if (!m_stoplock && m_mutex) - m_mutex->Lock(); - - if (m_UseTable[idx]) { - m_FreeStrings.push(idx); - m_UseTable[idx] = 0; + if (m_Table[i]) + { + m_Table[i]->assign(rs->FieldNumToName(i)); + } else { + m_Table[i] = new SourceHook::String(rs->FieldNumToName(i)); + } } - if (!m_stoplock && m_mutex) - m_mutex->Unlock(); -} - -stridx_t StringPool::MakeString(const char *str) -{ - if (!str) - return StringPool::NullString; - - if (!m_stoplock && m_mutex) - m_mutex->Lock(); - - stridx_t idx; - - if (m_FreeStrings.empty()) + IResultRow *row; + unsigned int idx = m_FieldCount; + while (!rs->IsDone()) { - idx = static_cast(m_Strings.size()); - SourceHook::String *shString = new SourceHook::String(str); - m_Strings.push_back(shString); - m_UseTable.push_back(1); - } else { - idx = m_FreeStrings.front(); - m_FreeStrings.pop(); - m_UseTable[idx] = 1; - m_Strings[idx]->assign(str); - } - - if (!m_stoplock && m_mutex) - m_mutex->Unlock(); - - return idx; -} - -void StringPool::SetMutex(IMutex *m) -{ - m_mutex = m; -} - -void StringPool::UnsetMutex() -{ - if (m_mutex) - { - m_mutex->DestroyThis(); - m_mutex = NULL; + row = rs->GetRow(); + for (unsigned int i=0; iassign(row->GetString(i)); + } else { + m_Table[idx] = new SourceHook::String(row->GetString(i)); + } + } + rs->NextRow(); } } -void StringPool::StartHardLock() -{ - if (m_stoplock) - return; - - m_mutex->Lock(); - m_stoplock = true; -} - -void StringPool::StopHardLock() -{ - if (!m_stoplock) - return; - - m_mutex->Unlock(); - m_stoplock = false; -} AMX_NATIVE_INFO g_ThreadSqlNatives[] = { diff --git a/dlls/mysqlx/threading.h b/dlls/mysqlx/threading.h index 25b084d7..e17045cc 100644 --- a/dlls/mysqlx/threading.h +++ b/dlls/mysqlx/threading.h @@ -14,32 +14,6 @@ struct QueuedResultInfo bool query_success; }; -typedef int stridx_t; - -class StringPool -{ -public: - StringPool(); - ~StringPool(); - void SetMutex(IMutex *m); - void UnsetMutex(); - bool IsThreadable(); -public: - stridx_t MakeString(const char *str); - void FreeString(stridx_t idx); - const char *GetString(stridx_t idx); - void StartHardLock(); - void StopHardLock(); -public: - static const int NullString = -1; -private: - CStack m_FreeStrings; - CVector m_UseTable; - CVector m_Strings; - IMutex *m_mutex; - bool m_stoplock; -}; - class AtomicResult : public IResultSet, public IResultRow @@ -73,10 +47,8 @@ private: private: unsigned int m_RowCount; unsigned int m_FieldCount; - unsigned int m_AllocFields; - unsigned int m_AllocRows; - stridx_t *m_Fields; - stridx_t **m_Rows; + size_t m_AllocSize; + SourceHook::String **m_Table; unsigned int m_CurRow; bool m_IsFree; };