Skip to content

Commit 5991a14

Browse files
committed
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 sqlitebrowser#166.
1 parent 9e4a6df commit 5991a14

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/EditTableDialog.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -344,19 +344,24 @@ void EditTableDialog::itemChanged(QTreeWidgetItem *item, int column)
344344
new_value.compare("current_date", Qt::CaseInsensitive) &&
345345
new_value.compare("current_timestamp", Qt::CaseInsensitive))
346346
{
347-
if(!((new_value.trimmed().startsWith('\'') ||
348-
new_value.trimmed().startsWith('"')) && (new_value.trimmed().endsWith('\'') || new_value.trimmed().endsWith('"'))))
347+
QChar first_char = new_value.trimmed().at(0);
348+
if(!((first_char == '\'' || first_char == '"') && new_value.trimmed().endsWith(first_char)))
349349
{
350350
bool is_numeric;
351351
new_value.toDouble(&is_numeric);
352352
if(!is_numeric)
353353
{
354-
new_value = QString("'%1'").arg(new_value.replace("'", "''"));
355-
item->setText(column, new_value);
354+
if(new_value.trimmed().startsWith("=(") && new_value.trimmed().endsWith(')'))
355+
{
356+
new_value = new_value.trimmed().mid(1); // Leave the brackets as they are needed for a valid SQL expression
357+
} else {
358+
new_value = QString("'%1'").arg(new_value.replace("'", "''"));
359+
item->setText(column, new_value);
360+
}
356361
}
357362
}
358363
}
359-
field->setDefaultValue(item->text(column));
364+
field->setDefaultValue(new_value);
360365
if(!m_bNewTable)
361366
callRenameColumn = true;
362367
}

0 commit comments

Comments
 (0)