diff options
Diffstat (limited to 'Plugins/SqlEnterpriseFormatter')
15 files changed, 352 insertions, 12 deletions
diff --git a/Plugins/SqlEnterpriseFormatter/SqlEnterpriseFormatter.pro b/Plugins/SqlEnterpriseFormatter/SqlEnterpriseFormatter.pro index 2d5b88c..a00ab89 100644 --- a/Plugins/SqlEnterpriseFormatter/SqlEnterpriseFormatter.pro +++ b/Plugins/SqlEnterpriseFormatter/SqlEnterpriseFormatter.pro @@ -49,7 +49,8 @@ SOURCES += sqlenterpriseformatter.cpp \ formatrollback.cpp \ formatsavepoint.cpp \ formatvacuum.cpp \ - formatorderby.cpp + formatorderby.cpp \ + formatupsert.cpp HEADERS += sqlenterpriseformatter.h\ sqlenterpriseformatter_global.h \ @@ -88,7 +89,8 @@ HEADERS += sqlenterpriseformatter.h\ formatrollback.h \ formatsavepoint.h \ formatvacuum.h \ - formatorderby.h + formatorderby.h \ + formatupsert.h OTHER_FILES += \ sqlenterpriseformatter.json @@ -100,7 +102,8 @@ RESOURCES += \ sqlenterpriseformatter.qrc -TRANSLATIONS += SqlEnterpriseFormatter_de.ts \ +TRANSLATIONS += SqlEnterpriseFormatter_ro_RO.ts \ + SqlEnterpriseFormatter_de.ts \ SqlEnterpriseFormatter_it.ts \ SqlEnterpriseFormatter_zh_CN.ts \ SqlEnterpriseFormatter_sk.ts \ @@ -124,3 +127,4 @@ TRANSLATIONS += SqlEnterpriseFormatter_de.ts \ + diff --git a/Plugins/SqlEnterpriseFormatter/SqlEnterpriseFormatter_fr.qm b/Plugins/SqlEnterpriseFormatter/SqlEnterpriseFormatter_fr.qm Binary files differindex 40423d9..974d221 100644 --- a/Plugins/SqlEnterpriseFormatter/SqlEnterpriseFormatter_fr.qm +++ b/Plugins/SqlEnterpriseFormatter/SqlEnterpriseFormatter_fr.qm diff --git a/Plugins/SqlEnterpriseFormatter/SqlEnterpriseFormatter_ro_RO.qm b/Plugins/SqlEnterpriseFormatter/SqlEnterpriseFormatter_ro_RO.qm Binary files differnew file mode 100644 index 0000000..2856eb9 --- /dev/null +++ b/Plugins/SqlEnterpriseFormatter/SqlEnterpriseFormatter_ro_RO.qm diff --git a/Plugins/SqlEnterpriseFormatter/SqlEnterpriseFormatter_ro_RO.ts b/Plugins/SqlEnterpriseFormatter/SqlEnterpriseFormatter_ro_RO.ts new file mode 100644 index 0000000..c1d1b7b --- /dev/null +++ b/Plugins/SqlEnterpriseFormatter/SqlEnterpriseFormatter_ro_RO.ts @@ -0,0 +1,228 @@ +<?xml version="1.0" encoding="utf-8"?> +<!DOCTYPE TS> +<TS version="2.1" language="ro_RO"> +<context> + <name>QObject</name> + <message> + <location filename="sqlenterpriseformatter.cpp" line="91"/> + <location filename="sqlenterpriseformatter.cpp" line="98"/> + <source>name</source> + <comment>example name wrapper</comment> + <translation type="unfinished"></translation> + </message> +</context> +<context> + <name>SqlEnterpriseFormatter</name> + <message> + <location filename="sqlenterpriseformatter.ui" line="46"/> + <source>Indentation</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="sqlenterpriseformatter.ui" line="58"/> + <source>Line up keywords in multi-line queries</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="sqlenterpriseformatter.ui" line="68"/> + <source>Indent contents of parenthesis block</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="sqlenterpriseformatter.ui" line="91"/> + <source>Tab size:</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="sqlenterpriseformatter.ui" line="106"/> + <source>New lines</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="sqlenterpriseformatter.ui" line="160"/> + <source>Before opening parenthesis in column definitions</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="sqlenterpriseformatter.ui" line="170"/> + <source>After opening parenthesis in column definitions</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="sqlenterpriseformatter.ui" line="180"/> + <source>Before closing parenthesis in column definitions</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="sqlenterpriseformatter.ui" line="190"/> + <source>After closing parenthesis in column definitions</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="sqlenterpriseformatter.ui" line="200"/> + <source>Before opening parenthesis in expressions</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="sqlenterpriseformatter.ui" line="210"/> + <source>After opening parenthesis in expressions</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="sqlenterpriseformatter.ui" line="220"/> + <source>Before closing parenthesis in expressions</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="sqlenterpriseformatter.ui" line="230"/> + <source>After closing parenthesis in expressions</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="sqlenterpriseformatter.ui" line="240"/> + <source>After JOIN keywords in FROM clause</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="sqlenterpriseformatter.ui" line="250"/> + <source>Put each column constraint in CREATE TABLE into new line</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="sqlenterpriseformatter.ui" line="260"/> + <source>After comma</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="sqlenterpriseformatter.ui" line="270"/> + <source>After comma in expressions</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="sqlenterpriseformatter.ui" line="280"/> + <source>After semicolon</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="sqlenterpriseformatter.ui" line="290"/> + <location filename="sqlenterpriseformatter.ui" line="512"/> + <source>Never before semicolon</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="sqlenterpriseformatter.ui" line="338"/> + <source>White spaces</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="sqlenterpriseformatter.ui" line="392"/> + <source>Before comma in lists</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="sqlenterpriseformatter.ui" line="402"/> + <source>After comma in lists</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="sqlenterpriseformatter.ui" line="412"/> + <source>Before opening parenthesis</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="sqlenterpriseformatter.ui" line="422"/> + <source>After opening parenthesis</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="sqlenterpriseformatter.ui" line="432"/> + <source>Before closing parenthesis</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="sqlenterpriseformatter.ui" line="442"/> + <source>After closing parenthesis</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="sqlenterpriseformatter.ui" line="452"/> + <source>No space between SQL function name and opening parenthesis</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="sqlenterpriseformatter.ui" line="462"/> + <source>Before dot operator (in path to database object)</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="sqlenterpriseformatter.ui" line="472"/> + <source>After dot operator (in path to database object)</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="sqlenterpriseformatter.ui" line="482"/> + <source>Before mathematical operator</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="sqlenterpriseformatter.ui" line="492"/> + <source>After mathematical operator</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="sqlenterpriseformatter.ui" line="502"/> + <source>Never before comma</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="sqlenterpriseformatter.ui" line="558"/> + <source>Names</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="sqlenterpriseformatter.ui" line="583"/> + <source>Preferred name wrapper</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="sqlenterpriseformatter.ui" line="600"/> + <source>Always use name wrapping</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="sqlenterpriseformatter.ui" line="610"/> + <source>Uppercase data type names</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="sqlenterpriseformatter.ui" line="620"/> + <source>Uppercase keywords</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="sqlenterpriseformatter.ui" line="631"/> + <source>Comments</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="sqlenterpriseformatter.ui" line="637"/> + <source>Preferred comment marker (where possible):</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="sqlenterpriseformatter.ui" line="654"/> + <source>Move all comments to the line end</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="sqlenterpriseformatter.ui" line="664"/> + <source>Line up comments at the line end</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="sqlenterpriseformatter.ui" line="695"/> + <source>Preview</source> + <translation type="unfinished"></translation> + </message> +</context> +</TS> diff --git a/Plugins/SqlEnterpriseFormatter/SqlEnterpriseFormatter_ru.qm b/Plugins/SqlEnterpriseFormatter/SqlEnterpriseFormatter_ru.qm Binary files differindex e4d3522..07f5b2e 100644 --- a/Plugins/SqlEnterpriseFormatter/SqlEnterpriseFormatter_ru.qm +++ b/Plugins/SqlEnterpriseFormatter/SqlEnterpriseFormatter_ru.qm diff --git a/Plugins/SqlEnterpriseFormatter/SqlEnterpriseFormatter_ru.ts b/Plugins/SqlEnterpriseFormatter/SqlEnterpriseFormatter_ru.ts index 8e942c9..54cf8ad 100644 --- a/Plugins/SqlEnterpriseFormatter/SqlEnterpriseFormatter_ru.ts +++ b/Plugins/SqlEnterpriseFormatter/SqlEnterpriseFormatter_ru.ts @@ -147,7 +147,7 @@ <message> <location filename="sqlenterpriseformatter.ui" line="452"/> <source>No space between SQL function name and opening parenthesis</source> - <translation>Не ставить пробел между именем функции SQL и открывающкй скобкой</translation> + <translation>Не ставить пробел между именем функции SQL и открывающей скобкой</translation> </message> <message> <location filename="sqlenterpriseformatter.ui" line="462"/> diff --git a/Plugins/SqlEnterpriseFormatter/formatcreatetable.cpp b/Plugins/SqlEnterpriseFormatter/formatcreatetable.cpp index d1f0996..6ac6226 100644 --- a/Plugins/SqlEnterpriseFormatter/formatcreatetable.cpp +++ b/Plugins/SqlEnterpriseFormatter/formatcreatetable.cpp @@ -48,7 +48,7 @@ void FormatCreateTable::formatColumns(const QList<SqliteCreateTable::Column*>& c int maxColNameIndent = 0; int maxColTypeIndent = 0; FormatColumnType* formatColType = nullptr; - foreach (SqliteCreateTable::Column* stmt, columns) + for (SqliteCreateTable::Column* stmt : columns) { maxColNameIndent = qMax(getColNameLength(stmt->name), maxColNameIndent); diff --git a/Plugins/SqlEnterpriseFormatter/formatinsert.cpp b/Plugins/SqlEnterpriseFormatter/formatinsert.cpp index 6c1e763..2a49cfd 100644 --- a/Plugins/SqlEnterpriseFormatter/formatinsert.cpp +++ b/Plugins/SqlEnterpriseFormatter/formatinsert.cpp @@ -1,6 +1,7 @@ #include "formatinsert.h" #include "parser/ast/sqliteselect.h" #include "parser/ast/sqliteinsert.h" +#include "parser/ast/sqliteupsert.h" #include "formatwith.h" FormatInsert::FormatInsert(SqliteInsert* insert) : @@ -49,7 +50,11 @@ void FormatInsert::formatInternal() { withKeyword("VALUES").withParDefLeft().withStatementList(insert->values).withParDefRight(); } + if (insert->upsert) + withStatement(insert->upsert); + withDecrIndent(); } + withSemicolon(); } diff --git a/Plugins/SqlEnterpriseFormatter/formatselect.cpp b/Plugins/SqlEnterpriseFormatter/formatselect.cpp index d2173c5..f5aa55e 100644 --- a/Plugins/SqlEnterpriseFormatter/formatselect.cpp +++ b/Plugins/SqlEnterpriseFormatter/formatselect.cpp @@ -142,11 +142,27 @@ void FormatSelectCoreSingleSource::formatInternal() withKeyword("AS"); withId(singleSource->alias); + } + + if (singleSource->indexedByKw) + withKeyword("INDEXED").withKeyword("BY").withId(singleSource->indexedBy); + else if (singleSource->notIndexedKw) + withKeyword("NOT").withKeyword("INDEXED"); + } + else if (!singleSource->funcName.isNull()) + { + if (!singleSource->database.isNull()) + withId(singleSource->database).withIdDot(); + + withId(singleSource->funcName).withParFuncLeft() + .withStatementList(singleSource->funcParams, "funcArgs", FormatStatement::ListSeparator::EXPR_COMMA).withParFuncRight(); - if (singleSource->indexedByKw) - withKeyword("INDEXED").withKeyword("BY").withId(singleSource->indexedBy); - else if (singleSource->notIndexedKw) - withKeyword("NOT").withKeyword("INDEXED"); + if (!singleSource->alias.isNull()) + { + if (singleSource->asKw) + withKeyword("AS"); + + withId(singleSource->alias); } } else if (singleSource->select) diff --git a/Plugins/SqlEnterpriseFormatter/formatstatement.cpp b/Plugins/SqlEnterpriseFormatter/formatstatement.cpp index 2faaa16..fbfec2b 100644 --- a/Plugins/SqlEnterpriseFormatter/formatstatement.cpp +++ b/Plugins/SqlEnterpriseFormatter/formatstatement.cpp @@ -28,6 +28,7 @@ #include "formatdroptrigger.h" #include "formatdropview.h" #include "formatorderby.h" +#include "formatupsert.h" #include "parser/ast/sqliteselect.h" #include "parser/ast/sqliteexpr.h" #include "parser/ast/sqlitelimit.h" @@ -57,6 +58,7 @@ #include "parser/ast/sqlitedropview.h" #include "parser/ast/sqliteorderby.h" #include "parser/ast/sqlitepragma.h" +#include "parser/ast/sqliteupsert.h" #include "sqlenterpriseformatter.h" #include "common/utils_sql.h" #include "common/global.h" @@ -132,6 +134,7 @@ FormatStatement *FormatStatement::forQuery(SqliteStatement *query) FORMATTER_FACTORY_ENTRY(query, SqliteColumnType, FormatColumnType); FORMATTER_FACTORY_ENTRY(query, SqliteIndexedColumn, FormatIndexedColumn); FORMATTER_FACTORY_ENTRY(query, SqliteInsert, FormatInsert); + FORMATTER_FACTORY_ENTRY(query, SqliteUpsert, FormatUpsert); FORMATTER_FACTORY_ENTRY(query, SqliteEmptyQuery, FormatEmpty); FORMATTER_FACTORY_ENTRY(query, SqliteAlterTable, FormatAlterTable); FORMATTER_FACTORY_ENTRY(query, SqliteAnalyze, FormatAnalyze); @@ -472,7 +475,7 @@ FormatStatement& FormatStatement::withIdList(const QStringList& names, const QSt markAndKeepIndent(indentName); bool first = true; - foreach (const QString& name, names) + for (const QString& name : names) { if (!first) withSeparator(sep); diff --git a/Plugins/SqlEnterpriseFormatter/formatupdate.cpp b/Plugins/SqlEnterpriseFormatter/formatupdate.cpp index 2670966..641c895 100644 --- a/Plugins/SqlEnterpriseFormatter/formatupdate.cpp +++ b/Plugins/SqlEnterpriseFormatter/formatupdate.cpp @@ -34,12 +34,16 @@ void FormatUpdate::formatInternal() markAndKeepIndent("updateColumns"); bool first = true; - foreach (const SqliteUpdate::ColumnAndValue& keyVal, upd->keyValueMap) + for (const SqliteUpdate::ColumnAndValue& keyVal : upd->keyValueMap) { if (!first) withListComma(); - withId(keyVal.first).withOperator("=").withStatement(keyVal.second); + if (keyVal.first.type() == QVariant::StringList) + withParDefLeft().withIdList(keyVal.first.toStringList()).withParDefRight().withOperator("=").withStatement(keyVal.second); + else + withId(keyVal.first.toString()).withOperator("=").withStatement(keyVal.second); + first = false; } diff --git a/Plugins/SqlEnterpriseFormatter/formatupsert.cpp b/Plugins/SqlEnterpriseFormatter/formatupsert.cpp new file mode 100644 index 0000000..70992f9 --- /dev/null +++ b/Plugins/SqlEnterpriseFormatter/formatupsert.cpp @@ -0,0 +1,49 @@ +#include "formatupsert.h" +#include "parser/ast/sqliteupsert.h" +#include "parser/ast/sqliteexpr.h" +#include "parser/ast/sqliteorderby.h" + +FormatUpsert::FormatUpsert(SqliteUpsert* upsert) : + upsert(upsert) +{ + +} + +void FormatUpsert::formatInternal() +{ + withKeyword("ON").withKeyword("CONFLICT"); + if (!upsert->conflictColumns.isEmpty()) + { + withParDefLeft().withStatementList(upsert->conflictColumns).withParDefRight(); + if (upsert->conflictWhere) + withKeyword("WHERE").withStatement(upsert->conflictWhere); + } + + withKeyword("DO"); + + if (upsert->doNothing) + { + withKeyword("NOTHING"); + } + else + { + withKeyword("UPDATE").withKeyword("SET"); + bool first = true; + for (const SqliteUpsert::ColumnAndValue& keyVal : upsert->keyValueMap) + { + if (!first) + withListComma(); + + if (keyVal.first.type() == QVariant::StringList) + withParDefLeft().withIdList(keyVal.first.toStringList()).withParDefRight().withOperator("=").withStatement(keyVal.second); + else + withId(keyVal.first.toString()).withOperator("=").withStatement(keyVal.second); + + first = false; + } + + if (upsert->setWhere) + withKeyword("WHERE").withStatement(upsert->setWhere); + } + +} diff --git a/Plugins/SqlEnterpriseFormatter/formatupsert.h b/Plugins/SqlEnterpriseFormatter/formatupsert.h new file mode 100644 index 0000000..3aca8f8 --- /dev/null +++ b/Plugins/SqlEnterpriseFormatter/formatupsert.h @@ -0,0 +1,19 @@ +#ifndef FORMATUPSERT_H +#define FORMATUPSERT_H + +#include "formatstatement.h" + +class SqliteUpsert; + +class FormatUpsert : public FormatStatement +{ + public: + FormatUpsert(SqliteUpsert* upsert); + + void formatInternal(); + + private: + SqliteUpsert* upsert = nullptr; +}; + +#endif // FORMATUPSERT_H diff --git a/Plugins/SqlEnterpriseFormatter/package.xml b/Plugins/SqlEnterpriseFormatter/package.xml new file mode 100644 index 0000000..643cd6a --- /dev/null +++ b/Plugins/SqlEnterpriseFormatter/package.xml @@ -0,0 +1,10 @@ +<?xml version="1.0"?>
+<Package>
+ <DisplayName>SQL enterprise formatter plugin</DisplayName>
+ <Description>Plugin for advanced, highly customizable SQL formatting.</Description>
+ <Version>%VERSION%</Version>
+ <ReleaseDate>%DATE%</ReleaseDate>
+ <Name>pl.com.salsoft.sqlitestudio.plugins.sqlenterpriseformatter</Name>
+ <Dependencies>pl.com.salsoft.sqlitestudio.plugins</Dependencies>
+ <Default>true</Default>
+</Package>
\ No newline at end of file diff --git a/Plugins/SqlEnterpriseFormatter/sqlenterpriseformatter.qrc b/Plugins/SqlEnterpriseFormatter/sqlenterpriseformatter.qrc index 839720f..6fde81d 100644 --- a/Plugins/SqlEnterpriseFormatter/sqlenterpriseformatter.qrc +++ b/Plugins/SqlEnterpriseFormatter/sqlenterpriseformatter.qrc @@ -3,6 +3,7 @@ <file>sqlenterpriseformatter.ui</file> </qresource> <qresource prefix="/msg"> + <file>SqlEnterpriseFormatter_ro_RO.qm</file> <file>SqlEnterpriseFormatter_de.qm</file> @@ -16,3 +17,4 @@ + |
