X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/d1f5f7a44bebccf61a53ad4b308d7face1d95ff7..19193a2c85987b595932957e73013e7ea100f0e8:/src/common/db.cpp diff --git a/src/common/db.cpp b/src/common/db.cpp index d9ce256f6d..c3957c35e6 100644 --- a/src/common/db.cpp +++ b/src/common/db.cpp @@ -603,15 +603,6 @@ bool wxDb::Open(const wxString &Dsn, const wxString &Uid, const wxString &AuthSt (UCHAR FAR *) uid.c_str(), SQL_NTS, (UCHAR FAR *) authStr.c_str(), SQL_NTS); -/* - if (retcode == SQL_SUCCESS_WITH_INFO) - DispAllErrors(henv, hdbc); - else if (retcode != SQL_SUCCESS) - return(DispAllErrors(henv, hdbc)); - - if (retcode == SQL_ERROR) - return(DispAllErrors(henv, hdbc)); -*/ if ((retcode != SQL_SUCCESS) && (retcode != SQL_SUCCESS_WITH_INFO)) return(DispAllErrors(henv, hdbc)); @@ -1784,7 +1775,7 @@ bool wxDb::Grant(int privileges, const wxString &tableName, const wxString &user } sqlStmt += wxT(" ON "); - sqlStmt += tableName; + sqlStmt += SQLTableName(tableName); sqlStmt += wxT(" TO "); sqlStmt += userList; @@ -2687,7 +2678,7 @@ wxDbColInf *wxDb::GetColumns(const wxString &tableName, int *numCols, const wxCh // Build a generic SELECT statement which returns 0 rows wxString Stmt; - Stmt.Printf(wxT("select * from %s where 0=1"), tableName); + Stmt.Printf(wxT("select * from \"%s\" where 0=1"), tableName); // Execute query if (SQLExecDirect(hstmt, (UCHAR FAR *) Stmt.c_str(), SQL_NTS) != SQL_SUCCESS) @@ -2980,7 +2971,7 @@ bool wxDb::Catalog(const wxChar *userID, const wxString &fileName) wxChar colName[DB_MAX_COLUMN_NAME_LEN+1]; SWORD sqlDataType; wxChar typeName[30+1]; - SWORD precision, length; + SDWORD precision, length; FILE *fp = fopen(fileName.c_str(),wxT("wt")); if (fp == NULL) @@ -3022,8 +3013,12 @@ bool wxDb::Catalog(const wxChar *userID, const wxString &fileName) tblNameSave.Empty(); int cnt = 0; - while ((retcode = SQLFetch(hstmt)) == SQL_SUCCESS) + while (TRUE) { + retcode = SQLFetch(hstmt); + if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO) + break; + if (wxStrcmp(tblName, tblNameSave.c_str())) { if (cnt) @@ -3044,12 +3039,12 @@ bool wxDb::Catalog(const wxChar *userID, const wxString &fileName) tblNameSave = tblName; } - GetData(3,SQL_C_CHAR, (UCHAR *)tblName, DB_MAX_TABLE_NAME_LEN+1, &cb); - GetData(4,SQL_C_CHAR, (UCHAR *)colName, DB_MAX_COLUMN_NAME_LEN+1,&cb); - GetData(5,SQL_C_SSHORT,(UCHAR *)&sqlDataType,0, &cb); - GetData(6,SQL_C_CHAR, (UCHAR *)typeName, sizeof(typeName), &cb); - GetData(7,SQL_C_SSHORT,(UCHAR *)&precision, 0, &cb); - GetData(8,SQL_C_SSHORT,(UCHAR *)&length, 0, &cb); + GetData(3,SQL_C_CHAR, (UCHAR *) tblName, DB_MAX_TABLE_NAME_LEN+1, &cb); + GetData(4,SQL_C_CHAR, (UCHAR *) colName, DB_MAX_COLUMN_NAME_LEN+1,&cb); + GetData(5,SQL_C_SSHORT,(UCHAR *)&sqlDataType, 0, &cb); + GetData(6,SQL_C_CHAR, (UCHAR *) typeName, sizeof(typeName), &cb); + GetData(7,SQL_C_SLONG, (UCHAR *)&precision, 0, &cb); + GetData(8,SQL_C_SLONG, (UCHAR *)&length, 0, &cb); outStr.Printf(wxT("%-32s %-32s (%04d)%-15s %9d %9d\n"), tblName, colName, sqlDataType, typeName, precision, length); @@ -3277,6 +3272,34 @@ bool wxDb::TablePrivileges(const wxString &tableName, const wxString &priv, cons } // wxDb::TablePrivileges +const wxString wxDb::SQLTableName(const char *tableName) +{ + wxString TableName; + + if (Dbms() == dbmsACCESS) + TableName = '"'; + TableName += tableName; + if (Dbms() == dbmsACCESS) + TableName += '"'; + + return TableName; +} // wxDb::SQLTableName() + + +const wxString wxDb::SQLColumnName(const char *colName) +{ + wxString ColName; + + if (Dbms() == dbmsACCESS) + ColName = '"'; + ColName += colName; + if (Dbms() == dbmsACCESS) + ColName += '"'; + + return ColName; +} // wxDb::SQLColumnName() + + /********** wxDb::SetSqlLogging() **********/ bool wxDb::SetSqlLogging(wxDbSqlLogState state, const wxString &filename, bool append) { @@ -3525,7 +3548,7 @@ bool wxDb::ModifyColumn(const wxString &tableName, const wxString &columnName, } // create the SQL statement - sqlStmt.Printf(wxT("ALTER TABLE %s %s %s %s"), tableName.c_str(), alterSlashModify.c_str(), + sqlStmt.Printf(wxT("ALTER TABLE \"%s\" \"%s\" \"%s\" %s"), tableName.c_str(), alterSlashModify.c_str(), columnName.c_str(), dataTypeName.c_str()); // For varchars only, append the size of the column @@ -3718,7 +3741,7 @@ const wxChar WXDLLEXPORT *wxDbLogExtendedErrorMsg(const wxChar *userText, wxDb * msg.Append (wxT("\nODBC errors:\n")); msg += wxT("\n"); - + // Display errors for this connection int i; for (i = 0; i < DB_MAX_ERROR_HISTORY; i++)