public/IDBDriver.h
author Scott Ehlert <ds@alliedmods.net>
Sun Jul 15 08:00:26 2007 +0000 (2007-07-15)
changeset 1116 40cc5e9f0f1b
parent 1095 a9d7047a8d4b
child 1158 c243c33d199a
permissions -rw-r--r--
Removed strange debugging code
     1 /**
     2  * vim: set ts=4 :
     3  * ===============================================================
     4  * SourceMod, Copyright (C) 2004-2007 AlliedModders LLC. 
     5  * All rights reserved.
     6  * ===============================================================
     7  *
     8  *  This file is part of the SourceMod/SourcePawn SDK.  This file may only be 
     9  * used or modified under the Terms and Conditions of its License Agreement, 
    10  * which is found in public/licenses/LICENSE.txt.  As of this notice, derivative 
    11  * works must be licensed under the GNU General Public License (version 2 or 
    12  * greater).  A copy of the GPL is included under public/licenses/GPL.txt.
    13  * 
    14  * To view the latest information, see: http://www.sourcemod.net/license.php
    15  *
    16  * Version: $Id$
    17  */
    18 
    19 #ifndef _INCLUDE_SOURCEMOD_INTERFACE_DBDRIVER_H_
    20 #define _INCLUDE_SOURCEMOD_INTERFACE_DBDRIVER_H_
    21 
    22 #include <IShareSys.h>
    23 #include <IHandleSys.h>
    24 #include <string.h>
    25 
    26 #define SMINTERFACE_DBI_NAME		"IDBI"
    27 #define SMINTERFACE_DBI_VERSION		4
    28 
    29 namespace SourceMod
    30 {
    31 	/**
    32 	 * @brief Describes a database field value.
    33 	 */
    34 	enum DBResult
    35 	{
    36 		DBVal_Error = 0,		/**< Column number/field is invalid */
    37 		DBVal_TypeMismatch = 1,	/**< You cannot retrieve this data with this type */
    38 		DBVal_Null = 2,			/**< Field has no data (NULL) */
    39 		DBVal_Data = 3,			/**< Field has data */
    40 	};
    41 
    42 	/**
    43 	 * @brief Describes a primitive database type.
    44 	 */
    45 	enum DBType
    46 	{
    47 		DBType_Unknown = 0,		/**< Type could not be inferred */
    48 		DBType_String,			/**< NULL-terminated string (variable length) */
    49 		DBType_Blob,			/**< Raw binary data (variable length) */
    50 		DBType_Integer,			/**< 4-byte signed integer */
    51 		DBType_Float,			/**< 4-byte floating point  */
    52 	};
    53 
    54 	/**
    55 	 * @brief Represents a one database result row.
    56 	 *
    57 	 * Note that type mismatches will only occur when type safety is being
    58 	 * enforced.  So far this is only the case for prepared statements in 
    59 	 * MySQL and SQLite.
    60 	 *
    61 	 * Also, it is worth noting that retrieving as raw data will never cause a
    62 	 * type mismatch.
    63 	 */
    64 	class IResultRow
    65 	{
    66 	public:
    67 		/**
    68 		 * @brief Retrieves a database field result as a string.
    69 		 *
    70 		 * For NULL values, the resulting string pointer will be non-NULL but 
    71 		 * empty.  The pointer returned will become invalid after  advancing to
    72 		 * the next row.
    73 		 *
    74 		 * @param columnId		Column to use, starting from 0.
    75 		 * @param pString		Pointer to store a pointer to the string.
    76 		 * @param length		Optional pointer to store the string length.
    77 		 * @return				A DBResult return code.
    78 		 */
    79 		virtual DBResult GetString(unsigned int columnId, const char **pString, size_t *length) =0;
    80 
    81 		/**
    82 		 * @brief Retrieves a database field result as a string, using a 
    83 		 * user-supplied buffer.  If the field is NULL, an empty string
    84 		 * will be copied.
    85 		 *
    86 		 * @param columnId		Column to use, starting from 0.
    87 		 * @param buffer		Buffer to store string in.
    88 		 * @param maxlength		Maximum length of the buffer.
    89 		 * @param written		Optional pointer to store the number of bytes 
    90 		 *						written, excluding the null terminator.
    91 		 * @return				A DBResult return code.
    92 		 */
    93 		virtual DBResult CopyString(unsigned int columnId, 
    94 									char *buffer, 
    95 									size_t maxlength, 
    96 									size_t *written) =0;
    97 		
    98 		/**
    99 		 * @brief Retrieves a database field result as a float.
   100 		 *
   101 		 * For NULL entries, the returned float value will be 0.0.
   102 		 *
   103 		 * @param columnId		Column to use, starting from 0.
   104 		 * @param pFloat		Pointer to a floating point number to set.
   105 		 * @return				A DBResult return code.
   106 		 */
   107 		virtual DBResult GetFloat(unsigned int columnId, float *pFloat) =0;
   108 
   109 		/**
   110 		 * @brief Retrieves a database field result as an integer.
   111 		 *
   112 		 * For NULL entries, the returned integer value will be 0.
   113 		 *
   114 		 * @param columnId		Column to use, starting from 0.
   115 		 * @param pInt			Pointer to an integer number to set.
   116 		 * @return				A DBResult return code.
   117 		 */
   118 		virtual DBResult GetInt(unsigned int columnId, int *pInt) =0;
   119 
   120 		/**
   121 		 * @brief Returns whether or not a field is NULL.
   122 		 *
   123 		 * @param columnId		Column to use, starting from 0.
   124 		 * @return				True if field is NULL, false otherwise.
   125 		 */
   126 		virtual bool IsNull(unsigned int columnId) =0;
   127 
   128 		/**
   129 		 * @brief Returns the size of a field (text/raw/blob) in bytes.
   130 		 * For strings, this returned size will not include the null
   131 		 * terminator.
   132 		 * 
   133 		 * When used on fields that are not of variable length,
   134 		 * the size returned will be the number of bytes required
   135 		 * to store the internal data.  Note that the data size 
   136 		 * will correspond to the ACTUAL data type, not the 
   137 		 * COLUMN type.
   138 		 *
   139 		 * @param columnId		Column to use, starting from 0.
   140 		 * @return				Number of bytes required to store
   141 		 *						the data, or 0 on failure.
   142 		 */
   143 		virtual size_t GetDataSize(unsigned int columnId) =0;
   144 
   145 		/**
   146 		 * @brief Retrieves field data as a raw bitstream.  The pointer returned
   147 		 * will become invalid after advancing to the next row.
   148 		 *
   149 		 * @param columnId		Column to use, starting from 0.
   150 		 * @param pData			Pointer to store the raw bit stream.  If the 
   151 		 *						data is NULL, a NULL pointer will be returned.
   152 		 * @param length		Pointer to store the data length.
   153 		 * @return				A DBResult return code.
   154 		 */
   155 		virtual DBResult GetBlob(unsigned int columnId, const void **pData, size_t *length) =0;
   156 
   157 		/**
   158 		 * @brief Copies field data as a raw bitstream.
   159 		 *
   160 		 * @param columnId		Column to use, starting from 0.
   161 		 * @param buffer		Pointer to copy the data to.  If the data is
   162 		 *						NULL, no data will be copied.
   163 		 * @param maxlength		Maximum length of the buffer.
   164 		 * @param written		Optional pointer to store the number of bytes 
   165 		 *						written.
   166 		 * @return				A DBResult return code.
   167 		 */
   168 		virtual DBResult CopyBlob(unsigned int columnId, void *buffer, size_t maxlength, size_t *written) =0;
   169 	};
   170 
   171 	/**
   172 	 * @brief Describes a set of database results.
   173 	 */
   174 	class IResultSet
   175 	{
   176 	public:
   177 		/**
   178 		 * @brief Returns the number of rows in the set.
   179 		 *
   180 		 * @return				Number of rows in the set.
   181 		 */
   182 		virtual unsigned int GetRowCount() =0;
   183 
   184 		/**
   185 		 * @brief Returns the number of fields in the set.
   186 		 *
   187 		 * @return				Number of fields in the set.
   188 		 */
   189 		virtual unsigned int GetFieldCount() =0;
   190 
   191 		/**
   192 		 * @brief Converts a column number to a column name.
   193 		 *
   194 		 * @param columnId		Column to use, starting from 0.
   195 		 * @return				Pointer to column name, or NULL if not found.
   196 		 */
   197 		virtual const char *FieldNumToName(unsigned int columnId) =0;
   198 
   199 		/**
   200 		 * @brief Converts a column name to a column id.
   201 		 *
   202 		 * @param name			Column name (case sensitive).
   203 		 * @param columnId		Pointer to store the column id.  If the
   204 		 *						name is not found, the value will be
   205 		 *						undefined.
   206 		 * @return				True on success, false if not found.
   207 		 */
   208 		virtual bool FieldNameToNum(const char *name, unsigned int *columnId) =0;
   209 
   210 		/**
   211 		 * @brief Returns if there is still data in the result set.
   212 		 *
   213 		 * @return				False if there is more data to be read, 
   214 		 *						true, otherwise.
   215 		 */
   216 		virtual bool MoreRows() =0;
   217 
   218 		/**
   219 		 * @brief Returns a pointer to the current row and advances
   220 		 * the internal row pointer/counter to the next row available.
   221 		 *
   222 		 * @return				IResultRow pointer to the current row,
   223 		 *						or NULL if there is no more data.
   224 		 */
   225 		virtual IResultRow *FetchRow() =0;
   226 
   227 		/**
   228 		 * @brief Returns a pointer to the current row.
   229 		 *
   230 		 * @return				IResultRow pointer to the current row,
   231 		 *						or NULL if the current row is invalid.
   232 		 */
   233 		virtual IResultRow *CurrentRow() =0;
   234 
   235 		/**
   236 		 * @brief Rewinds back to the beginning of the row iteration.
   237 		 * 
   238 		 * @return				True on success, false otherwise.
   239 		 */
   240 		virtual bool Rewind() =0;
   241 
   242 		/**
   243 		 * @brief Returns a field's type as it should be interpreted
   244 		 * by the user.
   245 		 *
   246 		 * @param field			Field number (starting from 0).
   247 		 * @return				A DBType value.
   248 		 */
   249 		virtual DBType GetFieldType(unsigned int field) =0;
   250 
   251 		/**
   252 		 * @brief Returns a field's type as it will be interpreted
   253 		 * by the GetDataSize() function.  For example, MySQL
   254 		 * for non-prepared queries will store all results as
   255 		 * strings internally.
   256 		 *
   257 		 * @param field			Field number (starting from 0).
   258 		 * @return				A DBType value.
   259 		 */
   260 		virtual DBType GetFieldDataType(unsigned int field) =0;
   261 	};
   262 
   263 	class IDBDriver;
   264 
   265 	class IQuery
   266 	{
   267 	public:
   268 		/**
   269 		 * @brief Returns a pointer to the current result set, if any.  
   270 		 *
   271 		 * @return				An IResultSet pointer on success,
   272 		 *						NULL if no result set exists.
   273 		 */
   274 		virtual IResultSet *GetResultSet() =0;
   275 
   276 		/**
   277 		 * @brief Advances to the next result set if one exists.  This
   278 		 * is for checking for MORE result sets, and should not be used
   279 		 * on the first result set.
   280 		 *
   281 		 * Multiple results only happen in certain cases, such as CALLing
   282 		 * stored procedure that have a SELECTs, where MySQL will return 
   283 		 * both the CALL status and one or more SELECT result sets.  If
   284 		 * you do not process these results, they will be automatically
   285 		 * processed for you.  However, the behaviour of creating a new
   286 		 * query from the same connection while results are left 
   287 		 * unprocessed is undefined, and may result in a dropped 
   288 		 * connection.  Therefore, process all extra results or destroy the
   289 		 * IQuery pointer before starting a new query.
   290 		 *
   291 		 * Again, this only happens in very specific cases, so there is
   292 		 * no need to call this for normal queries.
   293 		 *
   294 		 * After calling this function, GetResultSet() must be called
   295 		 * again to return the result set.  The previous result set
   296 		 * is automatically destroyed and will be unusable.
   297 		 *
   298 		 * @return				True if another result set is
   299 		 *						available, false otherwise.
   300 		 */
   301 		virtual bool FetchMoreResults() =0;
   302 
   303 		/**
   304 		 * @brief Frees resources created by this query.
   305 		 */
   306 		virtual void Destroy() =0;
   307 	};
   308 
   309 	class IPreparedQuery : public IQuery
   310 	{
   311 	public:
   312 		/** 
   313 		 * @brief Binds an integer parameter.
   314 		 *
   315 		 * @param param			Parameter index, starting from 0.
   316 		 * @param num			Number to bind as a value.
   317 		 * @param signd			True to write as signed, false to write as 
   318 		 *						unsigned.
   319 		 * @return				True on success, false otherwise.
   320 		 */
   321 		virtual bool BindParamInt(unsigned int param, int num, bool signd=true) =0;
   322 
   323 		/**
   324 		 * @brief Binds a float parameter.
   325 		 *
   326 		 * @param param			Parameter index, starting from 0.
   327 		 * @param f				Float to bind as a value.
   328 		 * @return				True on success, false otherwise.
   329 		 */
   330 		virtual bool BindParamFloat(unsigned int param, float f) =0;
   331 
   332 		/**
   333 		 * @brief Binds an SQL NULL type as a parameter.
   334 		 *
   335 		 * @param param			Parameter index, starting from 0.
   336 		 * @return				True on success, false otherwise.
   337 		 */
   338 		virtual bool BindParamNull(unsigned int param) =0;
   339 
   340 		/**
   341 		 * @brief Binds a string as a parameter.
   342 		 *
   343 		 * @param param			Parameter index, starting from 0.
   344 		 * @param text			Pointer to a null-terminated string.
   345 		 * @param copy			If true, the pointer is assumed to be
   346 		 *						volatile and a temporary copy may be
   347 		 *						made for safety.
   348 		 * @return				True on success, false otherwise.
   349 		 */
   350 		virtual bool BindParamString(unsigned int param, const char *text, bool copy) =0;
   351 
   352 		/**
   353 		 * @brief Binds a blob of raw data as a parameter.
   354 		 *
   355 		 * @param param			Parameter index, starting from 0.
   356 		 * @param data			Pointer to a blob of memory.
   357 		 * @param length		Number of bytes to copy.
   358 		 * @param copy			If true, the pointer is assumed to be
   359 		 *						volatile and a temporary copy may be
   360 		 *						made for safety.
   361 		 * @return				True on success, false otherwise.
   362 		 */
   363 		virtual bool BindParamBlob(unsigned int param, 
   364 									const void *data, 
   365 									size_t length, 
   366 									bool copy) =0;
   367 
   368 		/**
   369 		 * @brief Executes the query with the currently bound parameters.
   370 
   371 		 * @return				True on success, false otherwise.
   372 		 */
   373 		virtual bool Execute() =0;
   374 
   375 		/**
   376 		 * @brief Returns the last error message from this statement.
   377 		 *
   378 		 * @param errCode		Optional pointer to store the driver-specific
   379 		 *						error code.
   380 		 * @return				Error message string.
   381 		 */
   382 		virtual const char *GetError(int *errCode=NULL) =0;
   383 
   384 		/**
   385 		 * @brief Number of rows affected by the last execute.
   386 		 *
   387 		 * @return				Number of rows affected by the last execute.
   388 		 */
   389 		virtual unsigned int GetAffectedRows() =0;
   390 
   391 		/**
   392 		 * @brief Retrieves the last insert ID on this database connection.
   393 		 *
   394 		 * @return				Row insertion ID of the last execute, if any.
   395 		 */
   396 		virtual unsigned int GetInsertID() =0;
   397 	};
   398 
   399 	class IDBDriver;
   400 
   401 	/**
   402 	 * @brief Encapsulates a database connection.
   403 	 */
   404 	class IDatabase
   405 	{
   406 	public:
   407 		/**
   408 		 * @brief Disconnects the database and frees its associated memory.
   409 		 * Note that the actual object will not be freed until all open 
   410 		 * references have been closed.
   411 		 *
   412 		 * It is guaranteed that an IDatabase pointer won't be destroyed until
   413 		 * all open IQuery or IPreparedQuery pointers are closed.
   414 		 * 
   415 		 * @return				True if object was destroyed, false if 
   416 		 *						references are remaining.
   417 		 */
   418 		virtual bool Close() =0;
   419 
   420 		/**
   421 		 * @brief Error code and string returned by the last operation on this
   422 		 * connection.
   423 		 *
   424 		 * @param errorCode		Optional pointer to retrieve an error code.
   425 		 * @return				Error string pointer (empty if none).
   426 		 */
   427 		virtual const char *GetError(int *errorCode=NULL) =0;
   428 
   429 		/**
   430 		 * @brief Prepares and executes a query in one step, and discards
   431 		 * any return data.
   432 		 *
   433 		 * @param query			Query string.
   434 		 * @return				True on success, false otherwise.
   435 		 */
   436 		virtual bool DoSimpleQuery(const char *query) =0;
   437 
   438 		/**
   439 		 * @brief Prepares and executes a query in one step, and returns
   440 		 * the resultant data set.
   441 		 *
   442 		 * Note: If a query contains more than one result set, each
   443 		 * result set must be processed before a new query is started.
   444 		 *
   445 		 * @param query			Query string.
   446 		 * @return				IQuery pointer on success, NULL otherwise.
   447 		 */
   448 		virtual IQuery *DoQuery(const char *query) =0;
   449 
   450 		/** 
   451 		 * @brief Prepares a query statement for multiple executions and/or
   452 		 * binding marked parameters (? in MySQL/sqLite, $n in PostgreSQL).
   453 		 *
   454 		 * @param query			Query string.
   455 		 * @param error			Error buffer.
   456 		 * @param maxlength		Maximum length of the error buffer.
   457 		 * @param errCode		Optional pointer to store a driver-specific error code.
   458 		 * @return				IPreparedQuery pointer on success, NULL
   459 		 *						otherwise.
   460 		 */
   461 		virtual IPreparedQuery *PrepareQuery(const char *query, char *error, size_t maxlength, int *errCode=NULL) =0;
   462 
   463 		/**
   464 		 * Quotes a string for insertion into a query.
   465 		 *
   466 		 * @param str			Source string.
   467 		 * @param buffer		Buffer to store new string (should not overlap source string).
   468 		 * @param maxlen		Maximum length of the output buffer.
   469 		 * @param newSize		Pointer to store the output size.
   470 		 * @return				True on success, false if the output buffer is not big enough.
   471 		 *						If not big enough, the required buffer size is passed through
   472 		 *						newSize.
   473 		 */
   474 		virtual bool QuoteString(const char *str, char buffer[], size_t maxlen, size_t *newSize) =0;
   475 
   476 		/**
   477 		 * @brief Number of rows affected by the last execute.
   478 		 *
   479 		 * @return				Number of rows affected by the last execute.
   480 		 */
   481 		virtual unsigned int GetAffectedRows() =0;
   482 
   483 		/**
   484 		 * @brief Retrieves the last insert ID on this database connection.
   485 		 *
   486 		 * @return				Row insertion ID of the last execute, if any.
   487 		 */
   488 		virtual unsigned int GetInsertID() =0;
   489 
   490 		/**
   491 		 * @brief Locks the database for an atomic query+retrieval operation.
   492 		 *
   493 		 * @return				True on success, false if not supported.
   494 		 */
   495 		virtual bool LockForFullAtomicOperation() =0;
   496 
   497 		/**
   498 		 * @brief Unlocks a locked atomic fetch.
   499 		 */
   500 		virtual void UnlockFromFullAtomicOperation() =0;
   501 
   502 		/**
   503 		 * @brief Increases the reference count on the database.
   504 		 */
   505 		virtual void IncReferenceCount() =0;
   506 
   507 		/**
   508 		 * @brief Returns the parent driver.
   509 		 */
   510 		virtual IDBDriver *GetDriver() =0;
   511 	};
   512 
   513 	/** 
   514 	 * @brief Describes database connection info.
   515 	 */
   516 	struct DatabaseInfo
   517 	{
   518 		DatabaseInfo()
   519 		{
   520 			dbiVersion = SMINTERFACE_DBI_VERSION;
   521 			port = 0;
   522 			maxTimeout = 0;
   523 		}
   524 		unsigned int dbiVersion;		/**< DBI Version for backwards compatibility */
   525 		const char *host;				/**< Host string */
   526 		const char *database;			/**< Database name string */
   527 		const char *user;				/**< User to authenticate as */
   528 		const char *pass;				/**< Password to authenticate with */
   529 		const char *driver;				/**< Driver to use */
   530 		unsigned int port;				/**< Port to use, 0=default */
   531 		unsigned int maxTimeout;		/**< Maximum timeout, 0=default */
   532 	};
   533 
   534 	/**
   535 	 * @brief Describes an SQL driver.
   536 	 */
   537 	class IDBDriver
   538 	{
   539 	public:
   540 		virtual unsigned int GetDBIVersion()
   541 		{
   542 			return SMINTERFACE_DBI_VERSION;
   543 		}
   544 	public:
   545 		/**
   546 		 * @brief Initiates a database connection.
   547 		 * 
   548 		 * @param info			Database connection info pointer.
   549 		 * @param persistent	If true, a previous persistent connection will
   550 		 *						be re-used if possible.
   551 		 * @param error			Buffer to store error message.
   552 		 * @param maxlength		Maximum size of the error buffer.
   553 		 * @return				A new IDatabase pointer, or NULL on failure.
   554 		 */
   555 		virtual IDatabase *Connect(const DatabaseInfo *info, bool persistent, char *error, size_t maxlength) =0;
   556 
   557 		/**
   558 		 * @brief Returns a case insensitive database identifier string.
   559 		 *
   560 		 * @return				String containing an identifier.
   561 		 */
   562 		virtual const char *GetIdentifier() =0;
   563 
   564 		/**
   565 		 * @brief Returns a case sensitive implementation name.
   566 		 *
   567 		 * @return				String containing an implementation name.
   568 		 */
   569 		virtual const char *GetProductName() =0;
   570 
   571 		/**
   572 		 * @brief Retrieves a Handle_t handle of the IDBDriver type.
   573 		 *
   574 		 * @return				A Handle_t handle.
   575 		 */
   576 		virtual Handle_t GetHandle() =0;
   577 
   578 		/**
   579 		 * @brief Returns the driver's controlling identity (must be the same 
   580 		 * as from IExtension::GetIdentity).
   581 		 *
   582 		 * @return				An IdentityToken_t identity.
   583 		 */
   584 		virtual IdentityToken_t *GetIdentity() =0;
   585 
   586 		/**
   587 		 * @brief Returns whether the driver is thread safe.
   588 		 *
   589 		 * @return				True if thread safe, false otherwise.
   590 		 */
   591 		virtual bool IsThreadSafe() =0;
   592 
   593 		/**
   594 		 * @brief Initializes thread safety for the calling thread.
   595 		 *
   596 		 * @return				True on success, false otherwise.
   597 		 */
   598 		virtual bool InitializeThreadSafety() =0;
   599 
   600 		/**
   601 		 * @brief Shuts down thread safety for the calling thread.
   602 		 */
   603 		virtual void ShutdownThreadSafety() =0;
   604 	};
   605 
   606 	/**
   607 	 * @brief Database-related Handle types.
   608 	 */
   609 	enum DBHandleType
   610 	{
   611 		DBHandle_Driver = 0,		/**< Driver Handle */
   612 		DBHandle_Database = 1,		/**< Database Handle */
   613 	};
   614 
   615 	/**
   616 	 * @brief Describes the DBI manager.
   617 	 */
   618 	class IDBManager : public SMInterface
   619 	{
   620 	public:
   621 		virtual const char *GetInterfaceName() =0;
   622 		virtual unsigned int GetInterfaceVersion() =0;
   623 	public:
   624 		/**
   625 		 * @brief Adds a driver to the DBI system.  Not thread safe.
   626 		 *
   627 		 * @param pDriver		Database driver.
   628 		 */
   629 		virtual void AddDriver(IDBDriver *pDriver) =0;
   630 
   631 		/**
   632 		 * @brief Removes a driver from the DBI system.  Not thread safe.
   633 		 *
   634 		 * @param pDriver		Database driver.
   635 		 */
   636 		virtual void RemoveDriver(IDBDriver *pDriver) =0;
   637 
   638 		/**
   639 		 * @brief Searches for database info by name.  Both the return pointer
   640 		 * and all pointers contained therein should be considered volatile.
   641 		 *
   642 		 * @param name			Named database info.
   643 		 * @return				DatabaseInfo pointer.
   644 		 */
   645 		virtual const DatabaseInfo *FindDatabaseConf(const char *name) =0;
   646 
   647 		/**
   648 		 * @brief Tries to connect to a named database.  Not thread safe.
   649 		 *
   650 		 * @param name			Named database info.
   651 		 * @param pdr			Pointer to store the IDBDriver pointer in.
   652 		 *						If driver is not found, NULL will be stored.
   653 		 * @param pdb			Pointer to store the IDatabase pointer in.
   654 		 *						If connection fails, NULL will be stored.
   655 		 * @param persistent	If true, the dbmanager will attempt to PConnect
   656 		 *						instead of connect.
   657 		 * @param error			Error buffer to store a driver's error message.
   658 		 * @param maxlength		Maximum length of the error buffer.
   659 		 * @return				True on success, false otherwise.
   660 		 */
   661 		virtual bool Connect(const char *name, 
   662 							IDBDriver **pdr, 
   663 							IDatabase **pdb, 
   664 							bool persistent, 
   665 							char *error, 
   666 							size_t maxlength) =0;
   667 
   668 		/**
   669 		 * @brief Returns the number of drivers loaded.  Not thread safe.
   670 		 *
   671 		 * @return				Number of drivers loaded.
   672 		 */
   673 		virtual unsigned int GetDriverCount() =0;
   674 
   675 		/**
   676 		 * @brief Returns a driver by index.  Not thread safe.
   677 		 *
   678 		 * @param index			Driver index, starting from 0.
   679 		 * @return				IDBDriver pointer for the given index.
   680 		 */
   681 		virtual IDBDriver *GetDriver(unsigned int index) =0;
   682 
   683 		/**
   684 		 * @brief Creates a Handle_t of the IDBDriver type.  Not thread safe.
   685 		 *
   686 		 * @param type			A DBHandleType value.
   687 		 * @param ptr			A pointer corrresponding to a DBHandleType 
   688 		 *						object.
   689 		 * @param token			Identity pointer of the owning identity.
   690 		 * @return				A new Handle_t handle, or 0 on failure.
   691 		 */
   692 		virtual Handle_t CreateHandle(DBHandleType type, void *ptr, IdentityToken_t *pToken) =0;
   693 
   694 		/**
   695 		 * @brief Reads an IDBDriver pointer from an IDBDriver handle.  Not 
   696 		 * thread safe.
   697 		 *
   698 		 * @param hndl			Handle_t handle to read.
   699 		 * @param type			A DBHandleType value.
   700 		 * @param ptr			Pointer to store the object pointer.
   701 		 * @return				HandleError value.
   702 		 */
   703 		virtual HandleError ReadHandle(Handle_t hndl, DBHandleType type, void **ptr) =0;
   704 
   705 		/**
   706 		 * @brief Releases an IDBDriver handle.
   707 		 *
   708 		 * @param hndl			Handle_t handle to release.
   709 		 * @param type			A DBHandleType value.
   710 		 * @param token			Identity pointer of the owning identity.
   711 		 * @return				HandleError value.
   712 		 */
   713 		virtual HandleError ReleaseHandle(Handle_t hndl, DBHandleType type, IdentityToken_t *token) =0;
   714 
   715 		/**
   716 		 * @brief Given a driver name, attempts to find it.  If it is not found, SourceMod
   717 		 * will attempt to load it.  This function is not thread safe.
   718 		 *
   719 		 * @param name			Driver identifier name.
   720 		 * @return				IDBDriver pointer on success, NULL otherwise.
   721 		 */
   722 		virtual IDBDriver *FindOrLoadDriver(const char *driver) =0;
   723 
   724 		/**
   725 		 * @brief Returns the default driver, or NULL if none is set.  This 
   726 		 * function is not thread safe.
   727 		 *
   728 		 * @return				IDBDriver pointer on success, NULL otherwise.
   729 		 */
   730 		virtual IDBDriver *GetDefaultDriver() =0;
   731 	};
   732 }
   733 
   734 #endif //_INCLUDE_SOURCEMOD_INTERFACE_DBDRIVER_H_