1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/extensions/sqlite/extension.cpp Sun Jul 29 01:15:31 2007 +0000
1.3 @@ -0,0 +1,64 @@
1.4 +/**
1.5 + * vim: set ts=4 :
1.6 + * ===============================================================
1.7 + * SourceMod SQLite Driver Extension
1.8 + * Copyright (C) 2004-2007 AlliedModders LLC. All rights reserved.
1.9 + * ===============================================================
1.10 + *
1.11 + * This program is free software; you can redistribute it and/or
1.12 + * modify it under the terms of the GNU General Public License
1.13 + * as published by the Free Software Foundation; either version 2
1.14 + * of the License, or (at your option) any later version.
1.15 + * This program is distributed in the hope that it will be useful,
1.16 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.17 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.18 + * GNU General Public License for more details.
1.19 + *
1.20 + * You should have received a copy of the GNU General Public License
1.21 + * along with this program; if not, write to the Free Software
1.22 + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
1.23 + *
1.24 + * Version: $Id$
1.25 + */
1.26 +
1.27 +#include "extension.h"
1.28 +#include "driver/SqDriver.h"
1.29 +
1.30 +/**
1.31 + * @file extension.cpp
1.32 + * @brief Implement extension code here.
1.33 + */
1.34 +
1.35 +SqliteExt g_SqliteExt; /**< Global singleton for extension's main interface */
1.36 +
1.37 +SMEXT_LINK(&g_SqliteExt);
1.38 +
1.39 +bool SqliteExt::SDK_OnLoad(char *error, size_t maxlength, bool late)
1.40 +{
1.41 + g_SqDriver.Initialize();
1.42 + dbi->AddDriver(&g_SqDriver);
1.43 +
1.44 + return true;
1.45 +}
1.46 +
1.47 +void SqliteExt::SDK_OnUnload()
1.48 +{
1.49 + dbi->RemoveDriver(&g_SqDriver);
1.50 + g_SqDriver.Shutdown();
1.51 +}
1.52 +
1.53 +size_t UTIL_Format(char *buffer, size_t maxlength, const char *fmt, ...)
1.54 +{
1.55 + va_list ap;
1.56 + va_start(ap, fmt);
1.57 + size_t len = vsnprintf(buffer, maxlength, fmt, ap);
1.58 + va_end(ap);
1.59 +
1.60 + if (len >= maxlength)
1.61 + {
1.62 + buffer[maxlength - 1] = '\0';
1.63 + return (maxlength - 1);
1.64 + } else {
1.65 + return len;
1.66 + }
1.67 +}