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
This commit is contained in:
@@ -376,7 +376,8 @@ enum wxDBMS
|
|||||||
dbmsDBASE,
|
dbmsDBASE,
|
||||||
dbmsINFORMIX,
|
dbmsINFORMIX,
|
||||||
dbmsVIRTUOSO,
|
dbmsVIRTUOSO,
|
||||||
dbmsDB2
|
dbmsDB2,
|
||||||
|
dbmsINTERBASE
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -545,7 +546,7 @@ public:
|
|||||||
wxDbSqlTypeInfo GetTypeInfDate() {return typeInfDate;}
|
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 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 LogError(const char *errMsg, const char *SQLState = 0) {logError(errMsg, SQLState);}
|
||||||
void SetDebugErrorMessages(bool state) { silent = !state; }
|
void SetDebugErrorMessages(bool state) { silent = !state; }
|
||||||
bool SetSqlLogging(wxDbSqlLogState state, const wxChar *filename = SQL_LOG_FILENAME, bool append = FALSE);
|
bool SetSqlLogging(wxDbSqlLogState state, const wxChar *filename = SQL_LOG_FILENAME, bool append = FALSE);
|
||||||
|
@@ -646,15 +646,31 @@ bool wxDb::Open(wxDb *copyDb)
|
|||||||
|
|
||||||
// VARCHAR = Variable length character string
|
// VARCHAR = Variable length character string
|
||||||
typeInfVarchar.FsqlType = copyDb->typeInfVarchar.FsqlType;
|
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
|
// Float
|
||||||
typeInfFloat.FsqlType = copyDb->typeInfFloat.FsqlType;
|
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
|
// 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
|
// Date/Time
|
||||||
typeInfDate.FsqlType = copyDb->typeInfDate.FsqlType;
|
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
|
#ifdef DBDEBUG_CONSOLE
|
||||||
cout << "VARCHAR DATA TYPE: " << typeInfVarchar.TypeName << endl;
|
cout << "VARCHAR DATA TYPE: " << typeInfVarchar.TypeName << endl;
|
||||||
@@ -1873,7 +1889,7 @@ wxDbColInf *wxDb::GetColumns(char *tableName[], const char *userID)
|
|||||||
if (Dbms() == dbmsDBASE)
|
if (Dbms() == dbmsDBASE)
|
||||||
UserID = "";
|
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
|
// the name to uppercase
|
||||||
if (Dbms() == dbmsORACLE)
|
if (Dbms() == dbmsORACLE)
|
||||||
UserID = UserID.Upper();
|
UserID = UserID.Upper();
|
||||||
@@ -1902,9 +1918,10 @@ wxDbColInf *wxDb::GetColumns(char *tableName[], const char *userID)
|
|||||||
for (tbl = 0; tableName[tbl]; tbl++)
|
for (tbl = 0; tableName[tbl]; tbl++)
|
||||||
{
|
{
|
||||||
TableName = tableName[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
|
// the name to uppercase just in case programmer forgot to do this
|
||||||
if (Dbms() == dbmsORACLE)
|
if ((Dbms() == dbmsORACLE) ||
|
||||||
|
(Dbms() == dbmsINTERBASE))
|
||||||
TableName = TableName.Upper();
|
TableName = TableName.Upper();
|
||||||
|
|
||||||
SQLFreeStmt(hstmt, SQL_CLOSE);
|
SQLFreeStmt(hstmt, SQL_CLOSE);
|
||||||
@@ -2072,9 +2089,10 @@ wxDbColInf *wxDb::GetColumns(char *tableName, int *numCols, const char *userID)
|
|||||||
}
|
}
|
||||||
|
|
||||||
TableName = tableName;
|
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
|
// the name to uppercase just in case programmer forgot to do this
|
||||||
if (Dbms() == dbmsORACLE)
|
if ((Dbms() == dbmsORACLE) ||
|
||||||
|
(Dbms() == dbmsINTERBASE))
|
||||||
TableName = TableName.Upper();
|
TableName = TableName.Upper();
|
||||||
|
|
||||||
SQLFreeStmt(hstmt, SQL_CLOSE);
|
SQLFreeStmt(hstmt, SQL_CLOSE);
|
||||||
@@ -2341,9 +2359,10 @@ wxDbColInf *wxDb::GetColumns(char *tableName, int *numCols, const char *userID)
|
|||||||
}
|
}
|
||||||
|
|
||||||
TableName = tableName;
|
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
|
// the name to uppercase just in case programmer forgot to do this
|
||||||
if (Dbms() == dbmsORACLE)
|
if ((Dbms() == dbmsORACLE) ||
|
||||||
|
(Dbms() == dbmsINTERBASE))
|
||||||
TableName = TableName.Upper();
|
TableName = TableName.Upper();
|
||||||
|
|
||||||
SQLFreeStmt(hstmt, SQL_CLOSE);
|
SQLFreeStmt(hstmt, SQL_CLOSE);
|
||||||
@@ -2595,9 +2614,10 @@ int wxDb::GetColumnCount(char *tableName, const char *userID)
|
|||||||
// Loop through each table name
|
// Loop through each table name
|
||||||
{
|
{
|
||||||
TableName = tableName;
|
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
|
// the name to uppercase just in case programmer forgot to do this
|
||||||
if (Dbms() == dbmsORACLE)
|
if ((Dbms() == dbmsORACLE) ||
|
||||||
|
(Dbms() == dbmsINTERBASE))
|
||||||
TableName = TableName.Upper();
|
TableName = TableName.Upper();
|
||||||
|
|
||||||
SQLFreeStmt(hstmt, SQL_CLOSE);
|
SQLFreeStmt(hstmt, SQL_CLOSE);
|
||||||
@@ -2964,9 +2984,10 @@ bool wxDb::TableExists(const char *tableName, const char *userID, const char *ta
|
|||||||
UserID = UserID.Upper();
|
UserID = UserID.Upper();
|
||||||
|
|
||||||
TableName = tableName;
|
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
|
// the name to uppercase just in case programmer forgot to do this
|
||||||
if (Dbms() == dbmsORACLE)
|
if ((Dbms() == dbmsORACLE) ||
|
||||||
|
(Dbms() == dbmsINTERBASE))
|
||||||
TableName = TableName.Upper();
|
TableName = TableName.Upper();
|
||||||
|
|
||||||
SQLFreeStmt(hstmt, SQL_CLOSE);
|
SQLFreeStmt(hstmt, SQL_CLOSE);
|
||||||
@@ -3011,8 +3032,8 @@ bool wxDb::TableExists(const char *tableName, const char *userID, const char *ta
|
|||||||
|
|
||||||
|
|
||||||
/********** wxDb::TablePrivileges() **********/
|
/********** wxDb::TablePrivileges() **********/
|
||||||
bool wxDb::TablePrivileges(const char *tableName, const char* priv,
|
bool wxDb::TablePrivileges(const char *tableName, const char* priv, const char *schema,
|
||||||
const char *userID, const char *tablePath)
|
const char *userID, const char *tablePath)
|
||||||
{
|
{
|
||||||
wxDbTablePrivilegeInfo result;
|
wxDbTablePrivilegeInfo result;
|
||||||
SDWORD cbRetVal;
|
SDWORD cbRetVal;
|
||||||
@@ -3044,17 +3065,28 @@ bool wxDb::TablePrivileges(const char *tableName, const char* priv,
|
|||||||
UserID = UserID.Upper();
|
UserID = UserID.Upper();
|
||||||
|
|
||||||
TableName = tableName;
|
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
|
// the name to uppercase just in case programmer forgot to do this
|
||||||
if (Dbms() == dbmsORACLE)
|
if ((Dbms() == dbmsORACLE) ||
|
||||||
|
(Dbms() == dbmsINTERBASE))
|
||||||
TableName = TableName.Upper();
|
TableName = TableName.Upper();
|
||||||
|
|
||||||
SQLFreeStmt(hstmt, SQL_CLOSE);
|
SQLFreeStmt(hstmt, SQL_CLOSE);
|
||||||
|
|
||||||
retcode = SQLTablePrivileges(hstmt,
|
if (!schema)
|
||||||
NULL, 0, // Catalog
|
{
|
||||||
NULL, 0, // Schema
|
retcode = SQLTablePrivileges(hstmt,
|
||||||
(UCHAR FAR *)TableName.GetData(), SQL_NTS);
|
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
|
#ifdef DBDEBUG_CONSOLE
|
||||||
fprintf(stderr ,"SQLTablePrivileges() returned %i \n",retcode);
|
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))
|
if ((retcode != SQL_SUCCESS) && (retcode != SQL_SUCCESS_WITH_INFO))
|
||||||
return(DispAllErrors(henv, hdbc, hstmt));
|
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));
|
|
||||||
|
|
||||||
if (SQLGetData(hstmt, 3, SQL_C_CHAR, (UCHAR*) result.tableName, 128, &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, 5, SQL_C_CHAR, (UCHAR*) result.grantee, 128, &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, 7, SQL_C_CHAR, (UCHAR*) result.grantable, 3, &cbRetVal) != SQL_SUCCESS)
|
|
||||||
return(DispAllErrors(henv, hdbc, hstmt));
|
|
||||||
|
|
||||||
retcode = SQLFetch(hstmt);
|
retcode = SQLFetch(hstmt);
|
||||||
while (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
|
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, 2, SQL_C_CHAR, (UCHAR*) result.tableOwner, sizeof(result.tableOwner), &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, 4, SQL_C_CHAR, (UCHAR*) result.grantor, sizeof(result.grantor), &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, 6, SQL_C_CHAR, (UCHAR*) result.privilege, sizeof(result.privilege), &cbRetVal) != SQL_SUCCESS)
|
||||||
|
return(DispAllErrors(henv, hdbc, hstmt));
|
||||||
|
|
||||||
|
if (SQLGetData(hstmt, 7, SQL_C_CHAR, (UCHAR*) result.grantable, sizeof(result.grantable), &cbRetVal) != SQL_SUCCESS)
|
||||||
|
return(DispAllErrors(henv, hdbc, hstmt));
|
||||||
|
|
||||||
#ifdef DBDEBUG_CONSOLE
|
#ifdef DBDEBUG_CONSOLE
|
||||||
fprintf(stderr,"Scanning %s privilege on table %s.%s granted by %s to %s\n",
|
fprintf(stderr,"Scanning %s privilege on table %s.%s granted by %s to %s\n",
|
||||||
result.privilege,result.tableOwner,result.tableName,
|
result.privilege,result.tableOwner,result.tableName,
|
||||||
result.grantor, result.grantee);
|
result.grantor, result.grantee);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (UserID.IsSameAs(result.tableOwner,false))
|
if (UserID.IsSameAs(result.tableOwner,false))
|
||||||
{
|
{
|
||||||
SQLFreeStmt(hstmt, SQL_CLOSE);
|
SQLFreeStmt(hstmt, SQL_CLOSE);
|
||||||
@@ -3233,6 +3266,11 @@ wxDBMS wxDb::Dbms(void)
|
|||||||
wxStrncpy(baseName,dbInf.dbmsName,25);
|
wxStrncpy(baseName,dbInf.dbmsName,25);
|
||||||
baseName[25] = 0;
|
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
|
// BJO 20000428 : add support for Virtuoso
|
||||||
if (!wxStricmp(dbInf.dbmsName,"OpenLink Virtuoso VDBMS"))
|
if (!wxStricmp(dbInf.dbmsName,"OpenLink Virtuoso VDBMS"))
|
||||||
return((wxDBMS)(dbmsType = dbmsVIRTUOSO));
|
return((wxDBMS)(dbmsType = dbmsVIRTUOSO));
|
||||||
|
Reference in New Issue
Block a user