plugins/include/dbi.inc
author Dr!fter
Thu Jul 18 21:04:03 2013 -0400 (2013-07-18)
changeset 3956 1ccbc1dfa814
parent 3947 999d29e113db
child 3967 ceafb87d38a7
permissions -rw-r--r--
Fix gdc-psyfork when checking linux offset (NPOTB)
     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  * @return				A database connection Handle, or INVALID_HANDLE on failure.
   141  * 						On failure the error buffer will be filled with a message.
   142  * @error				Invalid KeyValues handle.
   143  */
   144 native Handle:SQL_ConnectCustom(Handle:keyvalues,
   145 								String:error[],
   146 								maxlength,
   147 								bool:persistent);
   148 
   149 /**
   150  * Grabs a handle to an SQLite database, creating one if it does not exist.  
   151  *
   152  * Unless there are extenuating circumstances, you should consider using "sourcemod-local" as the 
   153  * database name.  This provides some unification between plugins on behalf of users.
   154  *
   155  * As a precaution, you should always create some sort of unique prefix to your table names so 
   156  * there are no conflicts, and you should never drop or modify tables that you do not own.
   157  *
   158  * @param database		Database name.  
   159  * @param error			Error buffer.
   160  * @param maxlength		Maximum length of the error buffer.
   161  * @return				A database connection Handle, or INVALID_HANDLE on failure.
   162  * 						On failure the error buffer will be filled with a message.
   163  */
   164 stock Handle:SQLite_UseDatabase(const String:database[],
   165 								String:error[], 
   166 								maxlength)
   167 {
   168 	new Handle:kv, Handle:db;
   169 
   170 	kv = CreateKeyValues("");
   171 	KvSetString(kv, "driver", "sqlite");
   172 	KvSetString(kv, "database", database);
   173 
   174 	db = SQL_ConnectCustom(kv, error, maxlength, false);
   175 
   176 	CloseHandle(kv);
   177 
   178 	return db;
   179 }
   180 
   181 /**
   182  * This function is deprecated.  Use SQL_ConnectCustom or SQLite_UseDatabase instead.
   183  */
   184 #pragma deprecated Use SQL_ConnectCustom instead.
   185 native Handle:SQL_ConnectEx(Handle:driver, 
   186 							const String:host[],
   187 							const String:user[], 
   188 							const String:pass[],
   189 							const String:database[],
   190 							String:error[],
   191 							maxlength,
   192 							bool:persistent=true,
   193 							port=0,
   194 							maxTimeout=0);
   195 							
   196 /**
   197  * Returns if a named configuration is present in databases.cfg.
   198  *
   199  * @param name			Configuration name.
   200  * @return				True if it exists, false otherwise.
   201  */
   202 native bool:SQL_CheckConfig(const String:name[]);
   203 
   204 /**
   205  * Returns a driver Handle from a name string.
   206  *
   207  * If the driver is not found, SourceMod will attempt
   208  * to load an extension named dbi.<name>.ext.[dll|so].
   209  *
   210  * @param name			Driver identification string, or an empty
   211  *						string to return the default driver.
   212  * @return				Driver Handle, or INVALID_HANDLE on failure.
   213  */
   214 native Handle:SQL_GetDriver(const String:name[]="");
   215 
   216 /**
   217  * Reads the driver of an opened database.
   218  *
   219  * @param database		Database Handle.
   220  * @param ident			Option buffer to store the identification string.
   221  * @param ident_length	Maximum length of the buffer.
   222  * @return				Driver Handle.
   223  */
   224 native Handle:SQL_ReadDriver(Handle:database, String:ident[]="", ident_length=0);
   225 
   226 /**
   227  * Retrieves a driver's identification string.
   228  *
   229  * Example: "mysql", "sqlite"
   230  *
   231  * @param driver		Driver Handle, or INVALID_HANDLE for the default driver.
   232  * @param ident			Identification string buffer.
   233  * @param maxlength		Maximum length of the buffer.
   234  * @noreturn
   235  * @error				Invalid Handle other than INVALID_HANDLE.
   236  */
   237 native SQL_GetDriverIdent(Handle:driver, String:ident[], maxlength);
   238 
   239 /**
   240  * Retrieves a driver's product string.
   241  *
   242  * Example: "MySQL", "SQLite"
   243  *
   244  * @param driver		Driver Handle, or INVALID_HANDLE for the default driver.
   245  * @param product		Product string buffer.
   246  * @param maxlength		Maximum length of the buffer.
   247  * @noreturn
   248  * @error				Invalid Handle other than INVALID_HANDLE.
   249  */
   250 native SQL_GetDriverProduct(Handle:driver, String:product[], maxlength);
   251 
   252 /**
   253  * Sets the character set of the current connection. 
   254  * Like SET NAMES .. in mysql, but stays after connection problems.
   255  * 
   256  * Example: "utf8", "latin1"
   257  *
   258  * @param database      Database Handle.
   259  * @param characterset  The character set string to change to.
   260  * @return              True, if character set was changed, false otherwise.
   261  */
   262 native bool:SQL_SetCharset(Handle:database, const String:charset[]);
   263 
   264 /**
   265  * Returns the number of affected rows from the last query.
   266  *
   267  * @param hndl			A database OR statement Handle.
   268  * @return				Number of rows affected by the last query.
   269  * @error				Invalid database or statement Handle.
   270  */
   271 native SQL_GetAffectedRows(Handle:hndl);
   272 
   273 /**
   274  * Returns the last query's insertion id.
   275  *
   276  * @param hndl			A database, query, OR statement Handle.
   277  * @return				Last query's insertion id.
   278  * @error				Invalid database, query, or statement Handle.
   279  */
   280 native SQL_GetInsertId(Handle:hndl);
   281 
   282 /**
   283  * Returns the error reported by the last query.
   284  *
   285  * @param hndl			A database, query, OR statement Handle.
   286  * @param error			Error buffer.
   287  * @param maxlength		Maximum length of the buffer.
   288  * @return				True if there was an error, false otherwise.
   289  * @error				Invalid database, query, or statement Handle.
   290  */
   291 native bool:SQL_GetError(Handle:hndl, String:error[], maxlength);
   292 
   293 /**
   294  * Escapes a database string for literal insertion.  This is not needed
   295  * for binding strings in prepared statements.  
   296  *
   297  * Generally, database strings are inserted into queries enclosed in 
   298  * single quotes (').  If user input has a single quote in it, the 
   299  * quote needs to be escaped.  This function ensures that any unsafe 
   300  * characters are safely escaped according to the database engine and 
   301  * the database's character set.
   302  *
   303  * NOTE: SourceMod only guarantees properly escaped strings when the query
   304  * encloses the string in ''. While drivers tend to allow " instead, the string
   305  * may be not be escaped (for example, on SQLite)!
   306  *
   307  * @param hndl			A database Handle.
   308  * @param string		String to quote.
   309  * @param buffer		Buffer to store quoted string in.
   310  * @param maxlength		Maximum length of the buffer.
   311  * @param written		Optionally returns the number of bytes written.
   312  * @return				True on success, false if buffer is not big enough.
   313  *						The buffer must be at least 2*strlen(string)+1.
   314  * @error				Invalid database or statement Handle.
   315  */
   316 native bool:SQL_EscapeString(Handle:database, 
   317 							 const String:string[], 
   318 							 String:buffer[], 
   319 							 maxlength, 
   320 							 &written=0);
   321 
   322 /**
   323  * This is a backwards compatibility stock.  You should use SQL_EscapeString() 
   324  * instead, as this function will probably be deprecated in SourceMod 1.1.
   325  */
   326 stock bool:SQL_QuoteString(Handle:database,
   327 						   const String:string[],
   328 						   String:buffer[],
   329 						   maxlength,
   330 						   &written=0)
   331 {
   332 	return SQL_EscapeString(database, string, buffer, maxlength, written);
   333 }
   334 
   335 /**
   336  * Executes a query and ignores the result set.
   337  *
   338  * @param database		A database Handle.
   339  * @param query			Query string.
   340  * @param len			Optional parameter to specify the query length, in 
   341  *						bytes.  This can be used to send binary queries that 
   342  * 						have a premature terminator.
   343  * @return				True if query succeeded, false otherwise.  Use
   344  *						SQL_GetError to find the last error.
   345  * @error				Invalid database Handle.
   346  */
   347 native bool:SQL_FastQuery(Handle:database, const String:query[], len=-1);
   348 
   349 /**
   350  * Executes a simple query and returns a new query Handle for
   351  * receiving the results.
   352  *
   353  * @param database		A database Handle.
   354  * @param query			Query string.
   355  * @param len			Optional parameter to specify the query length, in 
   356  *						bytes.  This can be used to send binary queries that 
   357  * 						have a premature terminator.
   358  * @return				A new Query Handle on success, INVALID_HANDLE
   359  *						otherwise.  The Handle must be freed with CloseHandle().
   360  * @error				Invalid database Handle.
   361  */
   362 native Handle:SQL_Query(Handle:database, const String:query[], len=-1);
   363 
   364 /**
   365  * Creates a new prepared statement query.  Prepared statements can
   366  * be executed any number of times.  They can also have placeholder
   367  * parameters, similar to variables, which can be bound safely and
   368  * securely (for example, you do not need to quote bound strings).
   369  *
   370  * Statement handles will work in any function that accepts a Query handle.
   371  *
   372  * @param database		A database Handle.
   373  * @param query			Query string.
   374  * @param error			Error buffer.
   375  * @param maxlength		Maximum size of the error buffer.
   376  * @return				A new statement Handle on success, INVALID_HANDLE
   377  *						otherwise.  The Handle must be freed with CloseHandle().
   378  * @error				Invalid database Handle.
   379  */
   380 native Handle:SQL_PrepareQuery(Handle:database, const String:query[], String:error[], maxlength);
   381 
   382 /**
   383  * Advances to the next set of results.
   384  *
   385  * In some SQL implementations, multiple result sets can exist on one query.  
   386  * This is possible in MySQL with simple queries when executing a CALL 
   387  * query.  If this is the case, all result sets must be processed before
   388  * another query is made.
   389  *
   390  * @param query			A query Handle.
   391  * @return				True if there was another result set, false otherwise.
   392  * @error				Invalid query Handle.
   393  */
   394 native bool:SQL_FetchMoreResults(Handle:query);
   395 
   396 /**
   397  * Returns whether or not a result set exists.  This will
   398  * return true even if 0 results were returned, but false
   399  * on queries like UPDATE, INSERT, or DELETE.
   400  *
   401  * @param query			A query (or statement) Handle.
   402  * @return				True if there is a result set, false otherwise.
   403  * @error				Invalid query Handle.
   404  */
   405 native bool:SQL_HasResultSet(Handle:query);
   406 
   407 /**
   408  * Retrieves the number of rows in the last result set.
   409  * 
   410  * @param query			A query (or statement) Handle.
   411  * @return				Number of rows in the current result set.
   412  * @error				Invalid query Handle.
   413  */
   414 native SQL_GetRowCount(Handle:query);
   415 
   416 /**
   417  * Retrieves the number of fields in the last result set.
   418  * 
   419  * @param query			A query (or statement) Handle.
   420  * @return				Number of fields in the current result set.
   421  * @error				Invalid query Handle.
   422  */
   423 native SQL_GetFieldCount(Handle:query);
   424 
   425 /**
   426  * Retrieves the name of a field by index.
   427  * 
   428  * @param query			A query (or statement) Handle.
   429  * @param field			Field number (starting from 0).
   430  * @param name			Name buffer.
   431  * @param maxlength		Maximum length of the name buffer.
   432  * @noreturn
   433  * @error				Invalid query Handle, invalid field index, or
   434  *						no current result set.
   435  */
   436 native SQL_FieldNumToName(Handle:query, field, String:name[], maxlength);
   437 
   438 /**
   439  * Retrieves a field index by name.
   440  * 
   441  * @param query			A query (or statement) Handle.
   442  * @param name			Name of the field (case sensitive).
   443  * @param field			Variable to store field index in.
   444  * @return				True if found, false if not found.
   445  * @error				Invalid query Handle or no current result set.
   446  */
   447 native bool:SQL_FieldNameToNum(Handle:query, const String:name[], &field);
   448 
   449 /**
   450  * Fetches a row from the current result set.  This must be 
   451  * successfully called before any results are fetched.
   452  *
   453  * If this function fails, SQL_MoreResults() can be used to
   454  * tell if there was an error or the result set is finished.
   455  * 
   456  * @param query			A query (or statement) Handle.
   457  * @return				True if a row was fetched, false otherwise.
   458  * @error				Invalid query Handle.
   459  */
   460 native bool:SQL_FetchRow(Handle:query);
   461 
   462 /**
   463  * Returns if there are more rows.
   464  * 
   465  * @param query			A query (or statement) Handle.
   466  * @return				True if there are more rows, false otherwise.
   467  * @error				Invalid query Handle.
   468  */
   469 native bool:SQL_MoreRows(Handle:query);
   470 
   471 /**
   472  * Rewinds a result set back to the first result.
   473  * 
   474  * @param query			A query (or statement) Handle.
   475  * @return				True on success, false otherwise.
   476  * @error				Invalid query Handle or no current result set.
   477  */
   478 native bool:SQL_Rewind(Handle:query);
   479 
   480 /**
   481  * Fetches a string from a field in the current row of a result set.  
   482  * If the result is NULL, an empty string will be returned.  A NULL 
   483  * check can be done with the result parameter, or SQL_IsFieldNull().
   484  * 
   485  * @param query			A query (or statement) Handle.
   486  * @param field			The field index (starting from 0).
   487  * @param buffer		String buffer.
   488  * @param maxlength		Maximum size of the string buffer.
   489  * @param result		Optional variable to store the status of the return value.
   490  * @return				Number of bytes written.
   491  * @error				Invalid query Handle or field index, invalid
   492  *						type conversion requested from the database,
   493  *						or no current result set.
   494  */
   495 native SQL_FetchString(Handle:query, field, String:buffer[], maxlength, &DBResult:result=DBVal_Error);
   496 
   497 /**
   498  * Fetches a float from a field in the current row of a result set.  
   499  * If the result is NULL, a value of 0.0 will be returned.  A NULL 
   500  * check can be done with the result parameter, or SQL_IsFieldNull().
   501  * 
   502  * @param query			A query (or statement) Handle.
   503  * @param field			The field index (starting from 0).
   504  * @param result		Optional variable to store the status of the return value.
   505  * @return				A float value.
   506  * @error				Invalid query Handle or field index, invalid
   507  *						type conversion requested from the database,
   508  *						or no current result set.
   509  */
   510 native Float:SQL_FetchFloat(Handle:query, field, &DBResult:result=DBVal_Error);
   511 
   512 /**
   513  * Fetches an integer from a field in the current row of a result set.  
   514  * If the result is NULL, a value of 0 will be returned.  A NULL 
   515  * check can be done with the result parameter, or SQL_IsFieldNull().
   516  * 
   517  * @param query			A query (or statement) Handle.
   518  * @param field			The field index (starting from 0).
   519  * @param result		Optional variable to store the status of the return value.
   520  * @return				An integer value.
   521  * @error				Invalid query Handle or field index, invalid
   522  *						type conversion requested from the database,
   523  *						or no current result set.
   524  */
   525 native SQL_FetchInt(Handle:query, field, &DBResult:result=DBVal_Error);
   526 
   527 /**
   528  * Returns whether a field's data in the current row of a result set is 
   529  * NULL or not.  NULL is an SQL type which means "no data."
   530  * 
   531  * @param query			A query (or statement) Handle.
   532  * @param field			The field index (starting from 0).
   533  * @return				True if data is NULL, false otherwise.
   534  * @error				Invalid query Handle or field index, or no
   535  *						current result set.
   536  */
   537 native bool:SQL_IsFieldNull(Handle:query, field);
   538 
   539 /**
   540  * Returns the length of a field's data in the current row of a result
   541  * set.  This only needs to be called for strings to determine how many
   542  * bytes to use.  Note that the return value does not include the null
   543  * terminator.
   544  * 
   545  * @param query			A query (or statement) Handle.
   546  * @param field			The field index (starting from 0).
   547  * @return				Number of bytes for the field's data size.
   548  * @error				Invalid query Handle or field index or no
   549  *						current result set.
   550  */
   551 native SQL_FetchSize(Handle:query, field);
   552 
   553 /**
   554  * Binds a parameter in a prepared statement to a given integer value.
   555  * 
   556  * @param statement		A statement (prepared query) Handle.
   557  * @param param			The parameter index (starting from 0).
   558  * @param number		The number to bind.
   559  * @param signed		True to bind the number as signed, false to 
   560  *						bind it as unsigned.
   561  * @noreturn
   562  * @error				Invalid statement Handle or parameter index, or
   563  *						SQL error.
   564  */
   565 native SQL_BindParamInt(Handle:statement, param, number, bool:signed=true);
   566 
   567 /**
   568  * Binds a parameter in a prepared statement to a given float value.
   569  * 
   570  * @param statement		A statement (prepared query) Handle.
   571  * @param param			The parameter index (starting from 0).
   572  * @param float			The float number to bind.
   573  * @noreturn
   574  * @error				Invalid statement Handle or parameter index, or
   575  *						SQL error.
   576  */
   577 native SQL_BindParamFloat(Handle:statement, param, Float:value);
   578 
   579 /**
   580  * Binds a parameter in a prepared statement to a given string value.
   581  * 
   582  * @param statement		A statement (prepared query) Handle.
   583  * @param param			The parameter index (starting from 0).
   584  * @param value			The string to bind.
   585  * @param copy			Whether or not SourceMod should copy the value
   586  *						locally if necessary.  If the string contents
   587  *						won't change before calling SQL_Execute(), this
   588  *						can be set to false for optimization.
   589  * @noreturn
   590  * @error				Invalid statement Handle or parameter index, or
   591  *						SQL error.
   592  */
   593 native SQL_BindParamString(Handle:statement, param, const String:value[], bool:copy);
   594 
   595 /**
   596  * Executes a prepared statement.  All parameters must be bound beforehand.
   597  *
   598  * @param statement		A statement (prepared query) Handle.
   599  * @return				True on success, false on failure.
   600  * @error				Invalid statement Handle.
   601  */
   602 native bool:SQL_Execute(Handle:statement);
   603 
   604 /**
   605  * Locks a database so threading operations will not interrupt.
   606  * 
   607  * If you are using a database Handle for both threading and non-threading,
   608  * this MUST be called before doing any set of non-threading DB operations.
   609  * Otherwise you risk corrupting the database driver's memory or network
   610  * connection.
   611  * 
   612  * Leaving a lock on a database and then executing a threaded query results
   613  * in a dead lock! Make sure to call SQL_UnlockDatabase()!
   614  *
   615  * If the lock cannot be acquired, the main thread will pause until the 
   616  * threaded operation has concluded.
   617  *
   618  * @param database		A database Handle.
   619  * @noreturn
   620  * @error				Invalid database Handle.
   621  */
   622 native SQL_LockDatabase(Handle:database);
   623 
   624 /**
   625  * Unlocks a database so threading operations may continue.
   626  *
   627  * @param database		A database Handle.
   628  * @noreturn
   629  * @error				Invalid database Handle.
   630  */
   631 native SQL_UnlockDatabase(Handle:database);
   632 
   633 /**
   634  * General callback for threaded SQL stuff.
   635  *
   636  * @param db			Parent object of the Handle (or INVALID_HANDLE if none).
   637  * @param hndl			Handle to the child object (or INVALID_HANDLE if none).
   638  * @param error			Error string if there was an error.  The error could be 
   639  *						empty even if an error condition exists, so it is important 
   640  *						to check the actual Handle value instead.
   641  * @param data			Data passed in via the original threaded invocation.
   642  * @param 
   643  */
   644 functag public SQLTCallback(Handle:owner, Handle:hndl, const String:error[], any:data);
   645 
   646 /**
   647  * Tells whether two database handles both point to the same database 
   648  * connection.
   649  *
   650  * @param hndl1			First database Handle.
   651  * @param hndl2			Second database Handle.
   652  * @return				True if the Handles point to the same 
   653  *						connection, false otherwise.
   654  * @error				Invalid Handle.
   655  */
   656 native bool:SQL_IsSameConnection(Handle:hndl1, Handle:hndl2);
   657 
   658 /**
   659  * Connects to a database via a thread.  This can be used instead of
   660  * SQL_Connect() if you wish for non-blocking functionality.
   661  *
   662  * It is not necessary to use this to use threaded queries.  However, if you 
   663  * don't (or you mix threaded/non-threaded queries), you should see 
   664  * SQL_LockDatabase().
   665  *
   666  * @param callback		Callback; new Handle will be in hndl, owner is the driver.
   667  *						If no driver was found, the owner is INVALID_HANDLE.
   668  * @param name			Database name.
   669  * @noreturn
   670  */
   671 native SQL_TConnect(SQLTCallback:callback, const String:name[]="default", any:data=0);
   672 
   673 /**
   674  * Executes a simple query via a thread.  The query Handle is passed through
   675  * the callback.
   676  *
   677  * The database Handle returned through the callback is always a new Handle,
   678  * and if necessary, SQL_IsSameConnection() should be used to test against
   679  * other conenctions.
   680  *
   681  * The query Handle returned through the callback is temporary and destroyed 
   682  * at the end of the callback.  If you need to hold onto it, use CloneHandle().
   683  *
   684  * @param database		A database Handle.
   685  * @param callback		Callback; database is in "owner" and the query Handle
   686  *						is passed in "hndl".
   687  * @param query			Query string.
   688  * @param data			Extra data value to pass to the callback.
   689  * @param prio			Priority queue to use.
   690  * @noreturn
   691  * @error				Invalid database Handle.
   692  */
   693 native SQL_TQuery(Handle:database, SQLTCallback:callback, const String:query[], any:data=0, DBPriority:prio=DBPrio_Normal);