X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/5bdad317aa06da5590f585581677f18765985391..61fef19b852d426f5b00b60de083539b9ba0f76c:/src/common/db.cpp?ds=inline diff --git a/src/common/db.cpp b/src/common/db.cpp index f32276faf0..902591109e 100644 --- a/src/common/db.cpp +++ b/src/common/db.cpp @@ -53,9 +53,6 @@ #include "wx/object.h" #include "wx/list.h" #include "wx/utils.h" - #if wxUSE_GUI - #include "wx/msgdlg.h" - #endif #include "wx/log.h" #endif #include "wx/filefn.h" @@ -71,7 +68,7 @@ #include "wx/db.h" -WXDLLEXPORT_DATA(wxDbList*) PtrBegDbList = 0; +WXDLLIMPEXP_DATA_ODBC(wxDbList*) PtrBegDbList = 0; wxChar const *SQL_LOG_FILENAME = wxT("sqllog.txt"); @@ -562,7 +559,8 @@ const wxChar *wxDb::convertUserID(const wxChar *userID, wxString &UserID) UserID.Empty(); // dBase does not use user names, and some drivers fail if you try to pass one - if (Dbms() == dbmsDBASE) + if ( Dbms() == dbmsDBASE + || Dbms() == dbmsXBASE_SEQUITER ) UserID.Empty(); // Oracle user names may only be in uppercase, so force @@ -575,7 +573,7 @@ const wxChar *wxDb::convertUserID(const wxChar *userID, wxString &UserID) /********** wxDb::Open() **********/ -bool wxDb::Open(const wxString &Dsn, const wxString &Uid, const wxString &AuthStr) +bool wxDb::Open(const wxString &Dsn, const wxString &Uid, const wxString &AuthStr, bool failOnDataTypeUnsupported) { wxASSERT(Dsn.Length()); dsn = Dsn; @@ -686,7 +684,10 @@ bool wxDb::Open(const wxString &Dsn, const wxString &Uid, const wxString &AuthSt if (!getDataTypeInfo(SQL_FLOAT,typeInfFloat)) if (!getDataTypeInfo(SQL_DECIMAL,typeInfFloat)) if (!getDataTypeInfo(SQL_NUMERIC,typeInfFloat)) - return(FALSE); + { + if (failOnDataTypeUnsupported) + return(FALSE); + } else typeInfFloat.FsqlType = SQL_NUMERIC; else @@ -704,7 +705,10 @@ bool wxDb::Open(const wxString &Dsn, const wxString &Uid, const wxString &AuthSt // If SQL_INTEGER is not supported, use the floating point // data type to store integers as well as floats if (!getDataTypeInfo(typeInfFloat.FsqlType, typeInfInteger)) - return(FALSE); + { + if (failOnDataTypeUnsupported) + return(FALSE); + } else typeInfInteger.FsqlType = typeInfFloat.FsqlType; } @@ -712,25 +716,36 @@ bool wxDb::Open(const wxString &Dsn, const wxString &Uid, const wxString &AuthSt typeInfInteger.FsqlType = SQL_INTEGER; // Date/Time - if (Dbms() != dbmsDBASE) - { - if (!getDataTypeInfo(SQL_TIMESTAMP,typeInfDate)) - return(FALSE); - else - typeInfDate.FsqlType = SQL_TIMESTAMP; - } - else + if (!getDataTypeInfo(SQL_TIMESTAMP,typeInfDate)) { if (!getDataTypeInfo(SQL_DATE,typeInfDate)) - return(FALSE); + { +#ifdef SQL_DATETIME + if (getDataTypeInfo(SQL_DATETIME,typeInfDate)) + { + typeInfDate.FsqlType = SQL_TIME; + } + else +#endif // SQL_DATETIME defined + { + if (failOnDataTypeUnsupported) + return(FALSE); + } + } else typeInfDate.FsqlType = SQL_DATE; } + else + typeInfDate.FsqlType = SQL_TIMESTAMP; + if (!getDataTypeInfo(SQL_LONGVARBINARY, typeInfBlob)) { if (!getDataTypeInfo(SQL_VARBINARY,typeInfBlob)) - return(FALSE); + { + if (failOnDataTypeUnsupported) + return(FALSE); + } else typeInfBlob.FsqlType = SQL_VARBINARY; } @@ -1286,8 +1301,10 @@ bool wxDb::getDataTypeInfo(SWORD fSqlType, wxDbSqlTypeInfo &structSQLTypeInfo) // Get information about the data type specified if (SQLGetTypeInfo(hstmt, fSqlType) != SQL_SUCCESS) return(DispAllErrors(henv, hdbc, hstmt)); + // Fetch the record - if ((retcode = SQLFetch(hstmt)) != SQL_SUCCESS) + retcode = SQLFetch(hstmt); + if (retcode != SQL_SUCCESS) { #ifdef DBDEBUG_CONSOLE if (retcode == SQL_NO_DATA_FOUND) @@ -1299,6 +1316,7 @@ bool wxDb::getDataTypeInfo(SWORD fSqlType, wxDbSqlTypeInfo &structSQLTypeInfo) } wxChar typeName[DB_TYPE_NAME_LEN+1]; + // Obtain columns from the record if (SQLGetData(hstmt, 1, SQL_C_CHAR, (UCHAR*) typeName, DB_TYPE_NAME_LEN, &cbRet) != SQL_SUCCESS) return(DispAllErrors(henv, hdbc, hstmt)); @@ -3046,7 +3064,7 @@ bool wxDb::Catalog(const wxChar *userID, const wxString &fileName) 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"), + outStr.Printf(wxT("%-32s %-32s (%04d)%-15s %9ld %9ld\n"), tblName, colName, sqlDataType, typeName, precision, length); if (fputs(outStr.c_str(), fp) == EOF) { @@ -3478,6 +3496,12 @@ wxDBMS wxDb::Dbms(void) if (!wxStricmp(baseName,wxT("DBASE"))) return((wxDBMS)(dbmsType = dbmsDBASE)); + if (!wxStricmp(baseName,wxT("xBase"))) + return((wxDBMS)(dbmsType = dbmsXBASE_SEQUITER)); + + if (!wxStricmp(baseName,wxT("MySQL"))) + return((wxDBMS)(dbmsType = dbmsMY_SQL)); + baseName[3] = 0; if (!wxStricmp(baseName,wxT("DB2"))) return((wxDBMS)(dbmsType = dbmsDBASE)); @@ -3542,20 +3566,30 @@ bool wxDb::ModifyColumn(const wxString &tableName, const wxString &columnName, case dbmsPOSTGRES : case dbmsACCESS : case dbmsDBASE : + case dbmsXBASE_SEQUITER : default : alterSlashModify = "MODIFY"; break; } // create the SQL statement - sqlStmt.Printf(wxT("ALTER TABLE \"%s\" \"%s\" \"%s\" %s"), tableName.c_str(), alterSlashModify.c_str(), + if ( Dbms() == dbmsMY_SQL ) + { + sqlStmt.Printf(wxT("ALTER TABLE %s %s %s %s"), tableName.c_str(), alterSlashModify.c_str(), columnName.c_str(), dataTypeName.c_str()); + } + else + { + 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 - if (dataType == DB_DATA_TYPE_VARCHAR) + if (dataType == DB_DATA_TYPE_VARCHAR && + (Dbms() != dbmsMY_SQL || dataTypeName != "text")) { wxString s; - s.Printf(wxT("(%d)"), columnLength); + s.Printf(wxT("(%lu)"), columnLength); sqlStmt += s; } @@ -3572,7 +3606,7 @@ bool wxDb::ModifyColumn(const wxString &tableName, const wxString &columnName, /********** wxDbGetConnection() **********/ -wxDb WXDLLEXPORT *wxDbGetConnection(wxDbConnectInf *pDbConfig, bool FwdOnlyCursors) +wxDb WXDLLIMPEXP_ODBC *wxDbGetConnection(wxDbConnectInf *pDbConfig, bool FwdOnlyCursors) { wxDbList *pList; @@ -3661,7 +3695,7 @@ wxDb WXDLLEXPORT *wxDbGetConnection(wxDbConnectInf *pDbConfig, bool FwdOnlyCurso /********** wxDbFreeConnection() **********/ -bool WXDLLEXPORT wxDbFreeConnection(wxDb *pDb) +bool WXDLLIMPEXP_ODBC wxDbFreeConnection(wxDb *pDb) { wxDbList *pList; @@ -3679,7 +3713,7 @@ bool WXDLLEXPORT wxDbFreeConnection(wxDb *pDb) /********** wxDbCloseConnections() **********/ -void WXDLLEXPORT wxDbCloseConnections(void) +void WXDLLIMPEXP_ODBC wxDbCloseConnections(void) { wxDbList *pList, *pNext; @@ -3701,7 +3735,7 @@ void WXDLLEXPORT wxDbCloseConnections(void) /********** wxDbConnectionsInUse() **********/ -int WXDLLEXPORT wxDbConnectionsInUse(void) +int WXDLLIMPEXP_ODBC wxDbConnectionsInUse(void) { wxDbList *pList; int cnt = 0; @@ -3721,8 +3755,10 @@ int WXDLLEXPORT wxDbConnectionsInUse(void) /********** wxDbLogExtendedErrorMsg() **********/ // DEBUG ONLY function -const wxChar WXDLLEXPORT *wxDbLogExtendedErrorMsg(const wxChar *userText, wxDb *pDb, - wxChar *ErrFile, int ErrLine) +const wxChar* WXDLLIMPEXP_ODBC wxDbLogExtendedErrorMsg(const wxChar *userText, + wxDb *pDb, + const wxChar *ErrFile, + int ErrLine) { static wxString msg; msg = userText; @@ -3908,22 +3944,22 @@ bool GetDataSource(HENV henv, char *Dsn, SWORD DsnMax, char *DsDesc, SWORD DsDes return wxDbGetDataSource(henv, Dsn, DsnMax, DsDesc, DsDescMax, direction); } /***** DEPRECATED: use wxDbGetConnection() *****/ -wxDb WXDLLEXPORT *GetDbConnection(DbStuff *pDbStuff, bool FwdOnlyCursors) +wxDb WXDLLIMPEXP_ODBC *GetDbConnection(DbStuff *pDbStuff, bool FwdOnlyCursors) { return wxDbGetConnection((wxDbConnectInf *)pDbStuff, FwdOnlyCursors); } /***** DEPRECATED: use wxDbFreeConnection() *****/ -bool WXDLLEXPORT FreeDbConnection(wxDb *pDb) +bool WXDLLIMPEXP_ODBC FreeDbConnection(wxDb *pDb) { return wxDbFreeConnection(pDb); } /***** DEPRECATED: use wxDbCloseConnections() *****/ -void WXDLLEXPORT CloseDbConnections(void) +void WXDLLIMPEXP_ODBC CloseDbConnections(void) { wxDbCloseConnections(); } /***** DEPRECATED: use wxDbConnectionsInUse() *****/ -int WXDLLEXPORT NumberDbConnectionsInUse(void) +int WXDLLIMPEXP_ODBC NumberDbConnectionsInUse(void) { return wxDbConnectionsInUse(); }