2014-08-04 10:49:44 +00:00
|
|
|
// vim: set ts=4 sw=4 tw=99 noet:
|
|
|
|
//
|
|
|
|
// AMX Mod X, based on AMX Mod by Aleksander Naszko ("OLO").
|
|
|
|
// Copyright (C) The AMX Mod X Development Team.
|
|
|
|
//
|
|
|
|
// This software is licensed under the GNU General Public License, version 3 or higher.
|
|
|
|
// Additional exceptions apply. For full license details, see LICENSE.txt or visit:
|
|
|
|
// https://alliedmods.net/amxmodx-license
|
|
|
|
|
|
|
|
//
|
|
|
|
// SQLite Module
|
|
|
|
//
|
|
|
|
|
2006-06-03 19:52:21 +00:00
|
|
|
#include "amxxmodule.h"
|
|
|
|
#include "sqlite_header.h"
|
|
|
|
#include "sqlheaders.h"
|
|
|
|
|
2006-06-04 04:29:46 +00:00
|
|
|
static int g_ident = 0;
|
2006-06-03 19:52:21 +00:00
|
|
|
|
2017-03-11 18:26:25 +00:00
|
|
|
SqlFunctions g_SqliteFuncs =
|
2006-06-03 19:52:21 +00:00
|
|
|
{
|
|
|
|
&g_Sqlite,
|
|
|
|
SetMysqlAffinity,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
int SetMysqlAffinity(AMX *amx)
|
|
|
|
{
|
|
|
|
MF_AmxReRegister(amx, g_BaseSqlNatives, -1);
|
|
|
|
MF_AmxReRegister(amx, g_ThreadSqlNatives, -1);
|
|
|
|
|
2006-06-03 23:13:02 +00:00
|
|
|
return 1;
|
2006-06-03 19:52:21 +00:00
|
|
|
}
|
|
|
|
|
2006-06-03 22:26:43 +00:00
|
|
|
bool DirExists(const char *dir)
|
|
|
|
{
|
|
|
|
#if defined WIN32 || defined _WIN32
|
|
|
|
DWORD attr = GetFileAttributes(dir);
|
|
|
|
|
|
|
|
if (attr == INVALID_FILE_ATTRIBUTES)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (attr & FILE_ATTRIBUTE_DIRECTORY)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
#else
|
|
|
|
struct stat s;
|
|
|
|
|
|
|
|
if (stat(dir, &s) != 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (S_ISDIR(s.st_mode))
|
|
|
|
return true;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2006-06-03 19:52:21 +00:00
|
|
|
void OnAmxxAttach()
|
|
|
|
{
|
|
|
|
MF_AddNatives(g_BaseSqlNatives);
|
|
|
|
MF_AddNatives(g_ThreadSqlNatives);
|
|
|
|
g_SqliteFuncs.prev = (SqlFunctions *)MF_RegisterFunctionEx(&g_SqliteFuncs, SQL_DRIVER_FUNC);
|
|
|
|
|
|
|
|
MF_AddLibraries("dbi", LibType_Class, &g_ident);
|
|
|
|
|
|
|
|
//override any mysqlx old compat stuff
|
|
|
|
MF_AddNatives(g_OldCompatNatives);
|
2006-06-03 22:26:43 +00:00
|
|
|
MF_OverrideNatives(g_OldCompatNatives, MODULE_NAME);
|
|
|
|
|
|
|
|
char path[255];
|
2017-03-11 18:26:25 +00:00
|
|
|
MF_BuildPathnameR(path, sizeof(path), "%s/sqlite3", MF_GetLocalInfo("amxx_datadir", "addons/amxmodx/data"));
|
2006-06-03 22:26:43 +00:00
|
|
|
if (!DirExists(path))
|
|
|
|
{
|
|
|
|
mkdir(path
|
2013-02-13 07:14:37 +00:00
|
|
|
#if defined(__linux__) || defined(__APPLE__)
|
2006-06-03 22:26:43 +00:00
|
|
|
, 0775
|
|
|
|
#endif
|
|
|
|
);
|
|
|
|
}
|
2006-06-03 19:52:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void OnAmxxDetach()
|
|
|
|
{
|
|
|
|
ShutdownThreading();
|
|
|
|
MF_RemoveLibraries(&g_ident);
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnPluginsUnloaded()
|
|
|
|
{
|
|
|
|
FreeAllHandles(Handle_OldResult);
|
|
|
|
FreeAllHandles(Handle_OldDb);
|
|
|
|
FreeAllHandles(Handle_Connection);
|
|
|
|
}
|
|
|
|
|
2006-08-28 21:21:06 +00:00
|
|
|
extern "C" void __cxa_pure_virtual(void)
|
|
|
|
{
|
|
|
|
}
|