1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2025-06-19 16:47:14 +02:00

Fixed excpetion throwing in SQLite document to that generated corrupted messages because snprintf was used instead of vsnprintf.

Revised most of the SQLite plugin and cleaned code.
This commit is contained in:
Sandu Liviu Catalin
2016-04-02 12:11:14 +03:00
parent b6466b9181
commit fab15840cb
9 changed files with 524 additions and 310 deletions

View File

@ -6,12 +6,12 @@
#include "Column.hpp"
// --------------------------------------------------------------------------------------------
#include <sqrat.h>
#include <cstdio>
#include <cstdlib>
#include <cstdarg>
// --------------------------------------------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <sqrat.h>
// --------------------------------------------------------------------------------------------
#if defined(WIN32) || defined(_WIN32)
@ -21,14 +21,14 @@
namespace SqMod {
// --------------------------------------------------------------------------------------------
PluginFuncs* _Func = NULL;
PluginCallbacks* _Clbk = NULL;
PluginInfo* _Info = NULL;
PluginFuncs* _Func = nullptr;
PluginCallbacks* _Clbk = nullptr;
PluginInfo* _Info = nullptr;
// --------------------------------------------------------------------------------------------
HSQAPI _SqAPI = NULL;
HSQEXPORTS _SqMod = NULL;
HSQUIRRELVM _SqVM = NULL;
HSQAPI _SqAPI = nullptr;
HSQEXPORTS _SqMod = nullptr;
HSQUIRRELVM _SqVM = nullptr;
/* ------------------------------------------------------------------------------------------------
* Bind speciffic functions to certain server events.
@ -54,7 +54,9 @@ void OnSquirrelInitialize()
_SqMod = sq_api_import(_Func);
// Did we failed to obtain the plugin exports?
if(!_SqMod)
{
OutputError("Failed to attach [%s] on host plugin.", SQSQLITE_NAME);
}
else
{
// Obtain the Squirrel API
@ -71,12 +73,16 @@ void OnSquirrelLoad()
{
// Make sure that we have a valid plugin API
if (!_SqMod)
return; /* Unable to proceed. */
{
return; // Unable to proceed.
}
// Obtain the Squirrel API and VM
_SqVM = _SqMod->GetSquirrelVM();
// Make sure that a valid virtual machine exists
if (!_SqVM)
return; /* Unable to proceed. */
{
return; // Unable to proceed.
}
// Set this as the default database
DefaultVM::Set(_SqVM);
// Register the module API
@ -92,7 +98,7 @@ void OnSquirrelTerminate()
{
OutputMessage("Terminating: %s", SQSQLITE_NAME);
// Release the current database (if any)
DefaultVM::Set(NULL);
DefaultVM::Set(nullptr);
}
/* --------------------------------------------------------------------------------------------
@ -101,10 +107,12 @@ void OnSquirrelTerminate()
bool CheckAPIVer(CCStr ver)
{
// Obtain the numeric representation of the API version
long vernum = strtol(ver, NULL, 10);
long vernum = strtol(ver, nullptr, 10);
// Check against version mismatch
if (vernum == SQMOD_API_VER)
{
return true;
}
// Log the incident
OutputError("API version mismatch on %s", SQSQLITE_NAME);
OutputMessage("=> Requested: %ld Have: %ld", vernum, SQMOD_API_VER);
@ -121,7 +129,9 @@ static int OnInternalCommand(unsigned int type, const char * text)
{
case SQMOD_INITIALIZE_CMD:
if (CheckAPIVer(text))
{
OnSquirrelInitialize();
}
break;
case SQMOD_LOAD_CMD:
OnSquirrelLoad();
@ -159,9 +169,9 @@ void BindCallbacks()
// ------------------------------------------------------------------------------------------------
void UnbindCallbacks()
{
_Clbk->OnInitServer = NULL;
_Clbk->OnInternalCommand = NULL;
_Clbk->OnShutdownServer = NULL;
_Clbk->OnInitServer = nullptr;
_Clbk->OnInternalCommand = nullptr;
_Clbk->OnShutdownServer = nullptr;
}
// --------------------------------------------------------------------------------------------
@ -199,7 +209,7 @@ void RegisterAPI(HSQUIRRELVM vm)
.Prop(_SC("TotalChanges"), &Connection::GetTotalChanges)
.Prop(_SC("Trace"), &Connection::GetTracing, &Connection::SetTracing)
.Prop(_SC("Profile"), &Connection::GetProfiling, &Connection::SetProfiling)
.Prop(_SC("BusyTimeout"), (Int32 (Connection::*)(void) const)(NULL), &Connection::SetBusyTimeout)
.Prop(_SC("BusyTimeout"), (Int32 (Connection::*)(void) const)(nullptr), &Connection::SetBusyTimeout)
.Prop(_SC("QueueSize"), &Connection::QueueSize)
// Member Methods
.Func(_SC("Release"), &Connection::Release)
@ -584,7 +594,7 @@ void RegisterAPI(HSQUIRRELVM vm)
.Const(_SC("NOTICE"), SQLITE_NOTICE)
.Const(_SC("NOTICE_RECOVER_ROLLBACK"), SQLITE_NOTICE_RECOVER_ROLLBACK)
.Const(_SC("NOTICE_RECOVER_WAL"), SQLITE_NOTICE_RECOVER_WAL)
.Const(_SC("NULL"), SQLITE_NULL)
.Const(_SC("nullptr"), SQLITE_NULL)
.Const(_SC("OK"), SQLITE_OK)
.Const(_SC("OPEN_AUTOPROXY"), SQLITE_OPEN_AUTOPROXY)
.Const(_SC("OPEN_CREATE"), SQLITE_OPEN_CREATE)