2006-06-03 23:52:21 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include "SqliteDriver.h"
|
|
|
|
#include "SqliteDatabase.h"
|
|
|
|
#include "SqliteQuery.h"
|
|
|
|
|
|
|
|
#if defined WIN32 && !defined vsnprintf
|
|
|
|
#define vsnprintf _vsnprintf
|
|
|
|
#endif
|
|
|
|
|
|
|
|
using namespace SourceMod;
|
|
|
|
|
|
|
|
SqliteDatabase::SqliteDatabase(sqlite3 *sql, SqliteDriver *drvr) :
|
|
|
|
m_pSql(sql), m_pParent(drvr)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
SqliteDatabase::~SqliteDatabase()
|
|
|
|
{
|
|
|
|
Disconnect();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SqliteDatabase::Disconnect()
|
|
|
|
{
|
|
|
|
if (m_pSql)
|
|
|
|
{
|
|
|
|
sqlite3_close(m_pSql);
|
|
|
|
m_pSql = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SqliteDatabase::FreeHandle()
|
|
|
|
{
|
|
|
|
delete this;
|
|
|
|
}
|
|
|
|
|
|
|
|
ISQLDriver *SqliteDatabase::Driver()
|
|
|
|
{
|
|
|
|
return static_cast<ISQLDriver *>(m_pParent);
|
|
|
|
}
|
|
|
|
|
|
|
|
IQuery *SqliteDatabase::PrepareQuery(const char *query)
|
|
|
|
{
|
|
|
|
SqliteQuery *pQuery = new SqliteQuery(this, query);
|
|
|
|
return static_cast<IQuery *>(pQuery);
|
|
|
|
}
|
|
|
|
|
|
|
|
IQuery *SqliteDatabase::PrepareQueryFmt(const char *fmt, va_list ap)
|
|
|
|
{
|
|
|
|
char buffer[4096];
|
|
|
|
|
|
|
|
vsnprintf(buffer, sizeof(buffer)-1, fmt, ap);
|
|
|
|
|
|
|
|
return PrepareQuery(buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
IQuery *SqliteDatabase::PrepareQueryFmt(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
IQuery *qry;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
qry = PrepareQueryFmt(fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
return qry;
|
|
|
|
}
|
|
|
|
|
|
|
|
int SqliteDatabase::QuoteString(const char *str, char buffer[], size_t maxlen, size_t *newsize)
|
|
|
|
{
|
2007-04-25 17:55:56 +04:00
|
|
|
char *res = sqlite3_snprintf(static_cast<int>(maxlen), buffer, "%q", str);
|
2006-06-03 23:52:21 +04:00
|
|
|
|
2007-04-25 17:55:56 +04:00
|
|
|
if (res != NULL && newsize != NULL)
|
|
|
|
{
|
|
|
|
*newsize = strlen(buffer);
|
|
|
|
}
|
2006-06-03 23:52:21 +04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2009-01-08 23:02:09 +03:00
|
|
|
|
2014-04-19 00:31:14 +04:00
|
|
|
bool SqliteDatabase::SetCharacterSet(const char *characterset)
|
2014-04-19 00:04:32 +04:00
|
|
|
{
|
|
|
|
// sqlite only supports utf8 and utf16 - by the time the database is created. It's too late here.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|