plugins/include/dbi.inc
branchrefac-jit
changeset 2168 c24a6fa957db
child 2289 44045ead61cd
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/plugins/include/dbi.inc	Sun Jul 06 04:49:55 2008 +0000
     1.3 @@ -0,0 +1,633 @@
     1.4 +/**
     1.5 + * vim: set ts=4 :
     1.6 + * =============================================================================
     1.7 + * SourceMod (C)2004-2008 AlliedModders LLC.  All rights reserved.
     1.8 + * =============================================================================
     1.9 + *
    1.10 + * This file is part of the SourceMod/SourcePawn SDK.
    1.11 + *
    1.12 + * This program is free software; you can redistribute it and/or modify it under
    1.13 + * the terms of the GNU General Public License, version 3.0, as published by the
    1.14 + * Free Software Foundation.
    1.15 + * 
    1.16 + * This program is distributed in the hope that it will be useful, but WITHOUT
    1.17 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    1.18 + * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
    1.19 + * details.
    1.20 + *
    1.21 + * You should have received a copy of the GNU General Public License along with
    1.22 + * this program.  If not, see <http://www.gnu.org/licenses/>.
    1.23 + *
    1.24 + * As a special exception, AlliedModders LLC gives you permission to link the
    1.25 + * code of this program (as well as its derivative works) to "Half-Life 2," the
    1.26 + * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
    1.27 + * by the Valve Corporation.  You must obey the GNU General Public License in
    1.28 + * all respects for all other code used.  Additionally, AlliedModders LLC grants
    1.29 + * this exception to all derivative works.  AlliedModders LLC defines further
    1.30 + * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
    1.31 + * or <http://www.sourcemod.net/license.php>.
    1.32 + *
    1.33 + * Version: $Id$
    1.34 + */
    1.35 + 
    1.36 +#if defined _dbi_included
    1.37 + #endinput
    1.38 +#endif
    1.39 +#define _dbi_included
    1.40 +
    1.41 +/**
    1.42 + * @handle Driver
    1.43 + *
    1.44 + * Contains information about an SQL driver.
    1.45 + */
    1.46 + 
    1.47 +/**
    1.48 + * @handle Database
    1.49 + *
    1.50 + * Contains information about a database connection.
    1.51 + */
    1.52 + 
    1.53 +/**
    1.54 + * @handle Query
    1.55 + *
    1.56 + * Contains information about an active query and its 
    1.57 + * result sets.
    1.58 + */
    1.59 + 
    1.60 +/**
    1.61 + * @handle Statement : Query
    1.62 + *
    1.63 + * Extends a Query Handle and can be used as a Query Handle.
    1.64 + * Statement Handles are for prepared queries and contain
    1.65 + * their own function for binding parameters.  Statement
    1.66 + * Handles can be used instead of database Handles in a few
    1.67 + * select functions.
    1.68 + */
    1.69 +
    1.70 +/**
    1.71 + * Describes a database field fetch status.
    1.72 + */
    1.73 +enum DBResult
    1.74 +{
    1.75 +	DBVal_Error = 0,		/**< Column number/field is invalid. */
    1.76 +	DBVal_TypeMismatch = 1,	/**< You cannot retrieve this data with this type. */
    1.77 +	DBVal_Null = 2,			/**< Field has no data (NULL) */
    1.78 +	DBVal_Data = 3,			/**< Field has data */
    1.79 +};
    1.80 +
    1.81 +/**
    1.82 + * Describes binding types.
    1.83 + */
    1.84 +enum DBBindType
    1.85 +{
    1.86 +	DBBind_Int = 0,			/**< Bind an integer. */
    1.87 +	DBBind_Float = 1,		/**< Bind a float. */
    1.88 +	DBBind_String = 2,		/**< Bind a string. */
    1.89 +};
    1.90 +
    1.91 +/**
    1.92 + * Threading priority level.
    1.93 + */
    1.94 +enum DBPriority
    1.95 +{
    1.96 +	DBPrio_High = 0,		/**< High priority. */
    1.97 +	DBPrio_Normal = 1,		/**< Normal priority. */
    1.98 +	DBPrio_Low = 2,			/**< Low priority. */
    1.99 +};
   1.100 +
   1.101 +/**
   1.102 + * Creates an SQL connection from a named configuration.
   1.103 + *
   1.104 + * @param confname		Named configuration.
   1.105 + * @param persistent	True to re-use a previous persistent connection if
   1.106 + *						possible, false otherwise.
   1.107 + * @param error			Error buffer.
   1.108 + * @param maxlength		Maximum length of the error buffer.
   1.109 + * @return				A database connection Handle, or INVALID_HANDLE on failure.
   1.110 + */
   1.111 +native Handle:SQL_Connect(const String:confname[], bool:persistent, String:error[], maxlength);
   1.112 +
   1.113 +/**
   1.114 + * Creates a default SQL connection.
   1.115 + *
   1.116 + * @param error			Error buffer.
   1.117 + * @param maxlength		Maximum length of the error buffer.
   1.118 + * @param persistent	True to re-use a previous persistent connection
   1.119 + *						if possible, false otherwise.
   1.120 + * @return				A database connection Handle, or INVALID_HANDLE on failure.
   1.121 + */
   1.122 +stock Handle:SQL_DefConnect(String:error[], maxlength, bool:persistent=true)
   1.123 +{
   1.124 +	return SQL_Connect("default", persistent, error, maxlength);
   1.125 +}
   1.126 +
   1.127 +/**
   1.128 + * Creates an SQL connection from specific parameters.
   1.129 + *
   1.130 + * @param driver		Driver Handle, or INVALID_HANDLE for default.
   1.131 + * @param host			Host name.
   1.132 + * @param user			User name.
   1.133 + * @param pass			User password.
   1.134 + * @param database		Database name.
   1.135 + * @param error			Error buffer.
   1.136 + * @param maxlength		Maximum length of the error buffer.
   1.137 + * @param persistent	True to re-use a previous persistent connection 
   1.138 + *						if possible, false otherwise.
   1.139 + * @param port			Optional port to specify.
   1.140 + * @param maxTimeout	Maximum timeout in seconds if applicable.
   1.141 + * @return				A database connection Handle, or INVALID_HANDLE on failure.
   1.142 + * @error				Invalid driver Handle other than INVALID_HANDLE.
   1.143 + */
   1.144 +native Handle:SQL_ConnectEx(Handle:driver, 
   1.145 +							const String:host[],
   1.146 +							const String:user[], 
   1.147 +							const String:pass[],
   1.148 +							const String:database[],
   1.149 +							String:error[],
   1.150 +							maxlength,
   1.151 +							bool:persistent=true,
   1.152 +							port=0,
   1.153 +							maxTimeout=0);
   1.154 +							
   1.155 +/**
   1.156 + * Returns if a named configuration is present in databases.cfg.
   1.157 + *
   1.158 + * @param name			Configuration name.
   1.159 + * @return				True if it exists, false otherwise.
   1.160 + */
   1.161 +native bool:SQL_CheckConfig(const String:name[]);
   1.162 +
   1.163 +/**
   1.164 + * Returns a driver Handle from a name string.
   1.165 + *
   1.166 + * If the driver is not found, SourceMod will attempt
   1.167 + * to load an extension named dbi.<name>.ext.[dll|so].
   1.168 + *
   1.169 + * @param name			Driver identification string, or an empty
   1.170 + *						string to return the default driver.
   1.171 + * @return				Driver Handle, or INVALID_HANDLE on failure.
   1.172 + */
   1.173 +native Handle:SQL_GetDriver(const String:name[]="");
   1.174 +
   1.175 +/**
   1.176 + * Reads the driver of an opened database.
   1.177 + *
   1.178 + * @param database		Database Handle.
   1.179 + * @param ident			Option buffer to store the identification string.
   1.180 + * @param ident_length	Maximum length of the buffer.
   1.181 + * @return				Driver Handle.
   1.182 + */
   1.183 +native Handle:SQL_ReadDriver(Handle:database, String:ident[]="", ident_length=0);
   1.184 +
   1.185 +/**
   1.186 + * Retrieves a driver's identification string.
   1.187 + *
   1.188 + * Example: "mysql", "sqlite"
   1.189 + *
   1.190 + * @param driver		Driver Handle, or INVALID_HANDLE for the default driver.
   1.191 + * @param ident			Identification string buffer.
   1.192 + * @param maxlength		Maximum length of the buffer.
   1.193 + * @noreturn
   1.194 + * @error				Invalid Handle other than INVALID_HANDLE.
   1.195 + */
   1.196 +native SQL_GetDriverIdent(Handle:driver, String:ident[], maxlength);
   1.197 +
   1.198 +/**
   1.199 + * Retrieves a driver's product string.
   1.200 + *
   1.201 + * Example: "MySQL", "SQLite"
   1.202 + *
   1.203 + * @param driver		Driver Handle, or INVALID_HANDLE for the default driver.
   1.204 + * @param product		Product string buffer.
   1.205 + * @param maxlength		Maximum length of the buffer.
   1.206 + * @noreturn
   1.207 + * @error				Invalid Handle other than INVALID_HANDLE.
   1.208 + */
   1.209 +native SQL_GetDriverProduct(Handle:driver, String:product[], maxlength);
   1.210 +
   1.211 +/**
   1.212 + * Returns the number of affected rows from the last query.
   1.213 + *
   1.214 + * @param hndl			A database OR statement Handle.
   1.215 + * @return				Number of rows affected by the last query.
   1.216 + * @error				Invalid database or statement Handle.
   1.217 + */
   1.218 +native SQL_GetAffectedRows(Handle:hndl);
   1.219 +
   1.220 +/**
   1.221 + * Returns the last query's insertion id.
   1.222 + *
   1.223 + * @param hndl			A database OR statement Handle.
   1.224 + * @return				Last query's insertion id.
   1.225 + * @error				Invalid database or statement Handle.
   1.226 + */
   1.227 +native SQL_GetInsertId(Handle:hndl);
   1.228 +
   1.229 +/**
   1.230 + * Returns the error reported by the last query.
   1.231 + *
   1.232 + * @param hndl			A database OR statement Handle.
   1.233 + * @param error			Error buffer.
   1.234 + * @param maxlength		Maximum length of the buffer.
   1.235 + * @return				True if there was an error, false otherwise.
   1.236 + * @error				Invalid database or statement Handle.
   1.237 + */
   1.238 +native bool:SQL_GetError(Handle:hndl, String:error[], maxlength);
   1.239 +
   1.240 +/**
   1.241 + * Escapes a database string for literal insertion.  This is not needed
   1.242 + * for binding strings in prepared statements.  
   1.243 + *
   1.244 + * Generally, database strings are inserted into queries enclosed in 
   1.245 + * single quotes (').  If user input has a single quote in it, the 
   1.246 + * quote needs to be escaped.  This function ensures that any unsafe 
   1.247 + * characters are safely escaped according to the database engine and 
   1.248 + * the database's character set.
   1.249 + *
   1.250 + * @param hndl			A database Handle.
   1.251 + * @param string		String to quote.
   1.252 + * @param buffer		Buffer to store quoted string in.
   1.253 + * @param maxlength		Maximum length of the buffer.
   1.254 + * @param written		Optionally returns the number of bytes written.
   1.255 + * @return				True on success, false if buffer is not big enough.
   1.256 + *						The buffer must be at least 2*strlen(string)+1.
   1.257 + * @error				Invalid database or statement Handle.
   1.258 + */
   1.259 +native bool:SQL_EscapeString(Handle:database, 
   1.260 +							 const String:string[], 
   1.261 +							 String:buffer[], 
   1.262 +							 maxlength, 
   1.263 +							 &written=0);
   1.264 +
   1.265 +/**
   1.266 + * This is a backwards compatibility stock.  You should use SQL_EscapeString() 
   1.267 + * instead, as this function will probably be deprecated in SourceMod 1.1.
   1.268 + */
   1.269 +stock bool:SQL_QuoteString(Handle:database,
   1.270 +						   const String:string[],
   1.271 +						   String:buffer[],
   1.272 +						   maxlength,
   1.273 +						   &written=0)
   1.274 +{
   1.275 +	return SQL_EscapeString(database, string, buffer, maxlength, written);
   1.276 +}
   1.277 +
   1.278 +/**
   1.279 + * Executes a query and ignores the result set.
   1.280 + *
   1.281 + * @param database		A database Handle.
   1.282 + * @param query			Query string.
   1.283 + * @param len			Optional parameter to specify the query length, in 
   1.284 + *						bytes.  This can be used to send binary queries that 
   1.285 + * 						have a premature terminator.
   1.286 + * @return				True if query succeeded, false otherwise.  Use
   1.287 + *						SQL_GetError to find the last error.
   1.288 + * @error				Invalid database Handle.
   1.289 + */
   1.290 +native bool:SQL_FastQuery(Handle:database, const String:query[], len=-1);
   1.291 +
   1.292 +/**
   1.293 + * Executes a simple query and returns a new query Handle for
   1.294 + * receiving the results.
   1.295 + *
   1.296 + * @param database		A database Handle.
   1.297 + * @param query			Query string.
   1.298 + * @param len			Optional parameter to specify the query length, in 
   1.299 + *						bytes.  This can be used to send binary queries that 
   1.300 + * 						have a premature terminator.
   1.301 + * @return				A new Query Handle on success, INVALID_HANDLE
   1.302 + *						otherwise.  The Handle must be freed with CloseHandle().
   1.303 + * @error				Invalid database Handle.
   1.304 + */
   1.305 +native Handle:SQL_Query(Handle:database, const String:query[], len=-1);
   1.306 +
   1.307 +/**
   1.308 + * Creates a new prepared statement query.  Prepared statements can
   1.309 + * be executed any number of times.  They can also have placeholder
   1.310 + * parameters, similar to variables, which can be bound safely and
   1.311 + * securely (for example, you do not need to quote bound strings).
   1.312 + *
   1.313 + * Statement handles will work in any function that accepts a Query handle.
   1.314 + *
   1.315 + * @param database		A database Handle.
   1.316 + * @param query			Query string.
   1.317 + * @param error			Error buffer.
   1.318 + * @param maxlength		Maximum size of the error buffer.
   1.319 + * @return				A new statement Handle on success, INVALID_HANDLE
   1.320 + *						otherwise.  The Handle must be freed with CloseHandle().
   1.321 + * @error				Invalid database Handle.
   1.322 + */
   1.323 +native Handle:SQL_PrepareQuery(Handle:database, const String:query[], String:error[], maxlength);
   1.324 +
   1.325 +/**
   1.326 + * Advances to the next set of results.
   1.327 + *
   1.328 + * In some SQL implementations, multiple result sets can exist on one query.  
   1.329 + * This is possible in MySQL with simple queries when executing a CALL 
   1.330 + * query.  If this is the case, all result sets must be processed before
   1.331 + * another query is made.
   1.332 + *
   1.333 + * @param query			A query Handle.
   1.334 + * @return				True if there was another result set, false otherwise.
   1.335 + * @error				Invalid query Handle.
   1.336 + */
   1.337 +native bool:SQL_FetchMoreResults(Handle:query);
   1.338 +
   1.339 +/**
   1.340 + * Returns whether or not a result set exists.  This will
   1.341 + * return true even if 0 results were returned, but false
   1.342 + * on queries like UPDATE, INSERT, or DELETE.
   1.343 + *
   1.344 + * @param query			A query (or statement) Handle.
   1.345 + * @return				True if there is a result set, false otherwise.
   1.346 + * @error				Invalid query Handle.
   1.347 + */
   1.348 +native bool:SQL_HasResultSet(Handle:query);
   1.349 +
   1.350 +/**
   1.351 + * Retrieves the number of rows in the last result set.
   1.352 + * 
   1.353 + * @param query			A query (or statement) Handle.
   1.354 + * @return				Number of rows in the current result set.
   1.355 + * @error				Invalid query Handle.
   1.356 + */
   1.357 +native SQL_GetRowCount(Handle:query);
   1.358 +
   1.359 +/**
   1.360 + * Retrieves the number of fields in the last result set.
   1.361 + * 
   1.362 + * @param query			A query (or statement) Handle.
   1.363 + * @return				Number of fields in the current result set.
   1.364 + * @error				Invalid query Handle.
   1.365 + */
   1.366 +native SQL_GetFieldCount(Handle:query);
   1.367 +
   1.368 +/**
   1.369 + * Retrieves the name of a field by index.
   1.370 + * 
   1.371 + * @param query			A query (or statement) Handle.
   1.372 + * @param field			Field number (starting from 0).
   1.373 + * @param name			Name buffer.
   1.374 + * @param maxlength		Maximum length of the name buffer.
   1.375 + * @noreturn
   1.376 + * @error				Invalid query Handle, invalid field index, or
   1.377 + *						no current result set.
   1.378 + */
   1.379 +native SQL_FieldNumToName(Handle:query, field, String:name[], maxlength);
   1.380 +
   1.381 +/**
   1.382 + * Retrieves a field index by name.
   1.383 + * 
   1.384 + * @param query			A query (or statement) Handle.
   1.385 + * @param name			Name of the field (case sensitive).
   1.386 + * @param field			Variable to store field index in.
   1.387 + * @return				True if found, false if not found.
   1.388 + * @error				Invalid query Handle or no current result set.
   1.389 + */
   1.390 +native bool:SQL_FieldNameToNum(Handle:query, const String:name[], &field);
   1.391 +
   1.392 +/**
   1.393 + * Fetches a row from the current result set.  This must be 
   1.394 + * successfully called before any results are fetched.
   1.395 + *
   1.396 + * If this function fails, SQL_MoreResults() can be used to
   1.397 + * tell if there was an error or the result set is finished.
   1.398 + * 
   1.399 + * @param query			A query (or statement) Handle.
   1.400 + * @return				True if a row was fetched, false otherwise.
   1.401 + * @error				Invalid query Handle.
   1.402 + */
   1.403 +native bool:SQL_FetchRow(Handle:query);
   1.404 +
   1.405 +/**
   1.406 + * Returns if there are more rows.
   1.407 + * 
   1.408 + * @param query			A query (or statement) Handle.
   1.409 + * @return				True if there are more rows, false otherwise.
   1.410 + * @error				Invalid query Handle.
   1.411 + */
   1.412 +native bool:SQL_MoreRows(Handle:query);
   1.413 +
   1.414 +/**
   1.415 + * Rewinds a result set back to the first result.
   1.416 + * 
   1.417 + * @param query			A query (or statement) Handle.
   1.418 + * @return				True on success, false otherwise.
   1.419 + * @error				Invalid query Handle or no current result set.
   1.420 + */
   1.421 +native bool:SQL_Rewind(Handle:query);
   1.422 +
   1.423 +/**
   1.424 + * Fetches a string from a field in the current row of a result set.  
   1.425 + * If the result is NULL, an empty string will be returned.  A NULL 
   1.426 + * check can be done with the result parameter, or SQL_IsFieldNull().
   1.427 + * 
   1.428 + * @param query			A query (or statement) Handle.
   1.429 + * @param field			The field index (starting from 0).
   1.430 + * @param buffer		String buffer.
   1.431 + * @param maxlength		Maximum size of the string buffer.
   1.432 + * @param result		Optional variable to store the status of the return value.
   1.433 + * @return				Number of bytes written.
   1.434 + * @error				Invalid query Handle or field index, invalid
   1.435 + *						type conversion requested from the database,
   1.436 + *						or no current result set.
   1.437 + */
   1.438 +native SQL_FetchString(Handle:query, field, String:buffer[], maxlength, &DBResult:result=DBVal_Error);
   1.439 +
   1.440 +/**
   1.441 + * Fetches a float from a field in the current row of a result set.  
   1.442 + * If the result is NULL, a value of 0.0 will be returned.  A NULL 
   1.443 + * check can be done with the result parameter, or SQL_IsFieldNull().
   1.444 + * 
   1.445 + * @param query			A query (or statement) Handle.
   1.446 + * @param field			The field index (starting from 0).
   1.447 + * @param result		Optional variable to store the status of the return value.
   1.448 + * @return				A float value.
   1.449 + * @error				Invalid query Handle or field index, invalid
   1.450 + *						type conversion requested from the database,
   1.451 + *						or no current result set.
   1.452 + */
   1.453 +native Float:SQL_FetchFloat(Handle:query, field, &DBResult:result=DBVal_Error);
   1.454 +
   1.455 +/**
   1.456 + * Fetches an integer from a field in the current row of a result set.  
   1.457 + * If the result is NULL, a value of 0 will be returned.  A NULL 
   1.458 + * check can be done with the result parameter, or SQL_IsFieldNull().
   1.459 + * 
   1.460 + * @param query			A query (or statement) Handle.
   1.461 + * @param field			The field index (starting from 0).
   1.462 + * @param result		Optional variable to store the status of the return value.
   1.463 + * @return				An integer value.
   1.464 + * @error				Invalid query Handle or field index, invalid
   1.465 + *						type conversion requested from the database,
   1.466 + *						or no current result set.
   1.467 + */
   1.468 +native SQL_FetchInt(Handle:query, field, &DBResult:result=DBVal_Error);
   1.469 +
   1.470 +/**
   1.471 + * Returns whether a field's data in the current row of a result set is 
   1.472 + * NULL or not.  NULL is an SQL type which means "no data."
   1.473 + * 
   1.474 + * @param query			A query (or statement) Handle.
   1.475 + * @param field			The field index (starting from 0).
   1.476 + * @return				True if data is NULL, false otherwise.
   1.477 + * @error				Invalid query Handle or field index, or no
   1.478 + *						current result set.
   1.479 + */
   1.480 +native bool:SQL_IsFieldNull(Handle:query, field);
   1.481 +
   1.482 +/**
   1.483 + * Returns the length of a field's data in the current row of a result
   1.484 + * set.  This only needs to be called for strings to determine how many
   1.485 + * bytes to use.  Note that the return value does not include the null
   1.486 + * terminator.
   1.487 + * 
   1.488 + * @param query			A query (or statement) Handle.
   1.489 + * @param field			The field index (starting from 0).
   1.490 + * @return				Number of bytes for the field's data size.
   1.491 + * @error				Invalid query Handle or field index or no
   1.492 + *						current result set.
   1.493 + */
   1.494 +native SQL_FetchSize(Handle:query, field);
   1.495 +
   1.496 +/**
   1.497 + * Binds a parameter in a prepared statement to a given integer value.
   1.498 + * 
   1.499 + * @param statement		A statement (prepared query) Handle.
   1.500 + * @param param			The parameter index (starting from 0).
   1.501 + * @param number		The number to bind.
   1.502 + * @param signed		True to bind the number as signed, false to 
   1.503 + *						bind it as unsigned.
   1.504 + * @noreturn
   1.505 + * @error				Invalid statement Handle or parameter index, or
   1.506 + *						SQL error.
   1.507 + */
   1.508 +native SQL_BindParamInt(Handle:statement, param, number, bool:signed=true);
   1.509 +
   1.510 +/**
   1.511 + * Binds a parameter in a prepared statement to a given float value.
   1.512 + * 
   1.513 + * @param statement		A statement (prepared query) Handle.
   1.514 + * @param param			The parameter index (starting from 0).
   1.515 + * @param float			The float number to bind.
   1.516 + * @noreturn
   1.517 + * @error				Invalid statement Handle or parameter index, or
   1.518 + *						SQL error.
   1.519 + */
   1.520 +native SQL_BindParamFloat(Handle:statement, param, Float:value);
   1.521 +
   1.522 +/**
   1.523 + * Binds a parameter in a prepared statement to a given string value.
   1.524 + * 
   1.525 + * @param statement		A statement (prepared query) Handle.
   1.526 + * @param param			The parameter index (starting from 0).
   1.527 + * @param value			The string to bind.
   1.528 + * @param copy			Whether or not SourceMod should copy the value
   1.529 + *						locally if necessary.  If the string contents
   1.530 + *						won't change before calling SQL_Execute(), this
   1.531 + *						can be set to false for optimization.
   1.532 + * @noreturn
   1.533 + * @error				Invalid statement Handle or parameter index, or
   1.534 + *						SQL error.
   1.535 + */
   1.536 +native SQL_BindParamString(Handle:statement, param, const String:value[], bool:copy);
   1.537 +
   1.538 +/**
   1.539 + * Executes a prepared statement.  All parameters must be bound beforehand.
   1.540 + *
   1.541 + * @param statement		A statement (prepared query) Handle.
   1.542 + * @return				True on success, false on failure.
   1.543 + * @error				Invalid statement Handle.
   1.544 + */
   1.545 +native bool:SQL_Execute(Handle:statement);
   1.546 +
   1.547 +/**
   1.548 + * Locks a database so threading operations will not interrupt.
   1.549 + * 
   1.550 + * If you are using a database Handle for both threading and non-threading,
   1.551 + * this MUST be called before doing any set of non-threading DB operations.
   1.552 + * Otherwise you risk corrupting the database driver's memory or network
   1.553 + * connection.
   1.554 + * 
   1.555 + * Leaving a lock on a database and then executing a threaded query results
   1.556 + * in a dead lock! Make sure to call SQL_UnlockDatabase()!
   1.557 + *
   1.558 + * If the lock cannot be acquired, the main thread will pause until the 
   1.559 + * threaded operation has concluded.
   1.560 + *
   1.561 + * @param database		A database Handle.
   1.562 + * @noreturn
   1.563 + * @error				Invalid database Handle.
   1.564 + */
   1.565 +native SQL_LockDatabase(Handle:database);
   1.566 +
   1.567 +/**
   1.568 + * Unlocks a database so threading operations may continue.
   1.569 + *
   1.570 + * @param database		A database Handle.
   1.571 + * @noreturn
   1.572 + * @error				Invalid database Handle.
   1.573 + */
   1.574 +native SQL_UnlockDatabase(Handle:database);
   1.575 +
   1.576 +/**
   1.577 + * General callback for threaded SQL stuff.
   1.578 + *
   1.579 + * @param db			Parent object of the Handle (or INVALID_HANDLE if none).
   1.580 + * @param hndl			Handle to the child object (or INVALID_HANDLE if none).
   1.581 + * @param error			Error string if there was an error.  The error could be 
   1.582 + *						empty even if an error condition exists, so it is important 
   1.583 + *						to check the actual Handle value instead.
   1.584 + * @param data			Data passed in via the original threaded invocation.
   1.585 + * @param 
   1.586 + */
   1.587 +functag SQLTCallback public(Handle:owner, Handle:hndl, const String:error[], any:data);
   1.588 +
   1.589 +/**
   1.590 + * Tells whether two database handles both point to the same database 
   1.591 + * connection.
   1.592 + *
   1.593 + * @param hndl1			First database Handle.
   1.594 + * @param hndl2			Second database Handle.
   1.595 + * @return				True if the Handles point to the same 
   1.596 + *						connection, false otherwise.
   1.597 + * @error				Invalid Handle.
   1.598 + */
   1.599 +native bool:SQL_IsSameConnection(Handle:hndl1, Handle:hndl2);
   1.600 +
   1.601 +/**
   1.602 + * Connects to a database via a thread.  This can be used instead of
   1.603 + * SQL_Connect() if you wish for non-blocking functionality.
   1.604 + *
   1.605 + * It is not necessary to use this to use threaded queries.  However, if you 
   1.606 + * don't (or you mix threaded/non-threaded queries), you should see 
   1.607 + * SQL_LockDatabase().
   1.608 + *
   1.609 + * @param callback		Callback; new Handle will be in hndl, owner is the driver.
   1.610 + *						If no driver was found, the owner is INVALID_HANDLE.
   1.611 + * @param name			Database name.
   1.612 + * @noreturn
   1.613 + */
   1.614 +native SQL_TConnect(SQLTCallback:callback, const String:name[]="default", any:data=0);
   1.615 +
   1.616 +/**
   1.617 + * Executes a simple query via a thread.  The query Handle is passed through
   1.618 + * the callback.
   1.619 + *
   1.620 + * The database Handle returned through the callback is always a new Handle,
   1.621 + * and if necessary, SQL_IsSameConnection() should be used to test against
   1.622 + * other conenctions.
   1.623 + *
   1.624 + * The query Handle returned through the callback is temporary and destroyed 
   1.625 + * at the end of the callback.  If you need to hold onto it, use CloneHandle().
   1.626 + *
   1.627 + * @param database		A database Handle.
   1.628 + * @param callback		Callback; database is in "owner" and the query Handle
   1.629 + *						is passed in "hndl".
   1.630 + * @param query			Query string.
   1.631 + * @param data			Extra data value to pass to the callback.
   1.632 + * @param prio			Priority queue to use.
   1.633 + * @noreturn
   1.634 + * @error				Invalid database Handle.
   1.635 + */
   1.636 +native SQL_TQuery(Handle:database, SQLTCallback:callback, const String:query[], any:data=0, DBPriority:prio=DBPrio_Normal);