From: George Tasker Date: Wed, 23 Feb 2000 23:11:53 +0000 (+0000) Subject: ::IsNumber() returned FALSE if a + or - sign was the first character of the string... X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/2f74ed285965eaf401a4060507b5c80166dfc0f5 ::IsNumber() returned FALSE if a + or - sign was the first character of the string. "-123" should be considered a number git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@6250 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/src/common/db.cpp b/src/common/db.cpp index d2b7427acf..7e0f753143 100644 --- a/src/common/db.cpp +++ b/src/common/db.cpp @@ -547,6 +547,9 @@ 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)); @@ -627,6 +630,7 @@ 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) @@ -1559,9 +1563,6 @@ 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; @@ -2345,33 +2346,135 @@ 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() diff --git a/src/common/dbtable.cpp b/src/common/dbtable.cpp index 1cef849131..f39279fef8 100644 --- a/src/common/dbtable.cpp +++ b/src/common/dbtable.cpp @@ -130,6 +130,8 @@ wxTable::wxTable(wxDB *pwxDB, const char *tblName, const int nCols, wxStrcpy(tableName, tblName); // Table Name if (tblPath) wxStrcpy(tablePath, tblPath); // Table Path - used for dBase files + else + tablePath[0]=0; if (qryTblName) // Name of the table/view to query wxStrcpy(queryTableName, qryTblName); @@ -578,20 +580,43 @@ bool wxTable::Open(void) int i; // char sqlStmt[DB_MAX_STATEMENT_LEN]; wxString sqlStmt; + wxString *s = NULL; // Verify that the table exists in the database - if (!pDb->TableExists(tableName,pDb->GetUsername(),tablePath)) +// if (!pDb->TableExists(tableName,pDb->GetUsername(),tablePath)) + if (!pDb->TableExists(tableName,NULL,tablePath)) { - wxString s; + s =new wxString("Table/view does not exist in the database"); + if (*(pDb->dbInf.accessibleTables) == 'Y') + { + (*s)+=", or you have insufficient permissions.\n"; + } + else + { + (*s)+=".\n"; + } + } + else + { + // Verify the user has rights to access the table. + // Shortcut boolean evaluation to optimize out call to TablePrivs + // Unfortunely this optimization doesn't seem to be reliable! + if (/* *(pDb->dbInf.accessibleTables) == 'N' && */ + !pDb->TablePrivileges(tableName,"SELECT",NULL,tablePath)) + s = new wxString("Current logged in user has insufficient privileges to access this table.\n"); + } + + if (s) + { + wxString p; if (wxStrcmp(tablePath,"")) - s.sprintf("Error opening '%s/%s'.\n",tablePath,tableName); - else - s.sprintf("Error opening '%s'.\n", tableName); - if (!pDb->TableExists(tableName,NULL,tablePath)) - s += "Table/view does not exist in the database.\n"; - else - s += "Current logged in user does not have sufficient privileges to access this table.\n"; - pDb->LogError(s.GetData()); + p.sprintf("Error opening '%s/%s'.\n",tablePath,tableName); + else + p.sprintf("Error opening '%s'.\n", tableName); + + p += (*s); + pDb->LogError(p.GetData()); + return(FALSE); } diff --git a/src/common/string.cpp b/src/common/string.cpp index cd934faa9e..bd4dc94a62 100644 --- a/src/common/string.cpp +++ b/src/common/string.cpp @@ -910,6 +910,8 @@ bool wxString::IsWord() const bool wxString::IsNumber() const { const wxChar *s = (const wxChar*) *this; + if (wxStrlen(s)) + if ((s[0] == '-') || (s[0] == '+')) s++; while(*s){ if(!wxIsdigit(*s)) return(FALSE); s++;