X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/2f74ed285965eaf401a4060507b5c80166dfc0f5..399b60a0ad232265cd74ce8bf6a53a1f2cc57ff2:/src/common/db.cpp diff --git a/src/common/db.cpp b/src/common/db.cpp index 7e0f753143..12f614d4c5 100644 --- a/src/common/db.cpp +++ b/src/common/db.cpp @@ -47,7 +47,7 @@ #endif #ifdef DBDEBUG_CONSOLE - #include + #include "wx/ioswrap.h" #endif #ifdef __BORLANDC__ @@ -61,6 +61,7 @@ #include "wx/list.h" #include "wx/utils.h" #include "wx/msgdlg.h" + #include "wx/log.h" #endif #include "wx/filefn.h" #include "wx/wxchar.h" @@ -547,9 +548,6 @@ bool wxDB::getDbInfo(void) if (SQLGetInfo(hdbc, SQL_PROCEDURES, (UCHAR*) dbInf.procedureSupport, 2, &cb) != SQL_SUCCESS) return(DispAllErrors(henv, hdbc)); - if (SQLGetInfo(hdbc, SQL_ACCESSIBLE_TABLES, (UCHAR*) dbInf.accessibleTables, 2, &cb) != SQL_SUCCESS) - return(DispAllErrors(henv, hdbc)); - if (SQLGetInfo(hdbc, SQL_CURSOR_COMMIT_BEHAVIOR, (UCHAR*) &dbInf.cursorCommitBehavior, sizeof(dbInf.cursorCommitBehavior), &cb) != SQL_SUCCESS) return(DispAllErrors(henv, hdbc)); @@ -630,7 +628,6 @@ bool wxDB::getDbInfo(void) cout << "Max. Connections: " << dbInf.maxConnections << endl; cout << "Outer Joins: " << dbInf.outerJoins << endl; cout << "Support for Procedures: " << dbInf.procedureSupport << endl; - cout << "All tables accessible : " << dbInf.accessibleTables << endl; cout << "Cursor COMMIT Behavior: "; switch(dbInf.cursorCommitBehavior) @@ -901,7 +898,7 @@ void wxDB::Close(void) { s.sprintf("(%-20s) tableID:[%6lu] pDb:[%p]", tiu->tableName,tiu->tableID,tiu->pDb); s2.sprintf("Orphaned found using pDb:[%p]",this); - wxMessageBox (s,s2); + wxLogDebug (s.c_str(),s2.c_str()); } pNode = pNode->Next(); } @@ -965,7 +962,7 @@ bool wxDB::DispAllErrors(HENV aHenv, HDBC aHdbc, HSTMT aHstmt) } #ifdef __WXDEBUG__ - wxMessageBox(odbcErrMsg.GetData(),"DEBUG MESSAGE from DispAllErrors()"); + wxLogDebug(odbcErrMsg.GetData(),"DEBUG MESSAGE from DispAllErrors()"); #endif } @@ -1563,6 +1560,9 @@ wxColInf *wxDB::GetColumns(char *tableName[], const char *userID) * userID == "" ... UserID set equal to 'this->uid' * userID != "" ... UserID set equal to 'userID' * + * NOTE: ALL column bindings associated with this wxDB instance are unbound + * by this function. This function should use its own wxDB instance + * to avoid undesired unbinding of columns. */ { int noCols = 0; @@ -1674,12 +1674,20 @@ wxColInf *wxDB::GetColumns(char *tableName[], const char *userID) GetData( 9, SQL_C_SSHORT, (UCHAR*) &colInf[colNo].decimalDigits,0, &cb); GetData(10, SQL_C_SSHORT, (UCHAR*) &colInf[colNo].numPrecRadix, 0, &cb); GetData(11, SQL_C_SSHORT, (UCHAR*) &colInf[colNo].nullable, 0, &cb); - GetData(12, SQL_C_CHAR, (UCHAR*) colInf[colNo].remarks, 254+1, &cb); + GetData(12, SQL_C_CHAR, (UCHAR*) colInf[colNo].remarks, 254+1, &cb); // Determine the wxDB data type that is used to represent the native data type of this data source colInf[colNo].dbDataType = 0; if (!wxStricmp(typeInfVarchar.TypeName,colInf[colNo].typeName)) + { + if (colInf[colNo].columnSize < 1) + { + // IODBC does not return a correct columnSize, so we set + // columnSize = bufferLength if no column size was returned + colInf[colNo].columnSize = colInf[colNo].bufferLength; + } colInf[colNo].dbDataType = DB_DATA_TYPE_VARCHAR; + } else if (!wxStricmp(typeInfInteger.TypeName,colInf[colNo].typeName)) colInf[colNo].dbDataType = DB_DATA_TYPE_INTEGER; else if (!wxStricmp(typeInfFloat.TypeName,colInf[colNo].typeName)) @@ -1844,7 +1852,15 @@ wxColInf *wxDB::GetColumns(char *tableName, int *numCols, const char *userID) // Determine the wxDB data type that is used to represent the native data type of this data source colInf[colNo].dbDataType = 0; if (!wxStricmp(typeInfVarchar.TypeName,colInf[colNo].typeName)) + { + if (colInf[colNo].columnSize < 1) + { + // IODBC does not return a correct columnSize, so we set + // columnSize = bufferLength if no column size was returned + colInf[colNo].columnSize = colInf[colNo].bufferLength; + } colInf[colNo].dbDataType = DB_DATA_TYPE_VARCHAR; + } else if (!wxStricmp(typeInfInteger.TypeName,colInf[colNo].typeName)) colInf[colNo].dbDataType = DB_DATA_TYPE_INTEGER; else if (!wxStricmp(typeInfFloat.TypeName,colInf[colNo].typeName)) @@ -2346,135 +2362,33 @@ bool wxDB::TableExists(const char *tableName, const char *userID, const char *ta } // wxDB::TableExists() - -/********** wxDB::TablePrivileges() **********/ -bool wxDB::TablePrivileges(const char* privilege, const char *tableName, - const char *userID, const char *tablePath) -{ - SqlPrivilegesInfo result; - SDWORD cbRetVal; - RETCODE retcode; - - //We probably need to be able to dynamically set this based on - //the driver type, and state. - roger gammans - char curRole[]="public"; - - wxString UserID; - wxString TableName; - - assert(tableName && wxStrlen(tableName)); - - if (userID) - { - if (!wxStrlen(userID)) - UserID = uid; - else - UserID = userID; - } - else - UserID = ""; - - // Oracle user names may only be in uppercase, so force - // the name to uppercase - // if (Dbms() == dbmsORACLE) - // UserID = UserID.Upper(); - // - // However we fors case-insentive compare so it shouldn't matter. - - - TableName = tableName; - // Oracle table names are uppercase only, so force - // the name to uppercase just in case programmer forgot to do this - if (Dbms() == dbmsORACLE) - TableName = TableName.Upper(); - - SQLFreeStmt(hstmt, SQL_CLOSE); - - retcode = SQLTablePrivileges(hstmt, - NULL, 0, // All qualifiers - NULL, 0, // All owners - (UCHAR FAR *)TableName.GetData(), SQL_NTS); - -#ifdef DBDEBUG_CONSOLE - fprintf(stderr ,"SQLTablePrivileges() returned %i \n",retcode); -#endif -/* - retcode = SQLBindCol (hstmt, 1, SQL_C_CHAR, &result.TableQualifier, 128, &cbRetVal); - retcode = SQLBindCol (hstmt, 2, SQL_C_CHAR, &result.TableOwner, 128, &cbRetVal); - retcode = SQLBindCol (hstmt, 3, SQL_C_CHAR, &result.TableName, 128, &cbRetVal); - retcode = SQLBindCol (hstmt, 4, SQL_C_CHAR, &result.Grantor, 128, &cbRetVal); - retcode = SQLBindCol (hstmt, 5, SQL_C_CHAR, &result.Grantee, 128, &cbRetVal); - retcode = SQLBindCol (hstmt, 6, SQL_C_CHAR, &result.Privilege, 128, &cbRetVal); - retcode = SQLBindCol (hstmt, 7, SQL_C_CHAR, &result.Grantable, 3, &cbRetVal); -*/ - retcode = SQLFetch(hstmt); - while (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO) - { - GetData(1, SQL_C_CHAR, &result.TableQualifier, 128, &cbRetVal); - GetData(2, SQL_C_CHAR, &result.TableOwner, 128, &cbRetVal); - GetData(3, SQL_C_CHAR, &result.TableName, 128, &cbRetVal); - GetData(4, SQL_C_CHAR, &result.Grantor, 128, &cbRetVal); - GetData(5, SQL_C_CHAR, &result.Grantee, 128, &cbRetVal); - GetData(6, SQL_C_CHAR, &result.Privilege, 128, &cbRetVal); - GetData(7, SQL_C_CHAR, &result.Grantable, 3, &cbRetVal); - -#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); - return true; - } - if (UserID.IsSameAs(result.Grantee,false) && - !strcmp(result.Privilege, privilege)) - { - SQLFreeStmt(hstmt, SQL_CLOSE); - return true; - } - if (!strcmp(result.Grantee,curRole) && - !strcmp(result.Privilege, privilege)) - { - SQLFreeStmt(hstmt, SQL_CLOSE); - return true; - } - retcode = SQLFetch(hstmt); - } - - SQLFreeStmt(hstmt, SQL_CLOSE); - return false; -} // wxDB::TablePrivileges() - - /********** wxDB::SqlLog() **********/ bool wxDB::SqlLog(enum sqlLog state, const char *filename, bool append) { - assert(state == sqlLogON || state == sqlLogOFF); - assert(state == sqlLogOFF || filename); + assert(state == sqlLogON || state == sqlLogOFF); + assert(state == sqlLogOFF || filename); - if (state == sqlLogON) - { - if (fpSqlLog == 0) - { - fpSqlLog = fopen(filename, (append ? "at" : "wt")); - if (fpSqlLog == NULL) - return(FALSE); - } - } - else // sqlLogOFF - { - if (fpSqlLog) - { - if (fclose(fpSqlLog)) - return(FALSE); - fpSqlLog = 0; - } - } + if (state == sqlLogON) + { + if (fpSqlLog == 0) + { + fpSqlLog = fopen(filename, (append ? "at" : "wt")); + if (fpSqlLog == NULL) + return(FALSE); + } + } + else // sqlLogOFF + { + if (fpSqlLog) + { + if (fclose(fpSqlLog)) + return(FALSE); + fpSqlLog = 0; + } + } - sqlLogState = state; - return(TRUE); + sqlLogState = state; + return(TRUE); } // wxDB::SqlLog() @@ -2738,4 +2652,3 @@ bool GetDataSource(HENV henv, char *Dsn, SWORD DsnMax, char *DsDesc, SWORD DsDes #endif // wxUSE_ODBC -