EditTableDialog: Fix handling of default values

Fix the handling of default values in the Edit Table dialog by doing two
things: First, change the sqlb::Field class so that it doesn't put quotes
around any default values no matter what. This breaks for example NULL
default values but also causes invalid syntax if the default value is
already in quotes. Secondly, change the Edit Table dialog itself to
double check if the user should've put quotes around their default value
but hasn't. In this case add them automatically.

See issues #64 and #126.
This commit is contained in:
Martin Kleusberg
2014-10-15 12:45:43 +02:00
parent dea0a65385
commit c29702a1b9
2 changed files with 24 additions and 2 deletions

View File

@@ -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)