Fixed TablePrivileges() function (I HOPE!) so it will work with all supported databases

All variables/parameters having to do with number of columns changed to be of type UWORD rather than int, avoiding compiler warnings and giant tables causing problems, and matching the types with the ODBC APIs


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@9718 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
George Tasker 2001-04-11 14:11:02 +00:00
parent 6b3f4fb875
commit 02cf6fdd85
3 changed files with 36 additions and 30 deletions

View File

@ -339,7 +339,7 @@ class WXDLLEXPORT wxDbConnectInf
struct WXDLLEXPORT wxDbSqlTypeInfo struct WXDLLEXPORT wxDbSqlTypeInfo
{ {
wxString TypeName; wxString TypeName;
int FsqlType; SWORD FsqlType;
long Precision; long Precision;
short CaseSensitive; short CaseSensitive;
// short MinimumScale; // short MinimumScale;
@ -404,7 +404,7 @@ public:
wxChar tableName[DB_MAX_TABLE_NAME_LEN+1]; wxChar tableName[DB_MAX_TABLE_NAME_LEN+1];
wxChar tableType[254+1]; // "TABLE" or "SYSTEM TABLE" etc. wxChar tableType[254+1]; // "TABLE" or "SYSTEM TABLE" etc.
wxChar tableRemarks[254+1]; wxChar tableRemarks[254+1];
int numCols; // How many Columns does this Table have: GetColumnCount(..); UWORD numCols; // How many Columns does this Table have: GetColumnCount(..);
wxDbColInf *pColInf; // pColInf = NULL ; User can later call GetColumns(..); wxDbColInf *pColInf; // pColInf = NULL ; User can later call GetColumns(..);
wxDbTableInf(); wxDbTableInf();
@ -609,12 +609,12 @@ public:
int TranslateSqlState(const wxString &SQLState); int TranslateSqlState(const wxString &SQLState);
wxDbInf *GetCatalog(const wxChar *userID=NULL); wxDbInf *GetCatalog(const wxChar *userID=NULL);
bool Catalog(const wxChar *userID=NULL, const wxString &fileName=SQL_CATALOG_FILENAME); bool Catalog(const wxChar *userID=NULL, const wxString &fileName=SQL_CATALOG_FILENAME);
int GetKeyFields(const wxString &tableName, wxDbColInf* colInf, int nocols); int GetKeyFields(const wxString &tableName, wxDbColInf* colInf, UWORD noCols);
wxDbColInf *GetColumns(wxChar *tableName[], const wxChar *userID=NULL); wxDbColInf *GetColumns(wxChar *tableName[], const wxChar *userID=NULL);
wxDbColInf *GetColumns(const wxString &tableName, int *numCols, const wxChar *userID=NULL); wxDbColInf *GetColumns(const wxString &tableName, UWORD *numCols, const wxChar *userID=NULL);
int GetColumnCount(const wxString &tableName, const wxChar *userID=NULL); UWORD GetColumnCount(const wxString &tableName, const wxChar *userID=NULL);
const wxChar *GetDatabaseName(void) {return dbInf.dbmsName;} const wxChar *GetDatabaseName(void) {return dbInf.dbmsName;}
const wxString &GetDataSource(void) {return dsn;} const wxString &GetDataSource(void) {return dsn;}
const wxString &GetDatasourceName(void){return dsn;} const wxString &GetDatasourceName(void){return dsn;}

View File

@ -67,7 +67,7 @@ class WXDLLEXPORT wxDbColDef
public: public:
wxChar ColName[DB_MAX_COLUMN_NAME_LEN+1]; // Column Name wxChar ColName[DB_MAX_COLUMN_NAME_LEN+1]; // Column Name
int DbDataType; // Logical Data Type; e.g. DB_DATA_TYPE_INTEGER int DbDataType; // Logical Data Type; e.g. DB_DATA_TYPE_INTEGER
int SqlCtype; // C data type; e.g. SQL_C_LONG SWORD SqlCtype; // C data type; e.g. SQL_C_LONG
void *PtrDataObj; // Address of the data object void *PtrDataObj; // Address of the data object
int SzDataObj; // Size, in bytes, of the data object int SzDataObj; // Size, in bytes, of the data object
bool KeyField; // TRUE if this column is part of the PRIMARY KEY to the table; Date fields should NOT be KeyFields. bool KeyField; // TRUE if this column is part of the PRIMARY KEY to the table; Date fields should NOT be KeyFields.
@ -88,7 +88,7 @@ class WXDLLEXPORT wxDbColDataPtr
public: public:
void *PtrDataObj; void *PtrDataObj;
int SzDataObj; int SzDataObj;
int SqlCtype; SWORD SqlCtype;
}; // wxDbColDataPtr }; // wxDbColDataPtr
@ -111,7 +111,7 @@ private:
bool insertable; bool insertable;
// Private member functions // Private member functions
bool initialize(wxDb *pwxDb, const wxString &tblName, const int nCols, bool initialize(wxDb *pwxDb, const wxString &tblName, const UWORD numColumns,
const wxString &qryTblName, bool qryOnly, const wxString &tblPath); const wxString &qryTblName, bool qryOnly, const wxString &tblPath);
void cleanup(); void cleanup();
@ -153,7 +153,7 @@ private:
wxString tablePath; // needed for dBase tables wxString tablePath; // needed for dBase tables
wxString tableName; // Table name wxString tableName; // Table name
wxString queryTableName; // Query Table Name wxString queryTableName; // Query Table Name
int noCols; // # of columns in the table UWORD noCols; // # of columns in the table
bool queryOnly; // Query Only, no inserts, updates or deletes bool queryOnly; // Query Only, no inserts, updates or deletes
// Column Definitions // Column Definitions
@ -187,19 +187,19 @@ public:
char tablePath[wxDB_PATH_MAX]; // needed for dBase tables char tablePath[wxDB_PATH_MAX]; // needed for dBase tables
char tableName[DB_MAX_TABLE_NAME_LEN+1]; // Table name char tableName[DB_MAX_TABLE_NAME_LEN+1]; // Table name
char queryTableName[DB_MAX_TABLE_NAME_LEN+1]; // Query Table Name char queryTableName[DB_MAX_TABLE_NAME_LEN+1]; // Query Table Name
int noCols; // # of columns in the table UWORD noCols; // # of columns in the table
bool queryOnly; // Query Only, no inserts, updates or deletes bool queryOnly; // Query Only, no inserts, updates or deletes
// Column Definitions // Column Definitions
wxDbColDef *colDefs; // Array of wxDbColDef structures wxDbColDef *colDefs; // Array of wxDbColDef structures
#endif #endif
// Public member functions // Public member functions
wxDbTable(wxDb *pwxDb, const wxString &tblName, const int nCols, wxDbTable(wxDb *pwxDb, const wxString &tblName, const UWORD numColumns,
const wxString &qryTblName="", bool qryOnly = !wxDB_QUERY_ONLY, const wxString &qryTblName="", bool qryOnly = !wxDB_QUERY_ONLY,
const wxString &tblPath=""); const wxString &tblPath="");
// DEPRECATED // DEPRECATED
wxDbTable(wxDb *pwxDb, const wxString &tblName, const int nCols, wxDbTable(wxDb *pwxDb, const wxString &tblName, const UWORD numColumns,
const wxChar *qryTblName="", bool qryOnly = !wxDB_QUERY_ONLY, const wxChar *qryTblName="", bool qryOnly = !wxDB_QUERY_ONLY,
const wxString &tblPath=""); const wxString &tblPath="");
@ -222,7 +222,7 @@ public:
const wxString &GetQueryTableName() { return queryTableName; } const wxString &GetQueryTableName() { return queryTableName; }
const wxString &GetTablePath() { return tablePath; } const wxString &GetTablePath() { return tablePath; }
int GetNumberOfColumns() { return noCols; } // number of "defined" columns for this wxDbTable instance UWORD GetNumberOfColumns() { return noCols; } // number of "defined" columns for this wxDbTable instance
const wxString &GetFromClause() { return from; } const wxString &GetFromClause() { return from; }
const wxString &GetOrderByClause() { return orderBy; } const wxString &GetOrderByClause() { return orderBy; }
@ -302,7 +302,7 @@ public:
wxDbColDef *GetColDefs() { return colDefs; } wxDbColDef *GetColDefs() { return colDefs; }
void SetColDefs(int index, const wxString &fieldName, int dataType, void SetColDefs(int index, const wxString &fieldName, int dataType,
void *pData, int cType, void *pData, SWORD cType,
int size, bool keyField = FALSE, bool upd = TRUE, int size, bool keyField = FALSE, bool upd = TRUE,
bool insAllow = TRUE, bool derivedCol = FALSE); bool insAllow = TRUE, bool derivedCol = FALSE);
wxDbColDataPtr *SetColDefs(wxDbColInf *colInfs, ULONG numCols); wxDbColDataPtr *SetColDefs(wxDbColInf *colInfs, ULONG numCols);

View File

@ -1936,7 +1936,7 @@ bool wxDb::GetData(UWORD colNo, SWORD cType, PTR pData, SDWORD maxLen, SDWORD FA
/********** wxDb::GetKeyFields() **********/ /********** wxDb::GetKeyFields() **********/
int wxDb::GetKeyFields(const wxString &tableName, wxDbColInf* colInf, int noCols) int wxDb::GetKeyFields(const wxString &tableName, wxDbColInf* colInf, UWORD noCols)
{ {
wxChar szPkTable[DB_MAX_TABLE_NAME_LEN+1]; /* Primary key table name */ wxChar szPkTable[DB_MAX_TABLE_NAME_LEN+1]; /* Primary key table name */
wxChar szFkTable[DB_MAX_TABLE_NAME_LEN+1]; /* Foreign key table name */ wxChar szFkTable[DB_MAX_TABLE_NAME_LEN+1]; /* Foreign key table name */
@ -1946,7 +1946,7 @@ int wxDb::GetKeyFields(const wxString &tableName, wxDbColInf* colInf, int noCols
wxChar szFkCol[DB_MAX_COLUMN_NAME_LEN+1]; /* Foreign key column */ wxChar szFkCol[DB_MAX_COLUMN_NAME_LEN+1]; /* Foreign key column */
SQLRETURN retcode; SQLRETURN retcode;
SDWORD cb; SDWORD cb;
int i; SWORD i;
wxString tempStr; wxString tempStr;
/* /*
* ----------------------------------------------------------------------- * -----------------------------------------------------------------------
@ -2104,8 +2104,8 @@ wxDbColInf *wxDb::GetColumns(wxChar *tableName[], const wxChar *userID)
* to avoid undesired unbinding of columns. * to avoid undesired unbinding of columns.
*/ */
{ {
int noCols = 0; UWORD noCols = 0;
int colNo = 0; int colNo = 0;
wxDbColInf *colInf = 0; wxDbColInf *colInf = 0;
RETCODE retcode; RETCODE retcode;
@ -2246,7 +2246,7 @@ wxDbColInf *wxDb::GetColumns(wxChar *tableName[], const wxChar *userID)
/********** wxDb::GetColumns() **********/ /********** wxDb::GetColumns() **********/
wxDbColInf *wxDb::GetColumns(const wxString &tableName, int *numCols, const wxChar *userID) wxDbColInf *wxDb::GetColumns(const wxString &tableName, UWORD *numCols, const wxChar *userID)
// //
// Same as the above GetColumns() function except this one gets columns // Same as the above GetColumns() function except this one gets columns
// only for a single table, and if 'numCols' is not NULL, the number of // only for a single table, and if 'numCols' is not NULL, the number of
@ -2262,8 +2262,8 @@ wxDbColInf *wxDb::GetColumns(const wxString &tableName, int *numCols, const wxCh
// to avoid undesired unbinding of columns. // to avoid undesired unbinding of columns.
{ {
int noCols = 0; UWORD noCols = 0;
int colNo = 0; int colNo = 0;
wxDbColInf *colInf = 0; wxDbColInf *colInf = 0;
RETCODE retcode; RETCODE retcode;
@ -2447,7 +2447,7 @@ wxDbColInf *wxDb::GetColumns(const wxString &tableName, int *numCols, const wxCh
typedef struct typedef struct
{ {
int noCols; UWORD noCols;
wxDbColInf *colInf; wxDbColInf *colInf;
} _TableColumns; } _TableColumns;
@ -2458,7 +2458,7 @@ wxDbColInf *wxDb::GetColumns(wxChar *tableName[], const wxChar *userID)
// The last array element of the tableName[] argument must be zero (null). // The last array element of the tableName[] argument must be zero (null).
// This is how the end of the array is detected. // This is how the end of the array is detected.
int noCols = 0; UWORD noCols = 0;
// How many tables ? // How many tables ?
int tbl; int tbl;
@ -2517,7 +2517,7 @@ wxDbColInf *wxDb::GetColumns(const wxString &tableName, int *numCols, const wxCh
// by this function. This function should use its own wxDb instance // by this function. This function should use its own wxDb instance
// to avoid undesired unbinding of columns. // to avoid undesired unbinding of columns.
{ {
SWORD noCols = 0; UWORD noCols = 0;
int colNo = 0; int colNo = 0;
wxDbColInf *colInf = 0; wxDbColInf *colInf = 0;
@ -2762,7 +2762,7 @@ wxDbColInf *wxDb::GetColumns(const wxString &tableName, int *numCols, const wxCh
/********** wxDb::GetColumnCount() **********/ /********** wxDb::GetColumnCount() **********/
int wxDb::GetColumnCount(const wxString &tableName, const wxChar *userID) UWORD wxDb::GetColumnCount(const wxString &tableName, const wxChar *userID)
/* /*
* Returns a count of how many columns are in a table. * Returns a count of how many columns are in a table.
* If an error occurs in computing the number of columns * If an error occurs in computing the number of columns
@ -2778,7 +2778,7 @@ int wxDb::GetColumnCount(const wxString &tableName, const wxChar *userID)
* to avoid undesired unbinding of columns. * to avoid undesired unbinding of columns.
*/ */
{ {
int noCols = 0; UWORD noCols = 0;
RETCODE retcode; RETCODE retcode;
@ -3172,8 +3172,9 @@ bool wxDb::TablePrivileges(const wxString &tableName, const wxString &priv, cons
wxString TableName; wxString TableName;
wxString UserID; wxString UserID,Schema;
convertUserID(userID,UserID); convertUserID(userID,UserID);
convertUserID(schema,Schema);
TableName = tableName; TableName = tableName;
// Oracle and Interbase table names are uppercase only, so force // Oracle and Interbase table names are uppercase only, so force
@ -3184,18 +3185,23 @@ bool wxDb::TablePrivileges(const wxString &tableName, const wxString &priv, cons
SQLFreeStmt(hstmt, SQL_CLOSE); SQLFreeStmt(hstmt, SQL_CLOSE);
if (!schema) // Some databases cannot accept a user name when looking up table names,
// so we use the call below that leaves out the user name
if (!Schema.IsEmpty() &&
Dbms() != dbmsMY_SQL &&
Dbms() != dbmsACCESS &&
Dbms() != dbmsMS_SQL_SERVER)
{ {
retcode = SQLTablePrivileges(hstmt, retcode = SQLTablePrivileges(hstmt,
NULL, 0, // Catalog NULL, 0, // Catalog
NULL, 0, // Schema (UCHAR FAR *)Schema.c_str(), SQL_NTS, // Schema
(UCHAR FAR *)TableName.c_str(), SQL_NTS); (UCHAR FAR *)TableName.c_str(), SQL_NTS);
} }
else else
{ {
retcode = SQLTablePrivileges(hstmt, retcode = SQLTablePrivileges(hstmt,
NULL, 0, // Catalog NULL, 0, // Catalog
(UCHAR FAR *)schema, SQL_NTS, // Schema NULL, 0, // Schema
(UCHAR FAR *)TableName.c_str(), SQL_NTS); (UCHAR FAR *)TableName.c_str(), SQL_NTS);
} }