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