From d8a0a1c93086eafca299df69e0dab7b2c48575c2 Mon Sep 17 00:00:00 2001 From: George Tasker Date: Wed, 22 Nov 2000 00:19:25 +0000 Subject: [PATCH] Fixed problems with the wxDb::Open(wxDb *copyDb) not copying in all the different data types required values Added Interbase database support based on contributions from Roger Gammans Enabled the wxDb::TablePrivileges() function for v2.3/2.4 Fixed a bunch of problems with wxDb::TablePrivileges() not working correctly with all databases. Added the ability to pass in a SCHEMA to wxDbTablePrivileges() that greatly improves the speed of the privileges lookup. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@8768 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/db.h | 5 +- src/common/db.cpp | 116 ++++++++++++++++++++++++++++++---------------- 2 files changed, 80 insertions(+), 41 deletions(-) diff --git a/include/wx/db.h b/include/wx/db.h index 0db9c05184..1c6790cf01 100644 --- a/include/wx/db.h +++ b/include/wx/db.h @@ -376,7 +376,8 @@ enum wxDBMS dbmsDBASE, dbmsINFORMIX, dbmsVIRTUOSO, - dbmsDB2 + dbmsDB2, + dbmsINTERBASE }; @@ -545,7 +546,7 @@ public: wxDbSqlTypeInfo GetTypeInfDate() {return typeInfDate;} bool TableExists(const char *tableName, const char *userID=NULL, const char *path=NULL); // Table name can refer to a table, view, alias or synonym - bool TablePrivileges(const char *tableName, const char* priv, const char *userID=NULL, const char *path=""); // Table name can refer to a table, view, alias or synonym + bool TablePrivileges(const char *tableName, const char* priv, const char *schema=NULL, const char *userID=NULL, const char *path=""); // Table name can refer to a table, view, alias or synonym void LogError(const char *errMsg, const char *SQLState = 0) {logError(errMsg, SQLState);} void SetDebugErrorMessages(bool state) { silent = !state; } bool SetSqlLogging(wxDbSqlLogState state, const wxChar *filename = SQL_LOG_FILENAME, bool append = FALSE); diff --git a/src/common/db.cpp b/src/common/db.cpp index 9866c70aa0..994be49bb4 100644 --- a/src/common/db.cpp +++ b/src/common/db.cpp @@ -646,15 +646,31 @@ bool wxDb::Open(wxDb *copyDb) // VARCHAR = Variable length character string typeInfVarchar.FsqlType = copyDb->typeInfVarchar.FsqlType; + wxStrcpy(typeInfVarchar.TypeName, copyDb->typeInfVarchar.TypeName); + typeInfVarchar.Precision = copyDb->typeInfVarchar.Precision; + typeInfVarchar.CaseSensitive = copyDb->typeInfVarchar.CaseSensitive; + typeInfVarchar.MaximumScale = copyDb->typeInfVarchar.MaximumScale; // Float typeInfFloat.FsqlType = copyDb->typeInfFloat.FsqlType; + wxStrcpy(typeInfFloat.TypeName, copyDb->typeInfFloat.TypeName); + typeInfFloat.Precision = copyDb->typeInfFloat.Precision; + typeInfFloat.CaseSensitive = copyDb->typeInfFloat.CaseSensitive; + typeInfFloat.MaximumScale = copyDb->typeInfFloat.MaximumScale; // Integer - typeInfFloat.FsqlType = copyDb->typeInfFloat.FsqlType; + typeInfInteger.FsqlType = copyDb->typeInfInteger.FsqlType; + wxStrcpy(typeInfInteger.TypeName, copyDb->typeInfInteger.TypeName); + typeInfInteger.Precision = copyDb->typeInfInteger.Precision; + typeInfInteger.CaseSensitive = copyDb->typeInfInteger.CaseSensitive; + typeInfInteger.MaximumScale = copyDb->typeInfInteger.MaximumScale; // Date/Time typeInfDate.FsqlType = copyDb->typeInfDate.FsqlType; + wxStrcpy(typeInfDate.TypeName, copyDb->typeInfDate.TypeName); + typeInfDate.Precision = copyDb->typeInfDate.Precision; + typeInfDate.CaseSensitive = copyDb->typeInfDate.CaseSensitive; + typeInfDate.MaximumScale = copyDb->typeInfDate.MaximumScale; #ifdef DBDEBUG_CONSOLE cout << "VARCHAR DATA TYPE: " << typeInfVarchar.TypeName << endl; @@ -1873,7 +1889,7 @@ wxDbColInf *wxDb::GetColumns(char *tableName[], const char *userID) if (Dbms() == dbmsDBASE) UserID = ""; - // Oracle user names may only be in uppercase, so force + // Oracle and Interbase user names may only be in uppercase, so force // the name to uppercase if (Dbms() == dbmsORACLE) UserID = UserID.Upper(); @@ -1902,9 +1918,10 @@ wxDbColInf *wxDb::GetColumns(char *tableName[], const char *userID) for (tbl = 0; tableName[tbl]; tbl++) { TableName = tableName[tbl]; - // Oracle table names are uppercase only, so force + // Oracle and Interbase table names are uppercase only, so force // the name to uppercase just in case programmer forgot to do this - if (Dbms() == dbmsORACLE) + if ((Dbms() == dbmsORACLE) || + (Dbms() == dbmsINTERBASE)) TableName = TableName.Upper(); SQLFreeStmt(hstmt, SQL_CLOSE); @@ -2072,9 +2089,10 @@ wxDbColInf *wxDb::GetColumns(char *tableName, int *numCols, const char *userID) } TableName = tableName; - // Oracle table names are uppercase only, so force + // Oracle and Interbase table names are uppercase only, so force // the name to uppercase just in case programmer forgot to do this - if (Dbms() == dbmsORACLE) + if ((Dbms() == dbmsORACLE) || + (Dbms() == dbmsINTERBASE)) TableName = TableName.Upper(); SQLFreeStmt(hstmt, SQL_CLOSE); @@ -2341,9 +2359,10 @@ wxDbColInf *wxDb::GetColumns(char *tableName, int *numCols, const char *userID) } TableName = tableName; - // Oracle table names are uppercase only, so force + // Oracle and Interbase table names are uppercase only, so force // the name to uppercase just in case programmer forgot to do this - if (Dbms() == dbmsORACLE) + if ((Dbms() == dbmsORACLE) || + (Dbms() == dbmsINTERBASE)) TableName = TableName.Upper(); SQLFreeStmt(hstmt, SQL_CLOSE); @@ -2595,9 +2614,10 @@ int wxDb::GetColumnCount(char *tableName, const char *userID) // Loop through each table name { TableName = tableName; - // Oracle table names are uppercase only, so force + // Oracle and Interbase table names are uppercase only, so force // the name to uppercase just in case programmer forgot to do this - if (Dbms() == dbmsORACLE) + if ((Dbms() == dbmsORACLE) || + (Dbms() == dbmsINTERBASE)) TableName = TableName.Upper(); SQLFreeStmt(hstmt, SQL_CLOSE); @@ -2964,9 +2984,10 @@ bool wxDb::TableExists(const char *tableName, const char *userID, const char *ta UserID = UserID.Upper(); TableName = tableName; - // Oracle table names are uppercase only, so force + // Oracle and Interbase table names are uppercase only, so force // the name to uppercase just in case programmer forgot to do this - if (Dbms() == dbmsORACLE) + if ((Dbms() == dbmsORACLE) || + (Dbms() == dbmsINTERBASE)) TableName = TableName.Upper(); SQLFreeStmt(hstmt, SQL_CLOSE); @@ -3011,8 +3032,8 @@ bool wxDb::TableExists(const char *tableName, const char *userID, const char *ta /********** wxDb::TablePrivileges() **********/ -bool wxDb::TablePrivileges(const char *tableName, const char* priv, - const char *userID, const char *tablePath) +bool wxDb::TablePrivileges(const char *tableName, const char* priv, const char *schema, + const char *userID, const char *tablePath) { wxDbTablePrivilegeInfo result; SDWORD cbRetVal; @@ -3044,17 +3065,28 @@ bool wxDb::TablePrivileges(const char *tableName, const char* priv, UserID = UserID.Upper(); TableName = tableName; - // Oracle table names are uppercase only, so force + // Oracle and Interbase table names are uppercase only, so force // the name to uppercase just in case programmer forgot to do this - if (Dbms() == dbmsORACLE) + if ((Dbms() == dbmsORACLE) || + (Dbms() == dbmsINTERBASE)) TableName = TableName.Upper(); SQLFreeStmt(hstmt, SQL_CLOSE); - - retcode = SQLTablePrivileges(hstmt, - NULL, 0, // Catalog - NULL, 0, // Schema - (UCHAR FAR *)TableName.GetData(), SQL_NTS); + + if (!schema) + { + retcode = SQLTablePrivileges(hstmt, + NULL, 0, // Catalog + NULL, 0, // Schema + (UCHAR FAR *)TableName.c_str(), SQL_NTS); + } + else + { + retcode = SQLTablePrivileges(hstmt, + NULL, 0, // Catalog + (UCHAR FAR *)schema, SQL_NTS, // Schema + (UCHAR FAR *)TableName.c_str(), SQL_NTS); + } #ifdef DBDEBUG_CONSOLE fprintf(stderr ,"SQLTablePrivileges() returned %i \n",retcode); @@ -3063,35 +3095,36 @@ bool wxDb::TablePrivileges(const char *tableName, const char* priv, if ((retcode != SQL_SUCCESS) && (retcode != SQL_SUCCESS_WITH_INFO)) return(DispAllErrors(henv, hdbc, hstmt)); - if (SQLGetData(hstmt, 1, SQL_C_CHAR, (UCHAR*) result.tableQual, 128, &cbRetVal) != SQL_SUCCESS) - return(DispAllErrors(henv, hdbc, hstmt)); - - if (SQLGetData(hstmt, 2, SQL_C_CHAR, (UCHAR*) result.tableOwner, 128, &cbRetVal) != SQL_SUCCESS) - return(DispAllErrors(henv, hdbc, hstmt)); + retcode = SQLFetch(hstmt); + while (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO) + { + if (SQLGetData(hstmt, 1, SQL_C_CHAR, (UCHAR*) result.tableQual, sizeof(result.tableQual), &cbRetVal) != SQL_SUCCESS) + return(DispAllErrors(henv, hdbc, hstmt)); - if (SQLGetData(hstmt, 3, SQL_C_CHAR, (UCHAR*) result.tableName, 128, &cbRetVal) != SQL_SUCCESS) - return(DispAllErrors(henv, hdbc, hstmt)); + if (SQLGetData(hstmt, 2, SQL_C_CHAR, (UCHAR*) result.tableOwner, sizeof(result.tableOwner), &cbRetVal) != SQL_SUCCESS) + return(DispAllErrors(henv, hdbc, hstmt)); - if (SQLGetData(hstmt, 4, SQL_C_CHAR, (UCHAR*) result.grantor, 128, &cbRetVal) != SQL_SUCCESS) - return(DispAllErrors(henv, hdbc, hstmt)); + if (SQLGetData(hstmt, 3, SQL_C_CHAR, (UCHAR*) result.tableName, sizeof(result.tableName), &cbRetVal) != SQL_SUCCESS) + return(DispAllErrors(henv, hdbc, hstmt)); - if (SQLGetData(hstmt, 5, SQL_C_CHAR, (UCHAR*) result.grantee, 128, &cbRetVal) != SQL_SUCCESS) - return(DispAllErrors(henv, hdbc, hstmt)); + if (SQLGetData(hstmt, 4, SQL_C_CHAR, (UCHAR*) result.grantor, sizeof(result.grantor), &cbRetVal) != SQL_SUCCESS) + return(DispAllErrors(henv, hdbc, hstmt)); - if (SQLGetData(hstmt, 6, SQL_C_CHAR, (UCHAR*) result.privilege, 128, &cbRetVal) != SQL_SUCCESS) - return(DispAllErrors(henv, hdbc, hstmt)); + if (SQLGetData(hstmt, 5, SQL_C_CHAR, (UCHAR*) result.grantee, sizeof(result.grantee), &cbRetVal) != SQL_SUCCESS) + return(DispAllErrors(henv, hdbc, hstmt)); - if (SQLGetData(hstmt, 7, SQL_C_CHAR, (UCHAR*) result.grantable, 3, &cbRetVal) != SQL_SUCCESS) - return(DispAllErrors(henv, hdbc, hstmt)); + if (SQLGetData(hstmt, 6, SQL_C_CHAR, (UCHAR*) result.privilege, sizeof(result.privilege), &cbRetVal) != SQL_SUCCESS) + return(DispAllErrors(henv, hdbc, hstmt)); - retcode = SQLFetch(hstmt); - while (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO) - { + if (SQLGetData(hstmt, 7, SQL_C_CHAR, (UCHAR*) result.grantable, sizeof(result.grantable), &cbRetVal) != SQL_SUCCESS) + return(DispAllErrors(henv, hdbc, hstmt)); + #ifdef DBDEBUG_CONSOLE fprintf(stderr,"Scanning %s privilege on table %s.%s granted by %s to %s\n", result.privilege,result.tableOwner,result.tableName, result.grantor, result.grantee); #endif + if (UserID.IsSameAs(result.tableOwner,false)) { SQLFreeStmt(hstmt, SQL_CLOSE); @@ -3233,6 +3266,11 @@ wxDBMS wxDb::Dbms(void) wxStrncpy(baseName,dbInf.dbmsName,25); baseName[25] = 0; + // RGG 20001025 : add support for Interbase + // GT : Integrated to base classes on 20001121 + if (!wxStricmp(dbInf.dbmsName,"Interbase")) + return((wxDBMS)(dbmsType = dbmsINTERBASE)); + // BJO 20000428 : add support for Virtuoso if (!wxStricmp(dbInf.dbmsName,"OpenLink Virtuoso VDBMS")) return((wxDBMS)(dbmsType = dbmsVIRTUOSO)); -- 2.45.2