plugins/include/dbi.inc
author David Anderson <dvander@alliedmods.net>
Sun Aug 11 11:30:27 2013 -0700 (2013-08-11)
changeset 3984 d94a0d3bc008
parent 3967 ceafb87d38a7
permissions -rw-r--r--
Clean up INFO register structure (bug 5844 part 1, r=ds).
     1 /**
     2  * vim: set ts=4 :
     3  * =============================================================================
     4  * SourceMod (C)2004-2008 AlliedModders LLC.  All rights reserved.
     5  * =============================================================================
     6  *
     7  * This file is part of the SourceMod/SourcePawn SDK.
     8  *
     9  * This program is free software; you can redistribute it and/or modify it under
    10  * the terms of the GNU General Public License, version 3.0, as published by the
    11  * Free Software Foundation.
    12  * 
    13  * This program is distributed in the hope that it will be useful, but WITHOUT
    14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    15  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
    16  * details.
    17  *
    18  * You should have received a copy of the GNU General Public License along with
    19  * this program.  If not, see <http://www.gnu.org/licenses/>.
    20  *
    21  * As a special exception, AlliedModders LLC gives you permission to link the
    22  * code of this program (as well as its derivative works) to "Half-Life 2," the
    23  * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
    24  * by the Valve Corporation.  You must obey the GNU General Public License in
    25  * all respects for all other code used.  Additionally, AlliedModders LLC grants
    26  * this exception to all derivative works.  AlliedModders LLC defines further
    27  * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
    28  * or <http://www.sourcemod.net/license.php>.
    29  *
    30  * Version: $Id$
    31  */
    32  
    33 #if defined _dbi_included
    34  #endinput
    35 #endif
    36 #define _dbi_included
    37 
    38 /**
    39  * @handle Driver
    40  *
    41  * Contains information about an SQL driver.
    42  */
    43  
    44 /**
    45  * @handle Database
    46  *
    47  * Contains information about a database connection.
    48  */
    49  
    50 /**
    51  * @handle Query
    52  *
    53  * Contains information about an active query and its 
    54  * result sets.
    55  */
    56  
    57 /**
    58  * @handle Statement : Query
    59  *
    60  * Extends a Query Handle and can be used as a Query Handle.
    61  * Statement Handles are for prepared queries and contain
    62  * their own function for binding parameters.  Statement
    63  * Handles can be used instead of database Handles in a few
    64  * select functions.
    65  */
    66 
    67 /**
    68  * Describes a database field fetch status.
    69  */
    70 enum DBResult
    71 {
    72 	DBVal_Error = 0,		/**< Column number/field is invalid. */
    73 	DBVal_TypeMismatch = 1,	/**< You cannot retrieve this data with this type. */
    74 	DBVal_Null = 2,			/**< Field has no data (NULL) */
    75 	DBVal_Data = 3,			/**< Field has data */
    76 };
    77 
    78 /**
    79  * Describes binding types.
    80  */
    81 enum DBBindType
    82 {
    83 	DBBind_Int = 0,			/**< Bind an integer. */
    84 	DBBind_Float = 1,		/**< Bind a float. */
    85 	DBBind_String = 2,		/**< Bind a string. */
    86 };
    87 
    88 /**
    89  * Threading priority level.
    90  */
    91 enum DBPriority
    92 {
    93 	DBPrio_High = 0,		/**< High priority. */
    94 	DBPrio_Normal = 1,		/**< Normal priority. */
    95 	DBPrio_Low = 2,			/**< Low priority. */
    96 };
    97 
    98 /**
    99  * Creates an SQL connection from a named configuration.
   100  *
   101  * @param confname		Named configuration.
   102  * @param persistent	True to re-use a previous persistent connection if
   103  *						possible, false otherwise.
   104  * @param error			Error buffer.
   105  * @param maxlength		Maximum length of the error buffer.
   106  * @return				A database connection Handle, or INVALID_HANDLE on failure.
   107  */
   108 native Handle:SQL_Connect(const String:confname[], bool:persistent, String:error[], maxlength);
   109 
   110 /**
   111  * Creates a default SQL connection.
   112  *
   113  * @param error			Error buffer.
   114  * @param maxlength		Maximum length of the error buffer.
   115  * @param persistent	True to re-use a previous persistent connection
   116  *						if possible, false otherwise.
   117  * @return				A database connection Handle, or INVALID_HANDLE on failure.
   118  * 						On failure the error buffer will be filled with a message.
   119  */
   120 stock Handle:SQL_DefConnect(String:error[], maxlength, bool:persistent=true)
   121 {
   122 	return SQL_Connect("default", persistent, error, maxlength);
   123 }
   124 
   125 /**
   126  * Connects to a database using key value pairs containing the database info.
   127  * The key/value pairs should match what would be in databases.cfg.
   128  *
   129  * I.e. "driver" should be "default" or a driver name (or ommitted for 
   130  * the default).  For SQLite, only the "database" parameter is needed in addition.
   131  * For drivers which require external connections, more of the parameters may be 
   132  * needed.
   133  *
   134  * In general it is discouraged to use this function.  Connections should go through 
   135  * databases.cfg for greatest flexibility on behalf of users.
   136  *
   137  * @param keyvalues		Key/value pairs from a KeyValues handle, describing the connection.
   138  * @param error			Error buffer.
   139  * @param maxlength		Maximum length of the error buffer.
   140  * @param persistent	True to re-use a previous persistent connection if
   141  *						possible, false otherwise.
   142  * @return				A database connection Handle, or INVALID_HANDLE on failure.
   143  * 						On failure the error buffer will be filled with a message.
   144  * @error				Invalid KeyValues handle.
   145  */
   146 native Handle:SQL_ConnectCustom(Handle:keyvalues,
   147 								String:error[],
   148 								maxlength,
   149 								bool:persistent);
   150 
   151 /**
   152  * Grabs a handle to an SQLite database, creating one if it does not exist.  
   153  *
   154  * Unless there are extenuating circumstances, you should consider using "sourcemod-local" as the 
   155  * database name.  This provides some unification between plugins on behalf of users.
   156  *
   157  * As a precaution, you should always create some sort of unique prefix to your table names so 
   158  * there are no conflicts, and you should never drop or modify tables that you do not own.
   159  *
   160  * @param database		Database name.  
   161  * @param error			Error buffer.
   162  * @param maxlength		Maximum length of the error buffer.
   163  * @return				A database connection Handle, or INVALID_HANDLE on failure.
   164  * 						On failure the error buffer will be filled with a message.
   165  */
   166 stock Handle:SQLite_UseDatabase(const String:database[],
   167 								String:error[], 
   168 								maxlength)
   169 {
   170 	new Handle:kv, Handle:db;
   171 
   172 	kv = CreateKeyValues("");
   173 	KvSetString(kv, "driver", "sqlite");
   174 	KvSetString(kv, "database", database);
   175 
   176 	db = SQL_ConnectCustom(kv, error, maxlength, false);
   177 
   178 	CloseHandle(kv);
   179 
   180 	return db;
   181 }
   182 
   183 /**
   184  * This function is deprecated.  Use SQL_ConnectCustom or SQLite_UseDatabase instead.
   185  */
   186 #pragma deprecated Use SQL_ConnectCustom instead.
   187 native Handle:SQL_ConnectEx(Handle:driver, 
   188 							const String:host[],
   189 							const String:user[], 
   190 							const String:pass[],
   191 							const String:database[],
   192 							String:error[],
   193 							maxlength,
   194 							bool:persistent=true,
   195 							port=0,
   196 							maxTimeout=0);
   197 							
   198 /**
   199  * Returns if a named configuration is present in databases.cfg.
   200  *
   201  * @param name			Configuration name.
   202  * @return				True if it exists, false otherwise.
   203  */
   204 native bool:SQL_CheckConfig(const String:name[]);
   205 
   206 /**
   207  * Returns a driver Handle from a name string.
   208  *
   209  * If the driver is not found, SourceMod will attempt
   210  * to load an extension named dbi.<name>.ext.[dll|so].
   211  *
   212  * @param name			Driver identification string, or an empty
   213  *						string to return the default driver.
   214  * @return				Driver Handle, or INVALID_HANDLE on failure.
   215  */
   216 native Handle:SQL_GetDriver(const String:name[]="");
   217 
   218 /**
   219  * Reads the driver of an opened database.
   220  *
   221  * @param database		Database Handle.
   222  * @param ident			Option buffer to store the identification string.
   223  * @param ident_length	Maximum length of the buffer.
   224  * @return				Driver Handle.
   225  */
   226 native Handle:SQL_ReadDriver(Handle:database, String:ident[]="", ident_length=0);
   227 
   228 /**
   229  * Retrieves a driver's identification string.
   230  *
   231  * Example: "mysql", "sqlite"
   232  *
   233  * @param driver		Driver Handle, or INVALID_HANDLE for the default driver.
   234  * @param ident			Identification string buffer.
   235  * @param maxlength		Maximum length of the buffer.
   236  * @noreturn
   237  * @error				Invalid Handle other than INVALID_HANDLE.
   238  */
   239 native SQL_GetDriverIdent(Handle:driver, String:ident[], maxlength);
   240 
   241 /**
   242  * Retrieves a driver's product string.
   243  *
   244  * Example: "MySQL", "SQLite"
   245  *
   246  * @param driver		Driver Handle, or INVALID_HANDLE for the default driver.
   247  * @param product		Product string buffer.
   248  * @param maxlength		Maximum length of the buffer.
   249  * @noreturn
   250  * @error				Invalid Handle other than INVALID_HANDLE.
   251  */
   252 native SQL_GetDriverProduct(Handle:driver, String:product[], maxlength);
   253 
   254 /**
   255  * Sets the character set of the current connection. 
   256  * Like SET NAMES .. in mysql, but stays after connection problems.
   257  * 
   258  * Example: "utf8", "latin1"
   259  *
   260  * @param database      Database Handle.
   261  * @param characterset  The character set string to change to.
   262  * @return              True, if character set was changed, false otherwise.
   263  */
   264 native bool:SQL_SetCharset(Handle:database, const String:charset[]);
   265 
   266 /**
   267  * Returns the number of affected rows from the last query.
   268  *
   269  * @param hndl			A database OR statement Handle.
   270  * @return				Number of rows affected by the last query.
   271  * @error				Invalid database or statement Handle.
   272  */
   273 native SQL_GetAffectedRows(Handle:hndl);
   274 
   275 /**
   276  * Returns the last query's insertion id.
   277  *
   278  * @param hndl			A database, query, OR statement Handle.
   279  * @return				Last query's insertion id.
   280  * @error				Invalid database, query, or statement Handle.
   281  */
   282 native SQL_GetInsertId(Handle:hndl);
   283 
   284 /**
   285  * Returns the error reported by the last query.
   286  *
   287  * @param hndl			A database, query, OR statement Handle.
   288  * @param error			Error buffer.
   289  * @param maxlength		Maximum length of the buffer.
   290  * @return				True if there was an error, false otherwise.
   291  * @error				Invalid database, query, or statement Handle.
   292  */
   293 native bool:SQL_GetError(Handle:hndl, String:error[], maxlength);
   294 
   295 /**
   296  * Escapes a database string for literal insertion.  This is not needed
   297  * for binding strings in prepared statements.  
   298  *
   299  * Generally, database strings are inserted into queries enclosed in 
   300  * single quotes (').  If user input has a single quote in it, the 
   301  * quote needs to be escaped.  This function ensures that any unsafe 
   302  * characters are safely escaped according to the database engine and 
   303  * the database's character set.
   304  *
   305  * NOTE: SourceMod only guarantees properly escaped strings when the query
   306  * encloses the string in ''. While drivers tend to allow " instead, the string
   307  * may be not be escaped (for example, on SQLite)!
   308  *
   309  * @param database			A database Handle.
   310  * @param string		String to quote.
   311  * @param buffer		Buffer to store quoted string in.
   312  * @param maxlength		Maximum length of the buffer.
   313  * @param written		Optionally returns the number of bytes written.
   314  * @return				True on success, false if buffer is not big enough.
   315  *						The buffer must be at least 2*strlen(string)+1.
   316  * @error				Invalid database or statement Handle.
   317  */
   318 native bool:SQL_EscapeString(Handle:database, 
   319 							 const String:string[], 
   320 							 String:buffer[], 
   321 							 maxlength, 
   322 							 &written=0);
   323 
   324 /**
   325  * This is a backwards compatibility stock.  You should use SQL_EscapeString() 
   326  * instead, as this function will probably be deprecated in SourceMod 1.1.
   327  */
   328 stock bool:SQL_QuoteString(Handle:database,
   329 						   const String:string[],
   330 						   String:buffer[],
   331 						   maxlength,
   332 						   &written=0)
   333 {
   334 	return SQL_EscapeString(database, string, buffer, maxlength, written);
   335 }
   336 
   337 /**
   338  * Executes a query and ignores the result set.
   339  *
   340  * @param database		A database Handle.
   341  * @param query			Query string.
   342  * @param len			Optional parameter to specify the query length, in 
   343  *						bytes.  This can be used to send binary queries that 
   344  * 						have a premature terminator.
   345  * @return				True if query succeeded, false otherwise.  Use
   346  *						SQL_GetError to find the last error.
   347  * @error				Invalid database Handle.
   348  */
   349 native bool:SQL_FastQuery(Handle:database, const String:query[], len=-1);
   350 
   351 /**
   352  * Executes a simple query and returns a new query Handle for
   353  * receiving the results.
   354  *
   355  * @param database		A database Handle.
   356  * @param query			Query string.
   357  * @param len			Optional parameter to specify the query length, in 
   358  *						bytes.  This can be used to send binary queries that 
   359  * 						have a premature terminator.
   360  * @return				A new Query Handle on success, INVALID_HANDLE
   361  *						otherwise.  The Handle must be freed with CloseHandle().
   362  * @error				Invalid database Handle.
   363  */
   364 native Handle:SQL_Query(Handle:database, const String:query[], len=-1);
   365 
   366 /**
   367  * Creates a new prepared statement query.  Prepared statements can
   368  * be executed any number of times.  They can also have placeholder
   369  * parameters, similar to variables, which can be bound safely and
   370  * securely (for example, you do not need to quote bound strings).
   371  *
   372  * Statement handles will work in any function that accepts a Query handle.
   373  *
   374  * @param database		A database Handle.
   375  * @param query			Query string.
   376  * @param error			Error buffer.
   377  * @param maxlength		Maximum size of the error buffer.
   378  * @return				A new statement Handle on success, INVALID_HANDLE
   379  *						otherwise.  The Handle must be freed with CloseHandle().
   380  * @error				Invalid database Handle.
   381  */
   382 native Handle:SQL_PrepareQuery(Handle:database, const String:query[], String:error[], maxlength);
   383 
   384 /**
   385  * Advances to the next set of results.
   386  *
   387  * In some SQL implementations, multiple result sets can exist on one query.  
   388  * This is possible in MySQL with simple queries when executing a CALL 
   389  * query.  If this is the case, all result sets must be processed before
   390  * another query is made.
   391  *
   392  * @param query			A query Handle.
   393  * @return				True if there was another result set, false otherwise.
   394  * @error				Invalid query Handle.
   395  */
   396 native bool:SQL_FetchMoreResults(Handle:query);
   397 
   398 /**
   399  * Returns whether or not a result set exists.  This will
   400  * return true even if 0 results were returned, but false
   401  * on queries like UPDATE, INSERT, or DELETE.
   402  *
   403  * @param query			A query (or statement) Handle.
   404  * @return				True if there is a result set, false otherwise.
   405  * @error				Invalid query Handle.
   406  */
   407 native bool:SQL_HasResultSet(Handle:query);
   408 
   409 /**
   410  * Retrieves the number of rows in the last result set.
   411  * 
   412  * @param query			A query (or statement) Handle.
   413  * @return				Number of rows in the current result set.
   414  * @error				Invalid query Handle.
   415  */
   416 native SQL_GetRowCount(Handle:query);
   417 
   418 /**
   419  * Retrieves the number of fields in the last result set.
   420  * 
   421  * @param query			A query (or statement) Handle.
   422  * @return				Number of fields in the current result set.
   423  * @error				Invalid query Handle.
   424  */
   425 native SQL_GetFieldCount(Handle:query);
   426 
   427 /**
   428  * Retrieves the name of a field by index.
   429  * 
   430  * @param query			A query (or statement) Handle.
   431  * @param field			Field number (starting from 0).
   432  * @param name			Name buffer.
   433  * @param maxlength		Maximum length of the name buffer.
   434  * @noreturn
   435  * @error				Invalid query Handle, invalid field index, or
   436  *						no current result set.
   437  */
   438 native SQL_FieldNumToName(Handle:query, field, String:name[], maxlength);
   439 
   440 /**
   441  * Retrieves a field index by name.
   442  * 
   443  * @param query			A query (or statement) Handle.
   444  * @param name			Name of the field (case sensitive).
   445  * @param field			Variable to store field index in.
   446  * @return				True if found, false if not found.
   447  * @error				Invalid query Handle or no current result set.
   448  */
   449 native bool:SQL_FieldNameToNum(Handle:query, const String:name[], &field);
   450 
   451 /**
   452  * Fetches a row from the current result set.  This must be 
   453  * successfully called before any results are fetched.
   454  *
   455  * If this function fails, SQL_MoreResults() can be used to
   456  * tell if there was an error or the result set is finished.
   457  * 
   458  * @param query			A query (or statement) Handle.
   459  * @return				True if a row was fetched, false otherwise.
   460  * @error				Invalid query Handle.
   461  */
   462 native bool:SQL_FetchRow(Handle:query);
   463 
   464 /**
   465  * Returns if there are more rows.
   466  * 
   467  * @param query			A query (or statement) Handle.
   468  * @return				True if there are more rows, false otherwise.
   469  * @error				Invalid query Handle.
   470  */
   471 native bool:SQL_MoreRows(Handle:query);
   472 
   473 /**
   474  * Rewinds a result set back to the first result.
   475  * 
   476  * @param query			A query (or statement) Handle.
   477  * @return				True on success, false otherwise.
   478  * @error				Invalid query Handle or no current result set.
   479  */
   480 native bool:SQL_Rewind(Handle:query);
   481 
   482 /**
   483  * Fetches a string from a field in the current row of a result set.  
   484  * If the result is NULL, an empty string will be returned.  A NULL 
   485  * check can be done with the result parameter, or SQL_IsFieldNull().
   486  * 
   487  * @param query			A query (or statement) Handle.
   488  * @param field			The field index (starting from 0).
   489  * @param buffer		String buffer.
   490  * @param maxlength		Maximum size of the string buffer.
   491  * @param result		Optional variable to store the status of the return value.
   492  * @return				Number of bytes written.
   493  * @error				Invalid query Handle or field index, invalid
   494  *						type conversion requested from the database,
   495  *						or no current result set.
   496  */
   497 native SQL_FetchString(Handle:query, field, String:buffer[], maxlength, &DBResult:result=DBVal_Error);
   498 
   499 /**
   500  * Fetches a float from a field in the current row of a result set.  
   501  * If the result is NULL, a value of 0.0 will be returned.  A NULL 
   502  * check can be done with the result parameter, or SQL_IsFieldNull().
   503  * 
   504  * @param query			A query (or statement) Handle.
   505  * @param field			The field index (starting from 0).
   506  * @param result		Optional variable to store the status of the return value.
   507  * @return				A float value.
   508  * @error				Invalid query Handle or field index, invalid
   509  *						type conversion requested from the database,
   510  *						or no current result set.
   511  */
   512 native Float:SQL_FetchFloat(Handle:query, field, &DBResult:result=DBVal_Error);
   513 
   514 /**
   515  * Fetches an integer from a field in the current row of a result set.  
   516  * If the result is NULL, a value of 0 will be returned.  A NULL 
   517  * check can be done with the result parameter, or SQL_IsFieldNull().
   518  * 
   519  * @param query			A query (or statement) Handle.
   520  * @param field			The field index (starting from 0).
   521  * @param result		Optional variable to store the status of the return value.
   522  * @return				An integer value.
   523  * @error				Invalid query Handle or field index, invalid
   524  *						type conversion requested from the database,
   525  *						or no current result set.
   526  */
   527 native SQL_FetchInt(Handle:query, field, &DBResult:result=DBVal_Error);
   528 
   529 /**
   530  * Returns whether a field's data in the current row of a result set is 
   531  * NULL or not.  NULL is an SQL type which means "no data."
   532  * 
   533  * @param query			A query (or statement) Handle.
   534  * @param field			The field index (starting from 0).
   535  * @return				True if data is NULL, false otherwise.
   536  * @error				Invalid query Handle or field index, or no
   537  *						current result set.
   538  */
   539 native bool:SQL_IsFieldNull(Handle:query, field);
   540 
   541 /**
   542  * Returns the length of a field's data in the current row of a result
   543  * set.  This only needs to be called for strings to determine how many
   544  * bytes to use.  Note that the return value does not include the null
   545  * terminator.
   546  * 
   547  * @param query			A query (or statement) Handle.
   548  * @param field			The field index (starting from 0).
   549  * @return				Number of bytes for the field's data size.
   550  * @error				Invalid query Handle or field index or no
   551  *						current result set.
   552  */
   553 native SQL_FetchSize(Handle:query, field);
   554 
   555 /**
   556  * Binds a parameter in a prepared statement to a given integer value.
   557  * 
   558  * @param statement		A statement (prepared query) Handle.
   559  * @param param			The parameter index (starting from 0).
   560  * @param number		The number to bind.
   561  * @param signed		True to bind the number as signed, false to 
   562  *						bind it as unsigned.
   563  * @noreturn
   564  * @error				Invalid statement Handle or parameter index, or
   565  *						SQL error.
   566  */
   567 native SQL_BindParamInt(Handle:statement, param, number, bool:signed=true);
   568 
   569 /**
   570  * Binds a parameter in a prepared statement to a given float value.
   571  * 
   572  * @param statement		A statement (prepared query) Handle.
   573  * @param param			The parameter index (starting from 0).
   574  * @param value			The float number to bind.
   575  * @noreturn
   576  * @error				Invalid statement Handle or parameter index, or
   577  *						SQL error.
   578  */
   579 native SQL_BindParamFloat(Handle:statement, param, Float:value);
   580 
   581 /**
   582  * Binds a parameter in a prepared statement to a given string value.
   583  * 
   584  * @param statement		A statement (prepared query) Handle.
   585  * @param param			The parameter index (starting from 0).
   586  * @param value			The string to bind.
   587  * @param copy			Whether or not SourceMod should copy the value
   588  *						locally if necessary.  If the string contents
   589  *						won't change before calling SQL_Execute(), this
   590  *						can be set to false for optimization.
   591  * @noreturn
   592  * @error				Invalid statement Handle or parameter index, or
   593  *						SQL error.
   594  */
   595 native SQL_BindParamString(Handle:statement, param, const String:value[], bool:copy);
   596 
   597 /**
   598  * Executes a prepared statement.  All parameters must be bound beforehand.
   599  *
   600  * @param statement		A statement (prepared query) Handle.
   601  * @return				True on success, false on failure.
   602  * @error				Invalid statement Handle.
   603  */
   604 native bool:SQL_Execute(Handle:statement);
   605 
   606 /**
   607  * Locks a database so threading operations will not interrupt.
   608  * 
   609  * If you are using a database Handle for both threading and non-threading,
   610  * this MUST be called before doing any set of non-threading DB operations.
   611  * Otherwise you risk corrupting the database driver's memory or network
   612  * connection.
   613  * 
   614  * Leaving a lock on a database and then executing a threaded query results
   615  * in a dead lock! Make sure to call SQL_UnlockDatabase()!
   616  *
   617  * If the lock cannot be acquired, the main thread will pause until the 
   618  * threaded operation has concluded.
   619  *
   620  * @param database		A database Handle.
   621  * @noreturn
   622  * @error				Invalid database Handle.
   623  */
   624 native SQL_LockDatabase(Handle:database);
   625 
   626 /**
   627  * Unlocks a database so threading operations may continue.
   628  *
   629  * @param database		A database Handle.
   630  * @noreturn
   631  * @error				Invalid database Handle.
   632  */
   633 native SQL_UnlockDatabase(Handle:database);
   634 
   635 /**
   636  * General callback for threaded SQL stuff.
   637  *
   638  * @param owner			Parent object of the Handle (or INVALID_HANDLE if none).
   639  * @param hndl			Handle to the child object (or INVALID_HANDLE if none).
   640  * @param error			Error string if there was an error.  The error could be 
   641  *						empty even if an error condition exists, so it is important 
   642  *						to check the actual Handle value instead.
   643  * @param data			Data passed in via the original threaded invocation.
   644  * @param 
   645  */
   646 functag public SQLTCallback(Handle:owner, Handle:hndl, const String:error[], any:data);
   647 
   648 /**
   649  * Tells whether two database handles both point to the same database 
   650  * connection.
   651  *
   652  * @param hndl1			First database Handle.
   653  * @param hndl2			Second database Handle.
   654  * @return				True if the Handles point to the same 
   655  *						connection, false otherwise.
   656  * @error				Invalid Handle.
   657  */
   658 native bool:SQL_IsSameConnection(Handle:hndl1, Handle:hndl2);
   659 
   660 /**
   661  * Connects to a database via a thread.  This can be used instead of
   662  * SQL_Connect() if you wish for non-blocking functionality.
   663  *
   664  * It is not necessary to use this to use threaded queries.  However, if you 
   665  * don't (or you mix threaded/non-threaded queries), you should see 
   666  * SQL_LockDatabase().
   667  *
   668  * @param callback		Callback; new Handle will be in hndl, owner is the driver.
   669  *						If no driver was found, the owner is INVALID_HANDLE.
   670  * @param name			Database name.
   671  * @param data			Extra data value to pass to the callback.
   672  * @noreturn
   673  */
   674 native SQL_TConnect(SQLTCallback:callback, const String:name[]="default", any:data=0);
   675 
   676 /**
   677  * Executes a simple query via a thread.  The query Handle is passed through
   678  * the callback.
   679  *
   680  * The database Handle returned through the callback is always a new Handle,
   681  * and if necessary, SQL_IsSameConnection() should be used to test against
   682  * other conenctions.
   683  *
   684  * The query Handle returned through the callback is temporary and destroyed 
   685  * at the end of the callback.  If you need to hold onto it, use CloneHandle().
   686  *
   687  * @param database		A database Handle.
   688  * @param callback		Callback; database is in "owner" and the query Handle
   689  *						is passed in "hndl".
   690  * @param query			Query string.
   691  * @param data			Extra data value to pass to the callback.
   692  * @param prio			Priority queue to use.
   693  * @noreturn
   694  * @error				Invalid database Handle.
   695  */
   696 native SQL_TQuery(Handle:database, SQLTCallback:callback, const String:query[], any:data=0, DBPriority:prio=DBPrio_Normal);