From eedb308babe2cffcdf1b4b29280092115e36bdb7 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Thu, 9 Aug 2007 20:06:42 +0000 Subject: [PATCH] added amb739, SQL_ReadDriver() --HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%401300 --- core/smn_database.cpp | 19 +++++++++++++++++++ plugins/include/dbi.inc | 14 ++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/core/smn_database.cpp b/core/smn_database.cpp index 2b645173..3d5cf7a9 100644 --- a/core/smn_database.cpp +++ b/core/smn_database.cpp @@ -1236,6 +1236,24 @@ static cell_t SQL_IsSameConnection(IPluginContext *pContext, const cell_t *param return (db1 == db2) ? true : false; } +static cell_t SQL_ReadDriver(IPluginContext *pContext, const cell_t *params) +{ + IDatabase *db1=NULL; + HandleError err; + + if ((err = g_DBMan.ReadHandle(params[1], DBHandle_Database, (void **)&db1)) + != HandleError_None) + { + return pContext->ThrowNativeError("Invalid database Handle 1/%x (error: %d)", params[1], err); + } + + IDBDriver *driver = db1->GetDriver(); + + pContext->StringToLocalUTF8(params[2], params[3], driver->GetIdentifier(), NULL); + + return driver->GetHandle(); +} + REGISTER_NATIVES(dbNatives) { {"SQL_BindParamInt", SQL_BindParamInt}, @@ -1269,6 +1287,7 @@ REGISTER_NATIVES(dbNatives) {"SQL_PrepareQuery", SQL_PrepareQuery}, {"SQL_Query", SQL_Query}, {"SQL_QuoteString", SQL_QuoteString}, + {"SQL_ReadDriver", SQL_ReadDriver}, {"SQL_Rewind", SQL_Rewind}, {"SQL_TConnect", SQL_TConnect}, {"SQL_TQuery", SQL_TQuery}, diff --git a/plugins/include/dbi.inc b/plugins/include/dbi.inc index 8b8610a9..791b8c41 100644 --- a/plugins/include/dbi.inc +++ b/plugins/include/dbi.inc @@ -144,9 +144,21 @@ native Handle:SQL_ConnectEx(Handle:driver, */ native Handle:SQL_GetDriver(const String:name[]=""); +/** + * Reads the driver of an opened database. + * + * @param database Database Handle. + * @param ident Option buffer to store the identification string. + * @param ident_length Maximum length of the buffer. + * @return Driver Handle. + */ +native Handle:SQL_ReadDriver(Handle:database, String:ident[]="", ident_length=0); + /** * Retrieves a driver's identification string. * + * Example: "mysql", "sqlite" + * * @param driver Driver Handle, or INVALID_HANDLE for the default driver. * @param ident Identification string buffer. * @param maxlength Maximum length of the buffer. @@ -158,6 +170,8 @@ native SQL_GetDriverIdent(Handle:driver, String:ident[], maxlength); /** * Retrieves a driver's product string. * + * Example: "MySQL", "SQLite" + * * @param driver Driver Handle, or INVALID_HANDLE for the default driver. * @param product Product string buffer. * @param maxlength Maximum length of the buffer.