mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-01-20 02:50:46 -06:00
Preference for quoting identifier mechanism
A new option is added to the SQL tab in Preferences for choosing which quoting characters must be used by the application when it inserts an identifier in SQL code. The three options supported by SQLite are available. Default quoting characters have been changed from `Grave accents` to "Double quotes" (SQL standard). This options also affect the highlighting of double quoted strings: when the SQL standard is selected, double quoted expressions are highlighted as identifiers, otherwise as literal strings.
This commit is contained in:
@@ -1990,6 +1990,8 @@ void MainWindow::reloadSettings()
|
||||
|
||||
// Reload remote dock settings
|
||||
remoteDock->reloadSettings();
|
||||
|
||||
sqlb::setIdentifierQuoting(static_cast<sqlb::escapeQuoting>(Settings::getValue("editor", "identifier_quotes").toInt()));
|
||||
}
|
||||
|
||||
void MainWindow::checkNewVersion(const QString& versionstring, const QString& url)
|
||||
|
||||
@@ -168,6 +168,7 @@ void PreferencesDialog::loadSettings()
|
||||
ui->spinTabSize->setValue(Settings::getValue("editor", "tabsize").toInt());
|
||||
ui->spinLogFontSize->setValue(Settings::getValue("log", "fontsize").toInt());
|
||||
ui->wrapComboBox->setCurrentIndex(Settings::getValue("editor", "wrap_lines").toInt());
|
||||
ui->quoteComboBox->setCurrentIndex(Settings::getValue("editor", "identifier_quotes").toInt());
|
||||
ui->checkAutoCompletion->setChecked(Settings::getValue("editor", "auto_completion").toBool());
|
||||
ui->checkCompleteUpper->setEnabled(Settings::getValue("editor", "auto_completion").toBool());
|
||||
ui->checkCompleteUpper->setChecked(Settings::getValue("editor", "upper_keywords").toBool());
|
||||
@@ -223,6 +224,7 @@ void PreferencesDialog::saveSettings()
|
||||
Settings::setValue("editor", "tabsize", ui->spinTabSize->value());
|
||||
Settings::setValue("log", "fontsize", ui->spinLogFontSize->value());
|
||||
Settings::setValue("editor", "wrap_lines", ui->wrapComboBox->currentIndex());
|
||||
Settings::setValue("editor", "identifier_quotes", ui->quoteComboBox->currentIndex());
|
||||
Settings::setValue("editor", "auto_completion", ui->checkAutoCompletion->isChecked());
|
||||
Settings::setValue("editor", "upper_keywords", ui->checkCompleteUpper->isChecked());
|
||||
Settings::setValue("editor", "error_indicators", ui->checkErrorIndicators->isChecked());
|
||||
|
||||
@@ -920,6 +920,19 @@
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QFormLayout" name="formLayout_2">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label_14">
|
||||
<property name="text">
|
||||
<string>SQL editor &font</string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>comboEditorFont</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QFontComboBox" name="comboEditorFont"/>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_6">
|
||||
<property name="text">
|
||||
@@ -977,93 +990,13 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label_14">
|
||||
<item row="4" column="0">
|
||||
<widget class="QLabel" name="wrapLabel">
|
||||
<property name="text">
|
||||
<string>SQL editor &font</string>
|
||||
<string>Wrap lines</string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>comboEditorFont</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QFontComboBox" name="comboEditorFont"/>
|
||||
</item>
|
||||
<item row="5" column="0">
|
||||
<widget class="QLabel" name="label_20">
|
||||
<property name="text">
|
||||
<string>Code co&mpletion</string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>checkAutoCompletion</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="1">
|
||||
<widget class="QCheckBox" name="checkAutoCompletion">
|
||||
<property name="text">
|
||||
<string>enabled</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="0">
|
||||
<widget class="QLabel" name="label_24">
|
||||
<property name="text">
|
||||
<string>Keywords in &UPPER CASE</string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>checkCompleteUpper</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="1">
|
||||
<widget class="QCheckBox" name="checkCompleteUpper">
|
||||
<property name="toolTip">
|
||||
<string>When set, the SQL keywords are completed in UPPER CASE letters.</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>enabled</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" column="0">
|
||||
<widget class="QLabel" name="label_15">
|
||||
<property name="text">
|
||||
<string>Error indicators</string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>checkErrorIndicators</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" column="1">
|
||||
<widget class="QCheckBox" name="checkErrorIndicators">
|
||||
<property name="toolTip">
|
||||
<string>When set, the SQL code lines that caused errors during the last execution are highlighted and the results frame indicates the error in the background</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>enabled</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="8" column="0">
|
||||
<widget class="QLabel" name="label_10">
|
||||
<property name="text">
|
||||
<string>Hori&zontal tiling</string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>checkHorizontalTiling</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="8" column="1">
|
||||
<widget class="QCheckBox" name="checkHorizontalTiling">
|
||||
<property name="toolTip">
|
||||
<string>If enabled the SQL code editor and the result table view are shown side by side instead of one over the other.</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>enabled</string>
|
||||
<cstring>wrapComboBox</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@@ -1091,13 +1024,115 @@
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<widget class="QLabel" name="wrapLabel">
|
||||
<item row="5" column="1">
|
||||
<widget class="QComboBox" name="quoteComboBox">
|
||||
<property name="toolTip">
|
||||
<string>Choose the quoting mechanism used by the application for identifiers in SQL code.</string>
|
||||
</property>
|
||||
<property name="whatsThis">
|
||||
<string/>
|
||||
</property>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>"Double quotes"</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>`Grave accents`</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>[Square brackets]</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="0">
|
||||
<widget class="QLabel" name="label_20">
|
||||
<property name="text">
|
||||
<string>Wrap lines</string>
|
||||
<string>Code co&mpletion</string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>wrapComboBox</cstring>
|
||||
<cstring>checkAutoCompletion</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="1">
|
||||
<widget class="QCheckBox" name="checkAutoCompletion">
|
||||
<property name="text">
|
||||
<string>enabled</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" column="0">
|
||||
<widget class="QLabel" name="label_24">
|
||||
<property name="text">
|
||||
<string>Keywords in &UPPER CASE</string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>checkCompleteUpper</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" column="1">
|
||||
<widget class="QCheckBox" name="checkCompleteUpper">
|
||||
<property name="toolTip">
|
||||
<string>When set, the SQL keywords are completed in UPPER CASE letters.</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>enabled</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="8" column="0">
|
||||
<widget class="QLabel" name="label_15">
|
||||
<property name="text">
|
||||
<string>Error indicators</string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>checkErrorIndicators</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="8" column="1">
|
||||
<widget class="QCheckBox" name="checkErrorIndicators">
|
||||
<property name="toolTip">
|
||||
<string>When set, the SQL code lines that caused errors during the last execution are highlighted and the results frame indicates the error in the background</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>enabled</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="9" column="0">
|
||||
<widget class="QLabel" name="label_10">
|
||||
<property name="text">
|
||||
<string>Hori&zontal tiling</string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>checkHorizontalTiling</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="9" column="1">
|
||||
<widget class="QCheckBox" name="checkHorizontalTiling">
|
||||
<property name="toolTip">
|
||||
<string>If enabled the SQL code editor and the result table view are shown side by side instead of one over the other.</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>enabled</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="0">
|
||||
<widget class="QLabel" name="label_25">
|
||||
<property name="text">
|
||||
<string>Quotes for identifiers</string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>quoteComboBox</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
||||
@@ -294,6 +294,10 @@ QVariant Settings::getDefaultValue(const QString& group, const QString& name)
|
||||
if(group == "editor" && name == "wrap_lines")
|
||||
return 0; // QsciScintilla::WrapNone
|
||||
|
||||
// editor/identifier_quotes
|
||||
if(group == "editor" && name == "identifier_quotes")
|
||||
return 0; // sqlb::DoubleQuotes
|
||||
|
||||
// editor/auto_completion?
|
||||
if(group == "editor" && name == "auto_completion")
|
||||
return true;
|
||||
|
||||
@@ -11,9 +11,26 @@ namespace sqlb {
|
||||
|
||||
QStringList Field::Datatypes = QStringList() << "INTEGER" << "TEXT" << "BLOB" << "REAL" << "NUMERIC";
|
||||
|
||||
escapeQuoting customQuoting = DoubleQuotes;
|
||||
|
||||
void setIdentifierQuoting(escapeQuoting toQuoting)
|
||||
{
|
||||
customQuoting = toQuoting;
|
||||
}
|
||||
|
||||
QString escapeIdentifier(QString id)
|
||||
{
|
||||
return '`' + id.replace('`', "``") + '`';
|
||||
switch(customQuoting) {
|
||||
case DoubleQuotes:
|
||||
return '"' + id.replace('"', "\"\"") + '"';
|
||||
case GraveAccents:
|
||||
return '`' + id.replace('`', "``") + '`';
|
||||
case SquareBrackets:
|
||||
// There aren't any escaping possibilities for square brackets inside the identifier,
|
||||
// so we rely on the user to not enter these characters when this kind of quoting is
|
||||
// selected.
|
||||
return '[' + id + ']';
|
||||
}
|
||||
}
|
||||
|
||||
QStringList fieldVectorToFieldNames(const FieldVector& vector)
|
||||
|
||||
@@ -38,6 +38,15 @@ uint qHash(const QVector<T>& key, uint seed = 0)
|
||||
}
|
||||
#endif
|
||||
|
||||
enum escapeQuoting {
|
||||
DoubleQuotes,
|
||||
GraveAccents,
|
||||
SquareBrackets
|
||||
};
|
||||
|
||||
// Set quoting style for escapeIdentifier
|
||||
void setIdentifierQuoting(escapeQuoting toQuoting);
|
||||
|
||||
QString escapeIdentifier(QString id);
|
||||
|
||||
class ObjectIdentifier
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#include "sqlitetypes.h"
|
||||
#include "sqltextedit.h"
|
||||
#include "Settings.h"
|
||||
#include "SqlUiLexer.h"
|
||||
@@ -49,8 +50,18 @@ void SqlTextEdit::reloadSettings()
|
||||
setupSyntaxHighlightingFormat(sqlLexer, "keyword", QsciLexerSQL::Keyword);
|
||||
setupSyntaxHighlightingFormat(sqlLexer, "table", QsciLexerSQL::KeywordSet6);
|
||||
setupSyntaxHighlightingFormat(sqlLexer, "function", QsciLexerSQL::KeywordSet7);
|
||||
setupSyntaxHighlightingFormat(sqlLexer, "string", QsciLexerSQL::DoubleQuotedString);
|
||||
setupSyntaxHighlightingFormat(sqlLexer, "string", QsciLexerSQL::SingleQuotedString);
|
||||
|
||||
// Highlight double quote strings as identifier or as literal string depending on user preference
|
||||
switch(static_cast<sqlb::escapeQuoting>(Settings::getValue("editor", "identifier_quotes").toInt())) {
|
||||
case sqlb::DoubleQuotes:
|
||||
setupSyntaxHighlightingFormat(sqlLexer, "identifier", QsciLexerSQL::DoubleQuotedString);
|
||||
break;
|
||||
case sqlb::GraveAccents:
|
||||
case sqlb::SquareBrackets:
|
||||
setupSyntaxHighlightingFormat(sqlLexer, "string", QsciLexerSQL::DoubleQuotedString);
|
||||
break;
|
||||
}
|
||||
setupSyntaxHighlightingFormat(sqlLexer, "identifier", QsciLexerSQL::Identifier);
|
||||
setupSyntaxHighlightingFormat(sqlLexer, "identifier", QsciLexerSQL::QuotedIdentifier);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user