+bool wxDb::ModifyColumn(const wxString &tableName, const wxString &columnName,
+ int dataType, ULONG columnLength,
+ const wxString &optionalParam)
+{
+ wxASSERT(tableName.Length());
+ wxASSERT(columnName.Length());
+ wxASSERT((dataType == DB_DATA_TYPE_VARCHAR && columnLength > 0) ||
+ dataType != DB_DATA_TYPE_VARCHAR);
+
+ // Must specify a columnLength if modifying a VARCHAR type column
+ if (dataType == DB_DATA_TYPE_VARCHAR && !columnLength)
+ return FALSE;
+
+ wxString dataTypeName;
+ wxString sqlStmt;
+ wxString alterSlashModify;
+
+ switch(dataType)
+ {
+ case DB_DATA_TYPE_VARCHAR :
+ dataTypeName = typeInfVarchar.TypeName;
+ break;
+ case DB_DATA_TYPE_INTEGER :
+ dataTypeName = typeInfInteger.TypeName;
+ break;
+ case DB_DATA_TYPE_FLOAT :
+ dataTypeName = typeInfFloat.TypeName;
+ break;
+ case DB_DATA_TYPE_DATE :
+ dataTypeName = typeInfDate.TypeName;
+ break;
+ case DB_DATA_TYPE_BLOB :
+ dataTypeName = typeInfBlob.TypeName;
+ break;
+ default:
+ return FALSE;
+ }
+
+ // Set the modify or alter syntax depending on the type of database connected to
+ switch (Dbms())
+ {
+ case dbmsORACLE :
+ alterSlashModify = "MODIFY";
+ break;
+ case dbmsMS_SQL_SERVER :
+ alterSlashModify = "ALTER COLUMN";
+ break;
+ case dbmsUNIDENTIFIED :
+ return FALSE;
+ case dbmsSYBASE_ASA :
+ case dbmsSYBASE_ASE :
+ case dbmsMY_SQL :
+ case dbmsPOSTGRES :
+ case dbmsACCESS :
+ case dbmsDBASE :
+ default :
+ alterSlashModify = "MODIFY";
+ break;
+ }
+
+ // create the SQL statement
+ 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 &&
+ (Dbms() != dbmsMY_SQL || dataTypeName != "text"))
+ {
+ wxString s;
+ s.Printf(wxT("(%d)"), columnLength);
+ sqlStmt += s;
+ }
+
+ // for passing things like "NOT NULL"
+ if (optionalParam.Length())
+ {
+ sqlStmt += wxT(" ");
+ sqlStmt += optionalParam;
+ }
+
+ return ExecSql(sqlStmt);
+
+} // wxDb::ModifyColumn()
+
+