diff --git a/src/EditTableDialog.cpp b/src/EditTableDialog.cpp index 98e2c652..5118a2f7 100644 --- a/src/EditTableDialog.cpp +++ b/src/EditTableDialog.cpp @@ -334,10 +334,32 @@ void EditTableDialog::itemChanged(QTreeWidgetItem *item, int column) } break; case kDefault: + { + QString new_value = item->text(column); + // If the default value isn't a SQL keyword perform an extra check: If it isn't numeric but doesn't start and end with quotes, + // add the quotes + if(new_value.compare("null", Qt::CaseInsensitive) && + new_value.compare("current_time", Qt::CaseInsensitive) && + new_value.compare("current_date", Qt::CaseInsensitive) && + new_value.compare("current_timestamp", Qt::CaseInsensitive)) + { + if(!((new_value.trimmed().startsWith('\'') || + new_value.trimmed().startsWith('"')) && (new_value.trimmed().endsWith('\'') || new_value.trimmed().endsWith('"')))) + { + bool is_numeric; + new_value.toDouble(&is_numeric); + if(!is_numeric) + { + new_value = QString("'%1'").arg(new_value.replace("'", "''")); + item->setText(column, new_value); + } + } + } field->setDefaultValue(item->text(column)); if(!m_bNewTable) callRenameColumn = true; - break; + } + break; case kCheck: field->setCheck(item->text(column)); if(!m_bNewTable) diff --git a/src/sqlitetypes.cpp b/src/sqlitetypes.cpp index 3bccce9c..67329672 100644 --- a/src/sqlitetypes.cpp +++ b/src/sqlitetypes.cpp @@ -15,7 +15,7 @@ QString Field::toString(const QString& indent, const QString& sep) const if(m_notnull) str += " NOT NULL"; if(!m_defaultvalue.isEmpty()) - str += QString(" DEFAULT '%1'").arg(m_defaultvalue); + str += QString(" DEFAULT %1").arg(m_defaultvalue); if(!m_check.isEmpty()) str += " CHECK(" + m_check + ")"; if(m_autoincrement)