/addons/sourcemod/scripting/include/dbi.inc
Pascal | 681 lines | 608 code | 41 blank | 32 comment | 30 complexity | 1399280ecb4bfeed954b507d4da78d17 MD5 | raw file
- /**
- * vim: set ts=4 :
- * =============================================================================
- * SourceMod (C)2004-2008 AlliedModders LLC. All rights reserved.
- * =============================================================================
- *
- * This file is part of the SourceMod/SourcePawn SDK.
- *
- * This program is free software; you can redistribute it and/or modify it under
- * the terms of the GNU General Public License, version 3.0, as published by the
- * Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
- * details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program. If not, see <http://www.gnu.org/licenses/>.
- *
- * As a special exception, AlliedModders LLC gives you permission to link the
- * code of this program (as well as its derivative works) to "Half-Life 2," the
- * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
- * by the Valve Corporation. You must obey the GNU General Public License in
- * all respects for all other code used. Additionally, AlliedModders LLC grants
- * this exception to all derivative works. AlliedModders LLC defines further
- * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
- * or <http://www.sourcemod.net/license.php>.
- *
- * Version: $Id$
- */
-
- #if defined _dbi_included
- #endinput
- #endif
- #define _dbi_included
-
- /**
- * @handle Driver
- *
- * Contains information about an SQL driver.
- */
-
- /**
- * @handle Database
- *
- * Contains information about a database connection.
- */
-
- /**
- * @handle Query
- *
- * Contains information about an active query and its
- * result sets.
- */
-
- /**
- * @handle Statement : Query
- *
- * Extends a Query Handle and can be used as a Query Handle.
- * Statement Handles are for prepared queries and contain
- * their own function for binding parameters. Statement
- * Handles can be used instead of database Handles in a few
- * select functions.
- */
-
- /**
- * Describes a database field fetch status.
- */
- enum DBResult
- {
- DBVal_Error = 0, /**< Column number/field is invalid. */
- DBVal_TypeMismatch = 1, /**< You cannot retrieve this data with this type. */
- DBVal_Null = 2, /**< Field has no data (NULL) */
- DBVal_Data = 3, /**< Field has data */
- };
-
- /**
- * Describes binding types.
- */
- enum DBBindType
- {
- DBBind_Int = 0, /**< Bind an integer. */
- DBBind_Float = 1, /**< Bind a float. */
- DBBind_String = 2, /**< Bind a string. */
- };
-
- /**
- * Threading priority level.
- */
- enum DBPriority
- {
- DBPrio_High = 0, /**< High priority. */
- DBPrio_Normal = 1, /**< Normal priority. */
- DBPrio_Low = 2, /**< Low priority. */
- };
-
- /**
- * Creates an SQL connection from a named configuration.
- *
- * @param confname Named configuration.
- * @param persistent True to re-use a previous persistent connection if
- * possible, false otherwise.
- * @param error Error buffer.
- * @param maxlength Maximum length of the error buffer.
- * @return A database connection Handle, or INVALID_HANDLE on failure.
- */
- native Handle:SQL_Connect(const String:confname[], bool:persistent, String:error[], maxlength);
-
- /**
- * Creates a default SQL connection.
- *
- * @param error Error buffer.
- * @param maxlength Maximum length of the error buffer.
- * @param persistent True to re-use a previous persistent connection
- * if possible, false otherwise.
- * @return A database connection Handle, or INVALID_HANDLE on failure.
- * On failure the error buffer will be filled with a message.
- */
- stock Handle:SQL_DefConnect(String:error[], maxlength, bool:persistent=true)
- {
- return SQL_Connect("default", persistent, error, maxlength);
- }
-
- /**
- * Connects to a database using key value pairs containing the database info.
- * The key/value pairs should match what would be in databases.cfg.
- *
- * I.e. "driver" should be "default" or a driver name (or ommitted for
- * the default). For SQLite, only the "database" parameter is needed in addition.
- * For drivers which require external connections, more of the parameters may be
- * needed.
- *
- * In general it is discouraged to use this function. Connections should go through
- * databases.cfg for greatest flexibility on behalf of users.
- *
- * @param keyvalues Key/value pairs from a KeyValues handle, describing the connection.
- * @param error Error buffer.
- * @param maxlength Maximum length of the error buffer.
- * @return A database connection Handle, or INVALID_HANDLE on failure.
- * On failure the error buffer will be filled with a message.
- * @error Invalid KeyValues handle.
- */
- native Handle:SQL_ConnectCustom(Handle:keyvalues,
- String:error[],
- maxlength,
- bool:persistent);
-
- /**
- * Grabs a handle to an SQLite database, creating one if it does not exist.
- *
- * Unless there are extenuating circumstances, you should consider using "sourcemod-local" as the
- * database name. This provides some unification between plugins on behalf of users.
- *
- * As a precaution, you should always create some sort of unique prefix to your table names so
- * there are no conflicts, and you should never drop or modify tables that you do not own.
- *
- * @param database Database name.
- * @param error Error buffer.
- * @param maxlength Maximum length of the error buffer.
- * @return A database connection Handle, or INVALID_HANDLE on failure.
- * On failure the error buffer will be filled with a message.
- */
- stock Handle:SQLite_UseDatabase(const String:database[],
- String:error[],
- maxlength)
- {
- new Handle:kv, Handle:db;
-
- kv = CreateKeyValues("");
- KvSetString(kv, "driver", "sqlite");
- KvSetString(kv, "database", database);
-
- db = SQL_ConnectCustom(kv, error, maxlength, false);
-
- CloseHandle(kv);
-
- return db;
- }
-
- /**
- * This function is deprecated. Use SQL_ConnectCustom or SQLite_UseDatabase instead.
- */
- #pragma deprecated Use SQL_ConnectCustom instead.
- native Handle:SQL_ConnectEx(Handle:driver,
- const String:host[],
- const String:user[],
- const String:pass[],
- const String:database[],
- String:error[],
- maxlength,
- bool:persistent=true,
- port=0,
- maxTimeout=0);
-
- /**
- * Returns if a named configuration is present in databases.cfg.
- *
- * @param name Configuration name.
- * @return True if it exists, false otherwise.
- */
- native bool:SQL_CheckConfig(const String:name[]);
-
- /**
- * Returns a driver Handle from a name string.
- *
- * If the driver is not found, SourceMod will attempt
- * to load an extension named dbi.<name>.ext.[dll|so].
- *
- * @param name Driver identification string, or an empty
- * string to return the default driver.
- * @return Driver Handle, or INVALID_HANDLE on failure.
- */
- native Handle:SQL_GetDriver(const String:name[]="");
-
- /**
- * Reads the driver of an opened database.
- *
- * @param database Database Handle.
- * @param ident Option buffer to store the identification string.
- * @param ident_length Maximum length of the buffer.
- * @return Driver Handle.
- */
- native Handle:SQL_ReadDriver(Handle:database, String:ident[]="", ident_length=0);
-
- /**
- * Retrieves a driver's identification string.
- *
- * Example: "mysql", "sqlite"
- *
- * @param driver Driver Handle, or INVALID_HANDLE for the default driver.
- * @param ident Identification string buffer.
- * @param maxlength Maximum length of the buffer.
- * @noreturn
- * @error Invalid Handle other than INVALID_HANDLE.
- */
- native SQL_GetDriverIdent(Handle:driver, String:ident[], maxlength);
-
- /**
- * Retrieves a driver's product string.
- *
- * Example: "MySQL", "SQLite"
- *
- * @param driver Driver Handle, or INVALID_HANDLE for the default driver.
- * @param product Product string buffer.
- * @param maxlength Maximum length of the buffer.
- * @noreturn