From 5991a144a115d33de9628497ecdd38843ed1f182 Mon Sep 17 00:00:00 2001 From: Martin Kleusberg Date: Sat, 29 Nov 2014 17:36:54 +0100 Subject: [PATCH] EditTableDialog: Don't quote function in default value when marked '=()' When entering a default value like "=(strftime('%s','now'))", don't quote it but remove the '=' character and use the following expression as default value. See issue #166. --- src/EditTableDialog.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/EditTableDialog.cpp b/src/EditTableDialog.cpp index bb337a72..60e09083 100644 --- a/src/EditTableDialog.cpp +++ b/src/EditTableDialog.cpp @@ -344,19 +344,24 @@ void EditTableDialog::itemChanged(QTreeWidgetItem *item, int column) 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('"')))) + QChar first_char = new_value.trimmed().at(0); + if(!((first_char == '\'' || first_char == '"') && new_value.trimmed().endsWith(first_char))) { bool is_numeric; new_value.toDouble(&is_numeric); if(!is_numeric) { - new_value = QString("'%1'").arg(new_value.replace("'", "''")); - item->setText(column, new_value); + if(new_value.trimmed().startsWith("=(") && new_value.trimmed().endsWith(')')) + { + new_value = new_value.trimmed().mid(1); // Leave the brackets as they are needed for a valid SQL expression + } else { + new_value = QString("'%1'").arg(new_value.replace("'", "''")); + item->setText(column, new_value); + } } } } - field->setDefaultValue(item->text(column)); + field->setDefaultValue(new_value); if(!m_bNewTable) callRenameColumn = true; }