diff --git a/dlls/sqlite/basic_sql.cpp b/dlls/sqlite/basic_sql.cpp
index 3eec291a..36cebfc3 100644
--- a/dlls/sqlite/basic_sql.cpp
+++ b/dlls/sqlite/basic_sql.cpp
@@ -413,6 +413,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_Sqlite.NameString()) == 0)
{
return 1;
diff --git a/dlls/sqlite/msvc7/sqlite_amxx.vcproj b/dlls/sqlite/msvc7/sqlite_amxx.vcproj
index b9f97519..9ff2afbb 100644
--- a/dlls/sqlite/msvc7/sqlite_amxx.vcproj
+++ b/dlls/sqlite/msvc7/sqlite_amxx.vcproj
@@ -35,7 +35,7 @@
Name="VCCustomBuildTool"/>
g_ThreadQueue;
CStack g_FreeThreads;
@@ -260,9 +259,8 @@ 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);
@@ -317,17 +315,16 @@ void OnPluginsUnloading()
}
/***********************
- * ATOMIC RESULT STUFF *
- ***********************/
+* ATOMIC RESULT STUFF *
+***********************/
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()
@@ -337,20 +334,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;
}
@@ -388,7 +388,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)
@@ -416,7 +418,7 @@ const char *AtomicResult::GetRaw(unsigned int columnId, size_t *length)
const char *AtomicResult::GetStringSafe(unsigned int columnId)
{
const char *str = GetString(columnId);
-
+
return str ? str : "";
}
@@ -425,7 +427,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()
@@ -435,7 +441,7 @@ IResultRow *AtomicResult::GetRow()
bool AtomicResult::IsDone()
{
- if (m_CurRow >= m_RowCount)
+ if (m_CurRow > m_RowCount)
return true;
return false;
@@ -452,19 +458,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/sqlite/threading.h b/dlls/sqlite/threading.h
index 92147176..238840b6 100644
--- a/dlls/sqlite/threading.h
+++ b/dlls/sqlite/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;
};