Applied patch [ 649284 ] Fix wxODBC to work with MySQL 2.x
The current sample/db fails to build indexes with MyODBC v2.50.39 This is due to two problems: (1) wxDb::ModifyColumn() created a SQL statement that was not correctly formed for MySQL. This problem caused wxDbTable::CreateIndex() to fail to set the columns that are going to indexes to be NOT NULL. I fixed this by added a special case for MySQL. (2) When creating an Index on a VARCHAR column, MySQL requires a key length to be specified. wxDbTable::CreateIndex() current does not do this. I fixed this problem by adding code to do this. The attached patch file patches dbtable.cpp and db.cpp on the 2.5 branch. gor Mikolic-Torreira git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@18145 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -3576,8 +3576,16 @@ bool wxDb::ModifyColumn(const wxString &tableName, const wxString &columnName,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// create the SQL statement
|
// create the SQL statement
|
||||||
|
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(),
|
sqlStmt.Printf(wxT("ALTER TABLE \"%s\" \"%s\" \"%s\" %s"), tableName.c_str(), alterSlashModify.c_str(),
|
||||||
columnName.c_str(), dataTypeName.c_str());
|
columnName.c_str(), dataTypeName.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
// For varchars only, append the size of the column
|
// For varchars only, append the size of the column
|
||||||
if (dataType == DB_DATA_TYPE_VARCHAR &&
|
if (dataType == DB_DATA_TYPE_VARCHAR &&
|
||||||
|
@@ -1651,6 +1651,26 @@ bool wxDbTable::CreateIndex(const wxString &idxName, bool unique, UWORD noIdxCol
|
|||||||
sqlStmt += pDb->SQLColumnName(pIdxDefs[i].ColName);
|
sqlStmt += pDb->SQLColumnName(pIdxDefs[i].ColName);
|
||||||
// sqlStmt += pIdxDefs[i].ColName;
|
// sqlStmt += pIdxDefs[i].ColName;
|
||||||
|
|
||||||
|
// MySQL requires a key length on VARCHAR keys
|
||||||
|
if ( pDb->Dbms() == dbmsMY_SQL )
|
||||||
|
{
|
||||||
|
// Find the details on this column
|
||||||
|
int j;
|
||||||
|
for ( j = 0; j < noCols; ++j )
|
||||||
|
{
|
||||||
|
if ( wxStrcmp( pIdxDefs[i].ColName, colDefs[j].ColName ) == 0 )
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( colDefs[j].DbDataType == DB_DATA_TYPE_VARCHAR)
|
||||||
|
{
|
||||||
|
wxString s;
|
||||||
|
s.Printf(wxT("(%d)"), colDefs[i].SzDataObj);
|
||||||
|
sqlStmt += s;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Postgres and SQL Server 7 do not support the ASC/DESC keywords for index columns
|
// Postgres and SQL Server 7 do not support the ASC/DESC keywords for index columns
|
||||||
if (!((pDb->Dbms() == dbmsMS_SQL_SERVER) && (strncmp(pDb->dbInf.dbmsVer,"07",2)==0)) &&
|
if (!((pDb->Dbms() == dbmsMS_SQL_SERVER) && (strncmp(pDb->dbInf.dbmsVer,"07",2)==0)) &&
|
||||||
!(pDb->Dbms() == dbmsPOSTGRES))
|
!(pDb->Dbms() == dbmsPOSTGRES))
|
||||||
|
Reference in New Issue
Block a user