1.1 --- a/plugins/include/dbi.inc Thu Oct 09 20:19:22 2008 +1300
1.2 +++ b/plugins/include/dbi.inc Mon Oct 13 01:13:39 2008 -0500
1.3 @@ -115,6 +115,7 @@
1.4 * @param persistent True to re-use a previous persistent connection
1.5 * if possible, false otherwise.
1.6 * @return A database connection Handle, or INVALID_HANDLE on failure.
1.7 + * On failure the error buffer will be filled with a message.
1.8 */
1.9 stock Handle:SQL_DefConnect(String:error[], maxlength, bool:persistent=true)
1.10 {
1.11 @@ -122,22 +123,66 @@
1.12 }
1.13
1.14 /**
1.15 - * Creates an SQL connection from specific parameters.
1.16 + * Connects to a database using key value pairs containing the database info.
1.17 + * The key/value pairs should match what would be in databases.cfg.
1.18 *
1.19 - * @param driver Driver Handle, or INVALID_HANDLE for default.
1.20 - * @param host Host name.
1.21 - * @param user User name.
1.22 - * @param pass User password.
1.23 - * @param database Database name.
1.24 + * I.e. "driver" should be "default" or a driver name (or ommitted for
1.25 + * the default). For SQLite, only the "database" parameter is needed in addition.
1.26 + * For drivers which require external connections, more of the parameters may be
1.27 + * needed.
1.28 + *
1.29 + * In general it is discouraged to use this function. Connections should go through
1.30 + * databases.cfg for greatest flexibility on behalf of users.
1.31 + *
1.32 + * @param keyvalues Key/value pairs from a KeyValues handle, describing the connection.
1.33 * @param error Error buffer.
1.34 * @param maxlength Maximum length of the error buffer.
1.35 - * @param persistent True to re-use a previous persistent connection
1.36 - * if possible, false otherwise.
1.37 - * @param port Optional port to specify.
1.38 - * @param maxTimeout Maximum timeout in seconds if applicable.
1.39 + * @return A database connection Handle, or INVALID_HANDLE on failure.
1.40 + * On failure the error buffer will be filled with a message.
1.41 + * @error Invalid KeyValues handle.
1.42 + */
1.43 +native Handle:SQL_ConnectCustom(Handle:keyvalues,
1.44 + String:error[],
1.45 + maxlength,
1.46 + bool:persistent);
1.47 +
1.48 +/**
1.49 + * Grabs a handle to an SQLite database, creating one if it does not exist.
1.50 + *
1.51 + * Unless there are extenuating circumstances, you should consider using "sourcemod-local" as the
1.52 + * database name. This gives provides some unification between plugins on behalf of users.
1.53 + *
1.54 + * As a precaution, you should always create some sort of unique prefix to your table names so
1.55 + * there are no conflicts, and you should never drop or modify tables that you do not own.
1.56 + *
1.57 + * @param database Database name.
1.58 + * @param error Error buffer.
1.59 + * @param maxlength Maximum length of the error buffer.
1.60 + * @param persistent Persistent or not.
1.61 * @return A database connection Handle, or INVALID_HANDLE on failure.
1.62 - * @error Invalid driver Handle other than INVALID_HANDLE.
1.63 + * On failure the error buffer will be filled with a message.
1.64 */
1.65 +stock Handle:SQLite_UseDatabase(const String:database[],
1.66 + String:buffer[],
1.67 + maxlength)
1.68 +{
1.69 + new Handle:kv, Handle:db;
1.70 +
1.71 + kv = CreateKeyValues("");
1.72 + KvSetString(kv, "driver", "sqlite");
1.73 + KvSetString(kv, "database", database);
1.74 +
1.75 + db = SQL_ConnectCustom(kv, buffer, maxlength, false);
1.76 +
1.77 + CloseHandle(kv);
1.78 +
1.79 + return db;
1.80 +}
1.81 +
1.82 +/**
1.83 + * This function is deprecated. Use SQL_ConnectCustom or SQLite_UseDatabase instead.
1.84 + */
1.85 +#pragma deprecated Use SQL_ConnectCustom instead.
1.86 native Handle:SQL_ConnectEx(Handle:driver,
1.87 const String:host[],
1.88 const String:user[],