Semi-Blind fixes for trying to handle different versions of MySQL and MySQL windows drivers
Hopefully better handling of DATE type fields New parameter added to optionally not have database connections fail if a basic data type (like DATE) is not reported as supported by the datasource git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@14722 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
b58a1455e1
commit
e25cdb868f
@ -591,7 +591,8 @@ public:
|
||||
wxDb(const HENV &aHenv, bool FwdOnlyCursors=(bool)wxODBC_FWD_ONLY_CURSORS);
|
||||
~wxDb();
|
||||
|
||||
bool Open(const wxString &Dsn, const wxString &Uid, const wxString &AuthStr); // Data Source Name, User ID, Password
|
||||
// Data Source Name, User ID, Password and whether open should fail on data type not supported
|
||||
bool Open(const wxString &Dsn, const wxString &Uid, const wxString &AuthStr, bool failOnDataTypeUnsupported=TRUE);
|
||||
bool Open(wxDbConnectInf *dbConnectInf);
|
||||
bool Open(wxDb *copyDb); // pointer to a wxDb whose connection info should be copied rather than re-queried
|
||||
void Close(void);
|
||||
|
@ -575,7 +575,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 +686,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 +707,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 +718,32 @@ 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);
|
||||
{
|
||||
if (!getDataTypeInfo(SQL_DATETIME,typeInfDate))
|
||||
{
|
||||
if (failOnDataTypeUnsupported)
|
||||
return(FALSE);
|
||||
}
|
||||
else
|
||||
typeInfDate.FsqlType = SQL_TIME;
|
||||
}
|
||||
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 +1299,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 +1314,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));
|
||||
@ -3478,6 +3494,9 @@ wxDBMS wxDb::Dbms(void)
|
||||
if (!wxStricmp(baseName,wxT("DBASE")))
|
||||
return((wxDBMS)(dbmsType = dbmsDBASE));
|
||||
|
||||
if (!wxStricmp(baseName,wxT("MySQL")))
|
||||
return((wxDBMS)(dbmsType = dbmsMY_SQL));
|
||||
|
||||
baseName[3] = 0;
|
||||
if (!wxStricmp(baseName,wxT("DB2")))
|
||||
return((wxDBMS)(dbmsType = dbmsDBASE));
|
||||
@ -3552,7 +3571,8 @@ bool wxDb::ModifyColumn(const wxString &tableName, const wxString &columnName,
|
||||
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);
|
||||
|
@ -1384,7 +1384,8 @@ bool wxDbTable::CreateTable(bool attemptDrop)
|
||||
break;
|
||||
}
|
||||
// For varchars, append the size of the string
|
||||
if (colDefs[i].DbDataType == DB_DATA_TYPE_VARCHAR)// ||
|
||||
if (colDefs[i].DbDataType == DB_DATA_TYPE_VARCHAR &&
|
||||
(pDb->Dbms() != dbmsMY_SQL || pDb->GetTypeInfVarchar().TypeName != "text"))// ||
|
||||
// colDefs[i].DbDataType == DB_DATA_TYPE_BLOB)
|
||||
{
|
||||
wxString s;
|
||||
@ -1456,7 +1457,14 @@ bool wxDbTable::CreateTable(bool attemptDrop)
|
||||
if (j++) // Multi part key, comma separate names
|
||||
sqlStmt += wxT(",");
|
||||
sqlStmt += pDb->SQLColumnName(colDefs[i].ColName);
|
||||
// sqlStmt += colDefs[i].ColName;
|
||||
|
||||
if (pDb->Dbms() == dbmsMY_SQL &&
|
||||
colDefs[i].DbDataType == DB_DATA_TYPE_VARCHAR)
|
||||
{
|
||||
wxString s;
|
||||
s.Printf(wxT("(%d)"), colDefs[i].SzDataObj);
|
||||
sqlStmt += s;
|
||||
}
|
||||
}
|
||||
}
|
||||
sqlStmt += wxT(")");
|
||||
|
Loading…
Reference in New Issue
Block a user