+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 = _T("MODIFY");
+ break;
+ case dbmsMS_SQL_SERVER :
+ alterSlashModify = _T("ALTER COLUMN");
+ break;
+ case dbmsUNIDENTIFIED :
+ return false;
+ case dbmsSYBASE_ASA :
+ case dbmsSYBASE_ASE :
+ case dbmsMY_SQL :
+ case dbmsPOSTGRES :
+ case dbmsACCESS :
+ case dbmsDBASE :
+ case dbmsXBASE_SEQUITER :
+ default :
+ alterSlashModify = _T("MODIFY");
+ break;
+ }
+
+ // 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(),
+ 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 != _T("text")))
+ {
+ wxString s;
+ s.Printf(wxT("(%lu)"), columnLength);
+ sqlStmt += s;
+ }
+
+ // for passing things like "NOT NULL"
+ if (optionalParam.length())
+ {
+ sqlStmt += wxT(" ");
+ sqlStmt += optionalParam;
+ }
+
+ return ExecSql(sqlStmt);
+
+} // wxDb::ModifyColumn()
+
+/********** wxDb::EscapeSqlChars() **********/
+wxString wxDb::EscapeSqlChars(const wxString& valueOrig)
+{
+ wxString value(valueOrig);
+ switch (Dbms())
+ {
+ case dbmsACCESS:
+ // Access doesn't seem to care about backslashes, so only escape single quotes.
+ value.Replace(wxT("'"), wxT("''"));
+ break;
+
+ default:
+ // All the others are supposed to be the same for now, add special
+ // handling for them if necessary
+ value.Replace(wxT("\\"), wxT("\\\\"));
+ value.Replace(wxT("'"), wxT("\\'"));
+ break;
+ }
+
+ return value;
+} // wxDb::EscapeSqlChars()
+
+