aboutsummaryrefslogtreecommitdiffstats
path: root/Plugins/SqlEnterpriseFormatter
diff options
context:
space:
mode:
authorLibravatarUnit 193 <unit193@ubuntu.com>2016-06-13 18:42:57 -0400
committerLibravatarUnit 193 <unit193@ubuntu.com>2016-06-13 18:42:57 -0400
commit65d5f68cc6dc81799c5a5d90400a2c1f0dd02547 (patch)
tree6f245ba901b87ef42fed69965aea22f5eea6b590 /Plugins/SqlEnterpriseFormatter
parentaeb6bad01630d325a4e768e798a7a6d44e18fdaf (diff)
parent5d9314f134ddd3dc4c853e398ac90ba247fb2e4f (diff)
Merge tag 'upstream/3.1.0'
Upstream version 3.1.0 # gpg: Signature made Mon 13 Jun 2016 06:42:54 PM EDT using RSA key ID EBE9BD91 # gpg: Good signature from "Unit 193 <unit193@gmail.com>" # gpg: aka "Unit 193 <unit193@ninthfloor.org>" # gpg: aka "Unit 193 <unit193@ubuntu.com>" # gpg: aka "Unit 193 <unit193@ninthfloor.com>"
Diffstat (limited to 'Plugins/SqlEnterpriseFormatter')
-rw-r--r--Plugins/SqlEnterpriseFormatter/SqlEnterpriseFormatter_de.ts7
-rw-r--r--Plugins/SqlEnterpriseFormatter/SqlEnterpriseFormatter_es.ts7
-rw-r--r--Plugins/SqlEnterpriseFormatter/SqlEnterpriseFormatter_fr.ts20
-rw-r--r--Plugins/SqlEnterpriseFormatter/SqlEnterpriseFormatter_it.qmbin0 -> 23 bytes
-rw-r--r--Plugins/SqlEnterpriseFormatter/SqlEnterpriseFormatter_it.ts7
-rw-r--r--Plugins/SqlEnterpriseFormatter/SqlEnterpriseFormatter_pl.ts15
-rw-r--r--Plugins/SqlEnterpriseFormatter/SqlEnterpriseFormatter_pt_BR.ts7
-rw-r--r--Plugins/SqlEnterpriseFormatter/SqlEnterpriseFormatter_ru.qmbin5623 -> 6230 bytes
-rw-r--r--Plugins/SqlEnterpriseFormatter/SqlEnterpriseFormatter_ru.ts3
-rw-r--r--Plugins/SqlEnterpriseFormatter/SqlEnterpriseFormatter_sk.ts7
-rw-r--r--Plugins/SqlEnterpriseFormatter/SqlEnterpriseFormatter_zh_CN.ts7
-rw-r--r--Plugins/SqlEnterpriseFormatter/formatcreateview.cpp8
-rw-r--r--Plugins/SqlEnterpriseFormatter/formatexpr.cpp11
-rw-r--r--Plugins/SqlEnterpriseFormatter/formatraise.cpp2
-rw-r--r--Plugins/SqlEnterpriseFormatter/formatselect.cpp14
-rw-r--r--Plugins/SqlEnterpriseFormatter/formatstatement.cpp146
-rw-r--r--Plugins/SqlEnterpriseFormatter/formatstatement.h134
-rw-r--r--Plugins/SqlEnterpriseFormatter/formatupdate.cpp4
-rw-r--r--Plugins/SqlEnterpriseFormatter/sqlenterpriseformatter.cpp1
-rw-r--r--Plugins/SqlEnterpriseFormatter/sqlenterpriseformatter.ui22
20 files changed, 227 insertions, 195 deletions
diff --git a/Plugins/SqlEnterpriseFormatter/SqlEnterpriseFormatter_de.ts b/Plugins/SqlEnterpriseFormatter/SqlEnterpriseFormatter_de.ts
index 37751d0..b391360 100644
--- a/Plugins/SqlEnterpriseFormatter/SqlEnterpriseFormatter_de.ts
+++ b/Plugins/SqlEnterpriseFormatter/SqlEnterpriseFormatter_de.ts
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
-<TS version="2.1" language="de_DE">
+<TS version="2.0" language="de_DE">
<context>
<name>QObject</name>
<message>
@@ -210,11 +210,6 @@
<translation type="unfinished"></translation>
</message>
<message>
- <location filename="sqlenterpriseformatter.ui" line="647"/>
- <source>SqlEnterpriseFormatter.CommentMarkers</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>
diff --git a/Plugins/SqlEnterpriseFormatter/SqlEnterpriseFormatter_es.ts b/Plugins/SqlEnterpriseFormatter/SqlEnterpriseFormatter_es.ts
index b0b5eed..4910c3f 100644
--- a/Plugins/SqlEnterpriseFormatter/SqlEnterpriseFormatter_es.ts
+++ b/Plugins/SqlEnterpriseFormatter/SqlEnterpriseFormatter_es.ts
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
-<TS version="2.1" language="es_ES">
+<TS version="2.0" language="es_ES">
<context>
<name>QObject</name>
<message>
@@ -210,11 +210,6 @@
<translation type="unfinished"></translation>
</message>
<message>
- <location filename="sqlenterpriseformatter.ui" line="647"/>
- <source>SqlEnterpriseFormatter.CommentMarkers</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>
diff --git a/Plugins/SqlEnterpriseFormatter/SqlEnterpriseFormatter_fr.ts b/Plugins/SqlEnterpriseFormatter/SqlEnterpriseFormatter_fr.ts
index d0e62f7..6e90f84 100644
--- a/Plugins/SqlEnterpriseFormatter/SqlEnterpriseFormatter_fr.ts
+++ b/Plugins/SqlEnterpriseFormatter/SqlEnterpriseFormatter_fr.ts
@@ -41,12 +41,12 @@
<message>
<location filename="sqlenterpriseformatter.ui" line="160"/>
<source>Before opening parenthesis in column definitions</source>
- <translation>Avant l&apos;ouverture des parenthèses dans la définition de la colonne</translation>
+ <translation>Avant l&rsquo;ouverture des parenthèses dans la définition de la colonne</translation>
</message>
<message>
<location filename="sqlenterpriseformatter.ui" line="170"/>
<source>After opening parenthesis in column definitions</source>
- <translation>Après l&apos;ouverture des parenthèses dans la définition de la colonne</translation>
+ <translation>Après l&rsquo;ouverture des parenthèses dans la définition de la colonne</translation>
</message>
<message>
<location filename="sqlenterpriseformatter.ui" line="180"/>
@@ -61,22 +61,22 @@
<message>
<location filename="sqlenterpriseformatter.ui" line="200"/>
<source>Before opening parenthesis in expressions</source>
- <translation>Avant l&apos;ouverture des parenthèses dans l&apos;expression</translation>
+ <translation>Avant l&rsquo;ouverture des parenthèses dans l&rsquo;expression</translation>
</message>
<message>
<location filename="sqlenterpriseformatter.ui" line="210"/>
<source>After opening parenthesis in expressions</source>
- <translation>Après l&apos;ouverture des parenthèses dans l&apos;expression</translation>
+ <translation>Après l&rsquo;ouverture des parenthèses dans l&rsquo;expression</translation>
</message>
<message>
<location filename="sqlenterpriseformatter.ui" line="220"/>
<source>Before closing parenthesis in expressions</source>
- <translation>Avant la fermeture des parenthèses dans l&apos;expression</translation>
+ <translation>Avant la fermeture des parenthèses dans l&rsquo;expression</translation>
</message>
<message>
<location filename="sqlenterpriseformatter.ui" line="230"/>
<source>After closing parenthesis in expressions</source>
- <translation>Après la fermeture des parenthèses dans l&apos;expression</translation>
+ <translation>Après la fermeture des parenthèses dans l&rsquo;expression</translation>
</message>
<message>
<location filename="sqlenterpriseformatter.ui" line="240"/>
@@ -96,7 +96,7 @@
<message>
<location filename="sqlenterpriseformatter.ui" line="270"/>
<source>After comma in expressions</source>
- <translation>Après la virgule dans l&apos;exoression</translation>
+ <translation>Après la virgule dans l&rsquo;exoression</translation>
</message>
<message>
<location filename="sqlenterpriseformatter.ui" line="280"/>
@@ -127,12 +127,12 @@
<message>
<location filename="sqlenterpriseformatter.ui" line="412"/>
<source>Before opening parenthesis</source>
- <translation>Avant l&apos;ouverture des parenthèses</translation>
+ <translation>Avant l&rsquo;ouverture des parenthèses</translation>
</message>
<message>
<location filename="sqlenterpriseformatter.ui" line="422"/>
<source>After opening parenthesis</source>
- <translation>Après l&apos;ouverture des parenthèses</translation>
+ <translation>Après l&rsquo;ouverture des parenthèses</translation>
</message>
<message>
<location filename="sqlenterpriseformatter.ui" line="432"/>
@@ -147,7 +147,7 @@
<message>
<location filename="sqlenterpriseformatter.ui" line="452"/>
<source>No space between SQL function name and opening parenthesis</source>
- <translation>aucun espance entre le nom de la fonction SQL et l&apos;ouverture des paranthèses</translation>
+ <translation>aucun espance entre le nom de la fonction SQL et l&rsquo;ouverture des paranthèses</translation>
</message>
<message>
<location filename="sqlenterpriseformatter.ui" line="462"/>
diff --git a/Plugins/SqlEnterpriseFormatter/SqlEnterpriseFormatter_it.qm b/Plugins/SqlEnterpriseFormatter/SqlEnterpriseFormatter_it.qm
new file mode 100644
index 0000000..9dad8df
--- /dev/null
+++ b/Plugins/SqlEnterpriseFormatter/SqlEnterpriseFormatter_it.qm
Binary files differ
diff --git a/Plugins/SqlEnterpriseFormatter/SqlEnterpriseFormatter_it.ts b/Plugins/SqlEnterpriseFormatter/SqlEnterpriseFormatter_it.ts
index 9e721a4..93a7ba6 100644
--- a/Plugins/SqlEnterpriseFormatter/SqlEnterpriseFormatter_it.ts
+++ b/Plugins/SqlEnterpriseFormatter/SqlEnterpriseFormatter_it.ts
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
-<TS version="2.1" language="it_IT">
+<TS version="2.0" language="it_IT">
<context>
<name>QObject</name>
<message>
@@ -210,11 +210,6 @@
<translation type="unfinished"></translation>
</message>
<message>
- <location filename="sqlenterpriseformatter.ui" line="647"/>
- <source>SqlEnterpriseFormatter.CommentMarkers</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>
diff --git a/Plugins/SqlEnterpriseFormatter/SqlEnterpriseFormatter_pl.ts b/Plugins/SqlEnterpriseFormatter/SqlEnterpriseFormatter_pl.ts
index 2c03a46..f85f8f0 100644
--- a/Plugins/SqlEnterpriseFormatter/SqlEnterpriseFormatter_pl.ts
+++ b/Plugins/SqlEnterpriseFormatter/SqlEnterpriseFormatter_pl.ts
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
-<TS version="2.1" language="pl_PL">
+<TS version="2.0" language="pl_PL">
<context>
<name>QObject</name>
<message>
@@ -203,27 +203,22 @@
<message>
<location filename="sqlenterpriseformatter.ui" line="631"/>
<source>Comments</source>
- <translation type="unfinished"></translation>
+ <translation>Komentarze</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="647"/>
- <source>SqlEnterpriseFormatter.CommentMarkers</source>
- <translation type="unfinished"></translation>
+ <translation>Preferowany znacznik komentarzy (gdzie możliwy):</translation>
</message>
<message>
<location filename="sqlenterpriseformatter.ui" line="654"/>
<source>Move all comments to the line end</source>
- <translation type="unfinished"></translation>
+ <translation>Przenieś wszystkie komentarze na koniec linii</translation>
</message>
<message>
<location filename="sqlenterpriseformatter.ui" line="664"/>
<source>Line up comments at the line end</source>
- <translation type="unfinished"></translation>
+ <translation>Wyrównaj komentarze na końcu linii</translation>
</message>
<message>
<location filename="sqlenterpriseformatter.ui" line="695"/>
diff --git a/Plugins/SqlEnterpriseFormatter/SqlEnterpriseFormatter_pt_BR.ts b/Plugins/SqlEnterpriseFormatter/SqlEnterpriseFormatter_pt_BR.ts
index a408ffc..920e9cc 100644
--- a/Plugins/SqlEnterpriseFormatter/SqlEnterpriseFormatter_pt_BR.ts
+++ b/Plugins/SqlEnterpriseFormatter/SqlEnterpriseFormatter_pt_BR.ts
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
-<TS version="2.1" language="pt_BR">
+<TS version="2.0" language="pt_BR">
<context>
<name>QObject</name>
<message>
@@ -210,11 +210,6 @@
<translation type="unfinished"></translation>
</message>
<message>
- <location filename="sqlenterpriseformatter.ui" line="647"/>
- <source>SqlEnterpriseFormatter.CommentMarkers</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>
diff --git a/Plugins/SqlEnterpriseFormatter/SqlEnterpriseFormatter_ru.qm b/Plugins/SqlEnterpriseFormatter/SqlEnterpriseFormatter_ru.qm
index 1b13dc9..e4d3522 100644
--- a/Plugins/SqlEnterpriseFormatter/SqlEnterpriseFormatter_ru.qm
+++ b/Plugins/SqlEnterpriseFormatter/SqlEnterpriseFormatter_ru.qm
Binary files differ
diff --git a/Plugins/SqlEnterpriseFormatter/SqlEnterpriseFormatter_ru.ts b/Plugins/SqlEnterpriseFormatter/SqlEnterpriseFormatter_ru.ts
index 4e5e98d..9436651 100644
--- a/Plugins/SqlEnterpriseFormatter/SqlEnterpriseFormatter_ru.ts
+++ b/Plugins/SqlEnterpriseFormatter/SqlEnterpriseFormatter_ru.ts
@@ -210,9 +210,8 @@
<translation>Предпочитаемый символ комментирования (где применимо):</translation>
</message>
<message>
- <location filename="sqlenterpriseformatter.ui" line="647"/>
<source>SqlEnterpriseFormatter.CommentMarkers</source>
- <translation>SqlEnterpriseFormatter.CommentMarkers</translation>
+ <translation type="obsolete">SqlEnterpriseFormatter.CommentMarkers</translation>
</message>
<message>
<location filename="sqlenterpriseformatter.ui" line="654"/>
diff --git a/Plugins/SqlEnterpriseFormatter/SqlEnterpriseFormatter_sk.ts b/Plugins/SqlEnterpriseFormatter/SqlEnterpriseFormatter_sk.ts
index 37a42a4..ff7f588 100644
--- a/Plugins/SqlEnterpriseFormatter/SqlEnterpriseFormatter_sk.ts
+++ b/Plugins/SqlEnterpriseFormatter/SqlEnterpriseFormatter_sk.ts
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
-<TS version="2.1" language="sk_SK">
+<TS version="2.0" language="sk_SK">
<context>
<name>QObject</name>
<message>
@@ -210,11 +210,6 @@
<translation type="unfinished"></translation>
</message>
<message>
- <location filename="sqlenterpriseformatter.ui" line="647"/>
- <source>SqlEnterpriseFormatter.CommentMarkers</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>
diff --git a/Plugins/SqlEnterpriseFormatter/SqlEnterpriseFormatter_zh_CN.ts b/Plugins/SqlEnterpriseFormatter/SqlEnterpriseFormatter_zh_CN.ts
index d1a361b..0405ee5 100644
--- a/Plugins/SqlEnterpriseFormatter/SqlEnterpriseFormatter_zh_CN.ts
+++ b/Plugins/SqlEnterpriseFormatter/SqlEnterpriseFormatter_zh_CN.ts
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
-<TS version="2.1" language="zh_CN">
+<TS version="2.0" language="zh_CN">
<context>
<name>QObject</name>
<message>
@@ -210,11 +210,6 @@
<translation type="unfinished"></translation>
</message>
<message>
- <location filename="sqlenterpriseformatter.ui" line="647"/>
- <source>SqlEnterpriseFormatter.CommentMarkers</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>
diff --git a/Plugins/SqlEnterpriseFormatter/formatcreateview.cpp b/Plugins/SqlEnterpriseFormatter/formatcreateview.cpp
index e8d0351..52a49a2 100644
--- a/Plugins/SqlEnterpriseFormatter/formatcreateview.cpp
+++ b/Plugins/SqlEnterpriseFormatter/formatcreateview.cpp
@@ -1,6 +1,7 @@
#include "formatcreateview.h"
#include "parser/ast/sqlitecreateview.h"
#include "parser/ast/sqliteselect.h"
+#include "parser/ast/sqliteindexedcolumn.h"
FormatCreateView::FormatCreateView(SqliteCreateView* createView) :
createView(createView)
@@ -23,5 +24,10 @@ void FormatCreateView::formatInternal()
if (dialect == Dialect::Sqlite3 && !createView->database.isNull())
withId(createView->database).withIdDot();
- withId(createView->view).withKeyword("AS").withNewLine().withIncrIndent().withStatement(createView->select).withSemicolon().withDecrIndent();
+ withId(createView->view);
+
+ if (createView->columns.size() > 0)
+ withParDefLeft().withStatementList<SqliteIndexedColumn>(createView->columns).withParDefRight();
+
+ withKeyword("AS").withNewLine().withIncrIndent().withStatement(createView->select).withSemicolon().withDecrIndent();
}
diff --git a/Plugins/SqlEnterpriseFormatter/formatexpr.cpp b/Plugins/SqlEnterpriseFormatter/formatexpr.cpp
index ec5d4d6..b1a36b5 100644
--- a/Plugins/SqlEnterpriseFormatter/formatexpr.cpp
+++ b/Plugins/SqlEnterpriseFormatter/formatexpr.cpp
@@ -51,7 +51,8 @@ void FormatExpr::formatInternal()
{
// Operator can be a keyword
QString opStr = cfg->SqlEnterpriseFormatter.UppercaseKeywords.get() ? expr->unaryOp.toUpper() : expr->unaryOp.toLower();
- withOperator(opStr).withStatement(expr->expr1, "unaryOp");
+ withOperator(opStr, FormatToken::Flag::NO_SPACE_BEFORE|FormatToken::Flag::NO_SPACE_AFTER);
+ withStatement(expr->expr1, "unaryOp");
break;
}
case SqliteExpr::Mode::BINARY_OP:
@@ -76,7 +77,11 @@ void FormatExpr::formatInternal()
if (expr->distinctKw)
withKeyword("DISTINCT");
- withStatementList(expr->exprList, "funcArgs", FormatStatement::ListSeparator::EXPR_COMMA).withParFuncRight();
+ if (expr->star)
+ withOperator("*").withParFuncRight();
+ else
+ withStatementList(expr->exprList, "funcArgs", FormatStatement::ListSeparator::EXPR_COMMA).withParFuncRight();
+
break;
}
case SqliteExpr::Mode::SUB_EXPR:
@@ -157,7 +162,7 @@ void FormatExpr::formatInternal()
}
else if (expr->exprList.size() > 0)
{
- withParExprLeft().withStatementList(expr->exprList).withParExprRight();
+ withParExprLeft().withStatementList(expr->exprList, FormatToken::Flag::NO_NEWLINE_AFTER).withParExprRight();
}
else
{
diff --git a/Plugins/SqlEnterpriseFormatter/formatraise.cpp b/Plugins/SqlEnterpriseFormatter/formatraise.cpp
index be3787e..a347f28 100644
--- a/Plugins/SqlEnterpriseFormatter/formatraise.cpp
+++ b/Plugins/SqlEnterpriseFormatter/formatraise.cpp
@@ -10,7 +10,7 @@ void FormatRaise::formatInternal()
{
withKeyword("RAISE").withParFuncLeft().withKeyword(SqliteRaise::raiseType(raise->type));
if (raise->type != SqliteRaise::Type::IGNORE)
- withCommaOper().withString(raise->message);
+ withCommaOper().withStringOrId(raise->message);
withParFuncRight();
}
diff --git a/Plugins/SqlEnterpriseFormatter/formatselect.cpp b/Plugins/SqlEnterpriseFormatter/formatselect.cpp
index 4d2a229..d2173c5 100644
--- a/Plugins/SqlEnterpriseFormatter/formatselect.cpp
+++ b/Plugins/SqlEnterpriseFormatter/formatselect.cpp
@@ -23,8 +23,14 @@ void FormatSelect::formatInternal()
withNewLine().withKeyword("UNION").withNewLine();
break;
case SqliteSelect::CompoundOperator::UNION_ALL:
- withNewLine().withKeyword("UNION ALL").withNewLine();
+ {
+ if (core->valuesMode)
+ withListComma(FormatToken::Flag::NO_NEWLINE_BEFORE);
+ else
+ withNewLine().withKeyword("UNION ALL").withNewLine();
+
break;
+ }
case SqliteSelect::CompoundOperator::INTERSECT:
withNewLine().withKeyword("INTERSECT").withNewLine();
break;
@@ -52,7 +58,11 @@ void FormatSelectCore::formatInternal()
if (core->valuesMode)
{
- withKeyword("VALUES").withParDefLeft().withStatementList(core->resultColumns).withParDefRight();
+ SqliteSelect* select = dynamic_cast<SqliteSelect*>(core->parentStatement());
+ if (select->coreSelects.indexOf(core) == 0) // this is first core in series of cores of values mode of the SELECT
+ withKeyword("VALUES");
+
+ withParDefLeft().withStatementList(core->resultColumns).withParDefRight();
return;
}
diff --git a/Plugins/SqlEnterpriseFormatter/formatstatement.cpp b/Plugins/SqlEnterpriseFormatter/formatstatement.cpp
index e5eaed4..9702d32 100644
--- a/Plugins/SqlEnterpriseFormatter/formatstatement.cpp
+++ b/Plugins/SqlEnterpriseFormatter/formatstatement.cpp
@@ -23,6 +23,7 @@
#include "formatdelete.h"
#include "formatupdate.h"
#include "formatdropindex.h"
+#include "formatpragma.h"
#include "formatdroptable.h"
#include "formatdroptrigger.h"
#include "formatdropview.h"
@@ -55,6 +56,7 @@
#include "parser/ast/sqlitedroptrigger.h"
#include "parser/ast/sqlitedropview.h"
#include "parser/ast/sqliteorderby.h"
+#include "parser/ast/sqlitepragma.h"
#include "sqlenterpriseformatter.h"
#include "common/utils_sql.h"
#include "common/global.h"
@@ -149,6 +151,7 @@ FormatStatement *FormatStatement::forQuery(SqliteStatement *query)
FORMATTER_FACTORY_ENTRY(query, SqliteDropTrigger, FormatDropTrigger);
FORMATTER_FACTORY_ENTRY(query, SqliteDropView, FormatDropView);
FORMATTER_FACTORY_ENTRY(query, SqliteOrderBy, FormatOrderBy);
+ FORMATTER_FACTORY_ENTRY(query, SqlitePragma, FormatPragma);
if (stmt)
stmt->dialect = query->dialect;
@@ -182,9 +185,9 @@ FormatStatement& FormatStatement::withId(const QString& id)
return *this;
}
-FormatStatement& FormatStatement::withOperator(const QString& oper)
+FormatStatement& FormatStatement::withOperator(const QString& oper, FormatToken::Flags flags)
{
- withToken(FormatToken::OPERATOR, oper);
+ withToken(FormatToken::OPERATOR, oper, flags);
return *this;
}
@@ -194,15 +197,15 @@ FormatStatement&FormatStatement::withStringOrId(const QString& id)
return *this;
}
-FormatStatement& FormatStatement::withIdDot()
+FormatStatement& FormatStatement::withIdDot(FormatToken::Flags flags)
{
- withToken(FormatToken::ID_DOT, ".");
+ withToken(FormatToken::ID_DOT, ".", flags);
return *this;
}
-FormatStatement& FormatStatement::withStar()
+FormatStatement& FormatStatement::withStar(FormatToken::Flags flags)
{
- withToken(FormatToken::STAR, "*");
+ withToken(FormatToken::STAR, "*", flags);
return *this;
}
@@ -236,60 +239,60 @@ FormatStatement& FormatStatement::withBindParam(const QString& name)
return *this;
}
-FormatStatement& FormatStatement::withParDefLeft()
+FormatStatement& FormatStatement::withParDefLeft(FormatToken::Flags flags)
{
- withToken(FormatToken::PAR_DEF_LEFT, "(");
+ withToken(FormatToken::PAR_DEF_LEFT, "(", flags);
return *this;
}
-FormatStatement& FormatStatement::withParDefRight()
+FormatStatement& FormatStatement::withParDefRight(FormatToken::Flags flags)
{
- withToken(FormatToken::PAR_DEF_RIGHT, ")");
+ withToken(FormatToken::PAR_DEF_RIGHT, ")", flags);
return *this;
}
-FormatStatement& FormatStatement::withParExprLeft()
+FormatStatement& FormatStatement::withParExprLeft(FormatToken::Flags flags)
{
- withToken(FormatToken::PAR_EXPR_LEFT, "(");
+ withToken(FormatToken::PAR_EXPR_LEFT, "(", flags);
return *this;
}
-FormatStatement& FormatStatement::withParExprRight()
+FormatStatement& FormatStatement::withParExprRight(FormatToken::Flags flags)
{
- withToken(FormatToken::PAR_EXPR_RIGHT, ")");
+ withToken(FormatToken::PAR_EXPR_RIGHT, ")", flags);
return *this;
}
-FormatStatement& FormatStatement::withParFuncLeft()
+FormatStatement& FormatStatement::withParFuncLeft(FormatToken::Flags flags)
{
- withToken(FormatToken::PAR_FUNC_LEFT, "(");
+ withToken(FormatToken::PAR_FUNC_LEFT, "(", flags);
return *this;
}
-FormatStatement& FormatStatement::withParFuncRight()
+FormatStatement& FormatStatement::withParFuncRight(FormatToken::Flags flags)
{
- withToken(FormatToken::PAR_FUNC_RIGHT, ")");
+ withToken(FormatToken::PAR_FUNC_RIGHT, ")", flags);
return *this;
}
-FormatStatement& FormatStatement::withSemicolon()
+FormatStatement& FormatStatement::withSemicolon(FormatToken::Flags flags)
{
FormatToken* lastRealToken = getLastRealToken();
if ((lastRealToken && lastRealToken->type != FormatToken::SEMICOLON) || tokens.size() == 0)
- withToken(FormatToken::SEMICOLON, ";");
+ withToken(FormatToken::SEMICOLON, ";", flags);
return *this;
}
-FormatStatement& FormatStatement::withListComma()
+FormatStatement& FormatStatement::withListComma(FormatToken::Flags flags)
{
- withToken(FormatToken::COMMA_LIST, ",");
+ withToken(FormatToken::COMMA_LIST, ",", flags);
return *this;
}
-FormatStatement& FormatStatement::withCommaOper()
+FormatStatement& FormatStatement::withCommaOper(FormatToken::Flags flags)
{
- withToken(FormatToken::COMMA_OPER, ",");
+ withToken(FormatToken::COMMA_OPER, ",", flags);
return *this;
}
@@ -431,21 +434,21 @@ FormatStatement&FormatStatement::markKeywordLineUp(const QString& keyword, const
return *this;
}
-FormatStatement&FormatStatement::withSeparator(FormatStatement::ListSeparator sep)
+FormatStatement&FormatStatement::withSeparator(FormatStatement::ListSeparator sep, FormatToken::Flags flags)
{
switch (sep)
{
case ListSeparator::COMMA:
- withListComma();
+ withListComma(flags);
break;
case ListSeparator::EXPR_COMMA:
- withCommaOper();
+ withCommaOper(flags);
break;
case ListSeparator::NEW_LINE:
withNewLine();
break;
case ListSeparator::SEMICOLON:
- withSemicolon();
+ withSemicolon(flags);
break;
case ListSeparator::NONE:
break;
@@ -484,13 +487,20 @@ FormatStatement& FormatStatement::withIdList(const QStringList& names, const QSt
return *this;
}
-void FormatStatement::withToken(FormatStatement::FormatToken::Type type, const QVariant& value, const QVariant& additionalValue)
+FormatStatement::FormatToken* FormatStatement::withToken(FormatStatement::FormatToken::Type type, const QVariant& value, const QVariant& additionalValue, FormatToken::Flags flags)
{
FormatToken* token = new FormatToken;
token->type = type;
token->value = value;
token->additionalValue = additionalValue;
+ token->flags = flags;
tokens << token;
+ return token;
+}
+
+FormatStatement::FormatToken* FormatStatement::withToken(FormatStatement::FormatToken::Type type, const QVariant& value, FormatToken::Flags flags)
+{
+ return withToken(type, value, QVariant(), flags);
}
void FormatStatement::cleanup()
@@ -578,7 +588,6 @@ QString FormatStatement::detokenize()
break;
}
case FormatToken::STAR:
- case FormatToken::FLOAT:
case FormatToken::INTEGER:
case FormatToken::BLOB:
case FormatToken::BIND_PARAM:
@@ -588,14 +597,20 @@ QString FormatStatement::detokenize()
line += token->value.toString();
break;
}
+ case FormatToken::FLOAT:
+ {
+ applyIndent();
+ line += doubleToString(token->value.toDouble());
+ break;
+ }
case FormatToken::OPERATOR:
{
bool spaceAdded = endsWithSpace() || applyIndent();
- if (cfg->SqlEnterpriseFormatter.SpaceBeforeMathOp.get() && !spaceAdded)
+ if (cfg->SqlEnterpriseFormatter.SpaceBeforeMathOp.get() && !spaceAdded && !token->flags.testFlag(FormatToken::Flag::NO_SPACE_BEFORE))
line += SPACE;
line += token->value.toString();
- if (cfg->SqlEnterpriseFormatter.SpaceAfterMathOp.get())
+ if (cfg->SqlEnterpriseFormatter.SpaceAfterMathOp.get() && !token->flags.testFlag(FormatToken::Flag::NO_SPACE_AFTER))
line += SPACE;
break;
@@ -603,66 +618,66 @@ QString FormatStatement::detokenize()
case FormatToken::ID_DOT:
{
bool spaceAdded = endsWithSpace() || applyIndent();
- if (cfg->SqlEnterpriseFormatter.SpaceBeforeDot.get() && !spaceAdded)
+ if (cfg->SqlEnterpriseFormatter.SpaceBeforeDot.get() && !spaceAdded && !token->flags.testFlag(FormatToken::Flag::NO_SPACE_BEFORE))
line += SPACE;
line += token->value.toString();
- if (cfg->SqlEnterpriseFormatter.SpaceAfterDot.get())
+ if (cfg->SqlEnterpriseFormatter.SpaceAfterDot.get() && !token->flags.testFlag(FormatToken::Flag::NO_SPACE_AFTER))
line += SPACE;
break;
}
case FormatToken::PAR_DEF_LEFT:
{
- bool spaceBefore = cfg->SqlEnterpriseFormatter.SpaceBeforeOpenPar.get();
- bool spaceAfter = cfg->SqlEnterpriseFormatter.SpaceAfterOpenPar.get();
- bool nlBefore = cfg->SqlEnterpriseFormatter.NlBeforeOpenParDef.get();
- bool nlAfter = cfg->SqlEnterpriseFormatter.NlAfterOpenParDef.get();
+ bool spaceBefore = cfg->SqlEnterpriseFormatter.SpaceBeforeOpenPar.get() && !token->flags.testFlag(FormatToken::Flag::NO_SPACE_BEFORE);
+ bool spaceAfter = cfg->SqlEnterpriseFormatter.SpaceAfterOpenPar.get() && !token->flags.testFlag(FormatToken::Flag::NO_SPACE_AFTER);
+ bool nlBefore = cfg->SqlEnterpriseFormatter.NlBeforeOpenParDef.get() && !token->flags.testFlag(FormatToken::Flag::NO_NEWLINE_BEFORE);
+ bool nlAfter = cfg->SqlEnterpriseFormatter.NlAfterOpenParDef.get() && !token->flags.testFlag(FormatToken::Flag::NO_NEWLINE_AFTER);
detokenizeLeftPar(token, spaceBefore, spaceAfter, nlBefore, nlAfter);
break;
}
case FormatToken::PAR_DEF_RIGHT:
{
- bool spaceBefore = cfg->SqlEnterpriseFormatter.SpaceBeforeClosePar.get();
- bool spaceAfter = cfg->SqlEnterpriseFormatter.SpaceAfterClosePar.get();
- bool nlBefore = cfg->SqlEnterpriseFormatter.NlBeforeCloseParDef.get();
- bool nlAfter = cfg->SqlEnterpriseFormatter.NlAfterCloseParDef.get();
+ bool spaceBefore = cfg->SqlEnterpriseFormatter.SpaceBeforeClosePar.get() && !token->flags.testFlag(FormatToken::Flag::NO_SPACE_BEFORE);
+ bool spaceAfter = cfg->SqlEnterpriseFormatter.SpaceAfterClosePar.get() && !token->flags.testFlag(FormatToken::Flag::NO_SPACE_AFTER);
+ bool nlBefore = cfg->SqlEnterpriseFormatter.NlBeforeCloseParDef.get() && !token->flags.testFlag(FormatToken::Flag::NO_NEWLINE_BEFORE);
+ bool nlAfter = cfg->SqlEnterpriseFormatter.NlAfterCloseParDef.get() && !token->flags.testFlag(FormatToken::Flag::NO_NEWLINE_AFTER);
detokenizeRightPar(token, spaceBefore, spaceAfter, nlBefore, nlAfter);
break;
}
case FormatToken::PAR_EXPR_LEFT:
{
- bool spaceBefore = cfg->SqlEnterpriseFormatter.SpaceBeforeOpenPar.get();
- bool spaceAfter = cfg->SqlEnterpriseFormatter.SpaceAfterOpenPar.get();
- bool nlBefore = cfg->SqlEnterpriseFormatter.NlBeforeOpenParExpr.get();
- bool nlAfter = cfg->SqlEnterpriseFormatter.NlAfterOpenParExpr.get();
+ bool spaceBefore = cfg->SqlEnterpriseFormatter.SpaceBeforeOpenPar.get() && !token->flags.testFlag(FormatToken::Flag::NO_SPACE_BEFORE);
+ bool spaceAfter = cfg->SqlEnterpriseFormatter.SpaceAfterOpenPar.get() && !token->flags.testFlag(FormatToken::Flag::NO_SPACE_AFTER);
+ bool nlBefore = cfg->SqlEnterpriseFormatter.NlBeforeOpenParExpr.get() && !token->flags.testFlag(FormatToken::Flag::NO_NEWLINE_BEFORE);
+ bool nlAfter = cfg->SqlEnterpriseFormatter.NlAfterOpenParExpr.get() && !token->flags.testFlag(FormatToken::Flag::NO_NEWLINE_AFTER);
detokenizeLeftPar(token, spaceBefore, spaceAfter, nlBefore, nlAfter);
break;
}
case FormatToken::PAR_EXPR_RIGHT:
{
- bool spaceBefore = cfg->SqlEnterpriseFormatter.SpaceBeforeClosePar.get();
- bool spaceAfter = cfg->SqlEnterpriseFormatter.SpaceAfterClosePar.get();
- bool nlBefore = cfg->SqlEnterpriseFormatter.NlBeforeCloseParExpr.get();
- bool nlAfter = cfg->SqlEnterpriseFormatter.NlAfterCloseParExpr.get();
+ bool spaceBefore = cfg->SqlEnterpriseFormatter.SpaceBeforeClosePar.get() && !token->flags.testFlag(FormatToken::Flag::NO_SPACE_BEFORE);
+ bool spaceAfter = cfg->SqlEnterpriseFormatter.SpaceAfterClosePar.get() && !token->flags.testFlag(FormatToken::Flag::NO_SPACE_AFTER);
+ bool nlBefore = cfg->SqlEnterpriseFormatter.NlBeforeCloseParExpr.get() && !token->flags.testFlag(FormatToken::Flag::NO_NEWLINE_BEFORE);
+ bool nlAfter = cfg->SqlEnterpriseFormatter.NlAfterCloseParExpr.get() && !token->flags.testFlag(FormatToken::Flag::NO_NEWLINE_AFTER);
detokenizeRightPar(token, spaceBefore, spaceAfter, nlBefore, nlAfter);
break;
}
case FormatToken::PAR_FUNC_LEFT:
{
- bool spaceBefore = cfg->SqlEnterpriseFormatter.SpaceBeforeOpenPar.get() && !cfg->SqlEnterpriseFormatter.NoSpaceAfterFunctionName.get();
- bool spaceAfter = cfg->SqlEnterpriseFormatter.SpaceAfterOpenPar.get();
- bool nlBefore = cfg->SqlEnterpriseFormatter.NlBeforeOpenParExpr.get();
- bool nlAfter = cfg->SqlEnterpriseFormatter.NlAfterOpenParExpr.get();
+ bool spaceBefore = cfg->SqlEnterpriseFormatter.SpaceBeforeOpenPar.get() && !token->flags.testFlag(FormatToken::Flag::NO_SPACE_BEFORE) && !cfg->SqlEnterpriseFormatter.NoSpaceAfterFunctionName.get();
+ bool spaceAfter = cfg->SqlEnterpriseFormatter.SpaceAfterOpenPar.get() && !token->flags.testFlag(FormatToken::Flag::NO_SPACE_AFTER);
+ bool nlBefore = cfg->SqlEnterpriseFormatter.NlBeforeOpenParExpr.get() && !token->flags.testFlag(FormatToken::Flag::NO_NEWLINE_BEFORE);
+ bool nlAfter = cfg->SqlEnterpriseFormatter.NlAfterOpenParExpr.get() && !token->flags.testFlag(FormatToken::Flag::NO_NEWLINE_AFTER);
detokenizeLeftPar(token, spaceBefore, spaceAfter, nlBefore, nlAfter);
break;
}
case FormatToken::PAR_FUNC_RIGHT:
{
- bool spaceBefore = cfg->SqlEnterpriseFormatter.SpaceBeforeClosePar.get();
- bool spaceAfter = cfg->SqlEnterpriseFormatter.SpaceAfterClosePar.get();
- bool nlBefore = cfg->SqlEnterpriseFormatter.NlBeforeCloseParExpr.get();
- bool nlAfter = cfg->SqlEnterpriseFormatter.NlAfterCloseParExpr.get();
+ bool spaceBefore = cfg->SqlEnterpriseFormatter.SpaceBeforeClosePar.get() && !token->flags.testFlag(FormatToken::Flag::NO_SPACE_BEFORE);
+ bool spaceAfter = cfg->SqlEnterpriseFormatter.SpaceAfterClosePar.get() && !token->flags.testFlag(FormatToken::Flag::NO_SPACE_AFTER);
+ bool nlBefore = cfg->SqlEnterpriseFormatter.NlBeforeCloseParExpr.get() && !token->flags.testFlag(FormatToken::Flag::NO_NEWLINE_BEFORE);
+ bool nlAfter = cfg->SqlEnterpriseFormatter.NlAfterCloseParExpr.get() && !token->flags.testFlag(FormatToken::Flag::NO_NEWLINE_AFTER);
detokenizeRightPar(token, spaceBefore, spaceAfter, nlBefore, nlAfter);
break;
}
@@ -689,7 +704,7 @@ QString FormatStatement::detokenize()
}
case FormatToken::COMMA_LIST:
{
- if (cfg->SqlEnterpriseFormatter.SpaceNeverBeforeComma.get())
+ if (cfg->SqlEnterpriseFormatter.SpaceNeverBeforeComma.get() || token->flags.testFlag(FormatToken::Flag::NO_NEWLINE_BEFORE))
{
removeAllSpaces();
}
@@ -701,7 +716,7 @@ QString FormatStatement::detokenize()
}
line += token->value.toString();
- if (cfg->SqlEnterpriseFormatter.NlAfterComma.get())
+ if (cfg->SqlEnterpriseFormatter.NlAfterComma.get() && !token->flags.testFlag(FormatToken::Flag::NO_NEWLINE_AFTER))
newLine();
else if (cfg->SqlEnterpriseFormatter.SpaceAfterCommaInList.get())
line += SPACE;
@@ -722,7 +737,7 @@ QString FormatStatement::detokenize()
}
line += token->value.toString();
- if (cfg->SqlEnterpriseFormatter.NlAfterCommaInExpr.get())
+ if (cfg->SqlEnterpriseFormatter.NlAfterCommaInExpr.get() && !token->flags.testFlag(FormatToken::Flag::NO_NEWLINE_AFTER))
newLine();
else if (cfg->SqlEnterpriseFormatter.SpaceAfterCommaInList.get())
line += SPACE;
@@ -924,6 +939,11 @@ FormatStatement::FormatToken* FormatStatement::getLastRealToken(bool skipNewLine
return nullptr;
}
+FormatStatement::FormatToken* FormatStatement::getLastToken()
+{
+ return tokens.last();
+}
+
void FormatStatement::detokenizeLeftPar(FormatToken* token, bool spaceBefore, bool spaceAfter, bool nlBefore, bool nlAfter)
{
bool spaceAdded = endsWithSpace();
@@ -1059,9 +1079,9 @@ bool FormatStatement::willStartWithNewLine(FormatStatement::FormatToken* token)
void FormatStatement::formatId(const QString& value)
{
if (cfg->SqlEnterpriseFormatter.AlwaysUseNameWrapping.get())
- line += wrapObjName(value, dialect, wrapper);
+ line += wrapObjName(value, dialect, true, wrapper);
else
- line += wrapObjIfNeeded(value, dialect, wrapper);
+ line += wrapObjIfNeeded(value, dialect, true, wrapper);
}
FormatStatement* FormatStatement::forQuery(SqliteStatement* query, Dialect dialect, NameWrapper wrapper, Cfg::SqlEnterpriseFormatterConfig* cfg)
diff --git a/Plugins/SqlEnterpriseFormatter/formatstatement.h b/Plugins/SqlEnterpriseFormatter/formatstatement.h
index 6bd0fea..427efe9 100644
--- a/Plugins/SqlEnterpriseFormatter/formatstatement.h
+++ b/Plugins/SqlEnterpriseFormatter/formatstatement.h
@@ -16,6 +16,58 @@
class FormatStatement
{
public:
+ struct FormatToken
+ {
+ enum Type
+ {
+ KEYWORD,
+ LINED_UP_KEYWORD,
+ ID,
+ STRING_OR_ID,
+ OPERATOR,
+ STAR,
+ FLOAT,
+ STRING,
+ INTEGER,
+ BLOB,
+ BIND_PARAM,
+ ID_DOT,
+ PAR_DEF_LEFT,
+ PAR_DEF_RIGHT,
+ PAR_EXPR_LEFT,
+ PAR_EXPR_RIGHT,
+ PAR_FUNC_LEFT,
+ PAR_FUNC_RIGHT,
+ SEMICOLON,
+ COMMA_LIST,
+ COMMA_OPER, // for example in LIMIT
+ FUNC_ID,
+ DATA_TYPE,
+ NEW_LINE,
+ INDENT_MARKER,
+ INCR_INDENT,
+ SET_INDENT,
+ DECR_INDENT,
+ MARK_KEYWORD_LINEUP
+ };
+
+ enum Flag
+ {
+ NO_FLAG = 0x00,
+ NO_SPACE_BEFORE = 0x01,
+ NO_SPACE_AFTER = 0x02,
+ NO_NEWLINE_BEFORE = 0x04,
+ NO_NEWLINE_AFTER = 0x08
+ };
+
+ Q_DECLARE_FLAGS(Flags, Flag)
+
+ Type type;
+ QVariant value;
+ QVariant additionalValue;
+ Flags flags;
+ };
+
enum class ListSeparator
{
NONE,
@@ -40,24 +92,24 @@ class FormatStatement
FormatStatement& withLinedUpKeyword(const QString& kw, const QString& lineUpName = QString());
FormatStatement& withId(const QString& id);
FormatStatement& withIdList(const QStringList& names, const QString& indentName = QString(), ListSeparator sep = ListSeparator::COMMA);
- FormatStatement& withOperator(const QString& oper);
+ FormatStatement& withOperator(const QString& oper, FormatToken::Flags flags = FormatToken::Flag::NO_FLAG);
FormatStatement& withStringOrId(const QString& id);
- FormatStatement& withIdDot();
- FormatStatement& withStar();
+ FormatStatement& withIdDot(FormatToken::Flags flags = FormatToken::Flag::NO_FLAG);
+ FormatStatement& withStar(FormatToken::Flags flags = FormatToken::Flag::NO_FLAG);
FormatStatement& withFloat(double value);
FormatStatement& withInteger(qint64 value);
FormatStatement& withString(const QString& value);
FormatStatement& withBlob(const QString& value);
FormatStatement& withBindParam(const QString& name);
- FormatStatement& withParDefLeft();
- FormatStatement& withParDefRight();
- FormatStatement& withParExprLeft();
- FormatStatement& withParExprRight();
- FormatStatement& withParFuncLeft();
- FormatStatement& withParFuncRight();
- FormatStatement& withSemicolon();
- FormatStatement& withListComma();
- FormatStatement& withCommaOper();
+ FormatStatement& withParDefLeft(FormatToken::Flags flags = FormatToken::Flag::NO_FLAG);
+ FormatStatement& withParDefRight(FormatToken::Flags flags = FormatToken::Flag::NO_FLAG);
+ FormatStatement& withParExprLeft(FormatToken::Flags flags = FormatToken::Flag::NO_FLAG);
+ FormatStatement& withParExprRight(FormatToken::Flags flags = FormatToken::Flag::NO_FLAG);
+ FormatStatement& withParFuncLeft(FormatToken::Flags flags = FormatToken::Flag::NO_FLAG);
+ FormatStatement& withParFuncRight(FormatToken::Flags flags = FormatToken::Flag::NO_FLAG);
+ FormatStatement& withSemicolon(FormatToken::Flags flags = FormatToken::Flag::NO_FLAG);
+ FormatStatement& withListComma(FormatToken::Flags flags = FormatToken::Flag::NO_FLAG);
+ FormatStatement& withCommaOper(FormatToken::Flags flags = FormatToken::Flag::NO_FLAG);
FormatStatement& withSortOrder(SqliteSortOrder sortOrder);
FormatStatement& withConflict(SqliteConflictAlgo onConflict);
FormatStatement& withFuncId(const QString& func);
@@ -71,11 +123,17 @@ class FormatStatement
FormatStatement& withIncrIndent(const QString& name = QString());
FormatStatement& withDecrIndent();
FormatStatement& markKeywordLineUp(const QString& keyword, const QString& lineUpName = QString());
- FormatStatement& withSeparator(ListSeparator sep);
+ FormatStatement& withSeparator(ListSeparator sep, FormatToken::Flags flags = FormatToken::Flag::NO_FLAG);
+
+ template <class T>
+ FormatStatement& withStatementList(QList<T*> stmtList, FormatToken::Flags flags)
+ {
+ return withStatementList(stmtList, QString(), ListSeparator::COMMA, nullptr, flags);
+ }
template <class T>
FormatStatement& withStatementList(QList<T*> stmtList, const QString& indentName = QString(), ListSeparator sep = ListSeparator::COMMA,
- FormatStatementEnricher enricher = nullptr)
+ FormatStatementEnricher enricher = nullptr, FormatToken::Flags flags = FormatToken::Flag::NO_FLAG)
{
if (!indentName.isNull())
markAndKeepIndent(indentName);
@@ -84,7 +142,7 @@ class FormatStatement
foreach (T* stmt, stmtList)
{
if (!first)
- withSeparator(sep);
+ withSeparator(sep, flags);
withStatement(stmt, QString(), enricher);
first = false;
@@ -113,47 +171,8 @@ class FormatStatement
Cfg::SqlEnterpriseFormatterConfig* cfg = nullptr;
private:
- struct FormatToken
- {
- enum Type
- {
- KEYWORD,
- LINED_UP_KEYWORD,
- ID,
- STRING_OR_ID,
- OPERATOR,
- STAR,
- FLOAT,
- STRING,
- INTEGER,
- BLOB,
- BIND_PARAM,
- ID_DOT,
- PAR_DEF_LEFT,
- PAR_DEF_RIGHT,
- PAR_EXPR_LEFT,
- PAR_EXPR_RIGHT,
- PAR_FUNC_LEFT,
- PAR_FUNC_RIGHT,
- SEMICOLON,
- COMMA_LIST,
- COMMA_OPER, // for example in LIMIT
- FUNC_ID,
- DATA_TYPE,
- NEW_LINE,
- INDENT_MARKER,
- INCR_INDENT,
- SET_INDENT,
- DECR_INDENT,
- MARK_KEYWORD_LINEUP
- };
-
- Type type;
- QVariant value;
- QVariant additionalValue;
- };
-
- void withToken(FormatToken::Type type, const QVariant& value, const QVariant& additionalValue = QVariant());
+ FormatToken* withToken(FormatToken::Type type, const QVariant& value, const QVariant& additionalValue = QVariant(), FormatToken::Flags flags = FormatToken::Flag::NO_FLAG);
+ FormatToken* withToken(FormatToken::Type type, const QVariant& value, FormatToken::Flags flags);
void cleanup();
void buildTokens();
bool applyIndent();
@@ -166,6 +185,7 @@ class FormatStatement
void setIndent(int newIndent);
bool endsWithSpace();
FormatToken* getLastRealToken(bool skipNewLines = false);
+ FormatToken* getLastToken();
QString detokenize();
void detokenizeLeftPar(FormatToken* token, bool spaceBefore, bool spaceAfter, bool nlBefore, bool nlAfter);
void detokenizeRightPar(FormatToken* token, bool spaceBefore, bool spaceAfter, bool nlBefore, bool nlAfter);
@@ -197,4 +217,6 @@ class FormatStatement
static const QString NEWLINE;
};
+Q_DECLARE_OPERATORS_FOR_FLAGS(FormatStatement::FormatToken::Flags)
+
#endif // FORMATSTATEMENT_H
diff --git a/Plugins/SqlEnterpriseFormatter/formatupdate.cpp b/Plugins/SqlEnterpriseFormatter/formatupdate.cpp
index 54ce927..2670966 100644
--- a/Plugins/SqlEnterpriseFormatter/formatupdate.cpp
+++ b/Plugins/SqlEnterpriseFormatter/formatupdate.cpp
@@ -31,6 +31,8 @@ void FormatUpdate::formatInternal()
withNewLine().withLinedUpKeyword("SET");
+ markAndKeepIndent("updateColumns");
+
bool first = true;
foreach (const SqliteUpdate::ColumnAndValue& keyVal, upd->keyValueMap)
{
@@ -41,6 +43,8 @@ void FormatUpdate::formatInternal()
first = false;
}
+ withDecrIndent();
+
if (upd->where)
withNewLine().withLinedUpKeyword("WHERE").withStatement(upd->where);
diff --git a/Plugins/SqlEnterpriseFormatter/sqlenterpriseformatter.cpp b/Plugins/SqlEnterpriseFormatter/sqlenterpriseformatter.cpp
index a08f95c..8bed056 100644
--- a/Plugins/SqlEnterpriseFormatter/sqlenterpriseformatter.cpp
+++ b/Plugins/SqlEnterpriseFormatter/sqlenterpriseformatter.cpp
@@ -255,6 +255,7 @@ TokenList SqlEnterpriseFormatter::optimizeEndLineComments(const TokenList &input
void SqlEnterpriseFormatter::indentMultiLineComments(const TokenList &inputTokens)
{
+ UNUSED(inputTokens);
// TODO
}
diff --git a/Plugins/SqlEnterpriseFormatter/sqlenterpriseformatter.ui b/Plugins/SqlEnterpriseFormatter/sqlenterpriseformatter.ui
index b21de64..b32e253 100644
--- a/Plugins/SqlEnterpriseFormatter/sqlenterpriseformatter.ui
+++ b/Plugins/SqlEnterpriseFormatter/sqlenterpriseformatter.ui
@@ -39,7 +39,7 @@
</sizepolicy>
</property>
<property name="currentIndex">
- <number>0</number>
+ <number>4</number>
</property>
<widget class="QWidget" name="indentTab">
<attribute name="title">
@@ -134,8 +134,8 @@
<rect>
<x>0</x>
<y>0</y>
- <width>390</width>
- <height>299</height>
+ <width>576</width>
+ <height>420</height>
</rect>
</property>
<property name="styleSheet">
@@ -366,8 +366,8 @@
<rect>
<x>0</x>
<y>0</y>
- <width>418</width>
- <height>278</height>
+ <width>576</width>
+ <height>390</height>
</rect>
</property>
<property name="styleSheet">
@@ -644,7 +644,7 @@
<string notr="true">SqlEnterpriseFormatter.PreferredCommentMarker</string>
</property>
<property name="modelName" stdset="0">
- <string>SqlEnterpriseFormatter.CommentMarkers</string>
+ <string notr="true">SqlEnterpriseFormatter.CommentMarkers</string>
</property>
</widget>
</item>
@@ -713,15 +713,15 @@
</widget>
<customwidgets>
<customwidget>
- <class>ConfigComboBox</class>
- <extends>QComboBox</extends>
- <header>common/configcombobox.h</header>
- </customwidget>
- <customwidget>
<class>SqlView</class>
<extends>QPlainTextEdit</extends>
<header>sqlview.h</header>
</customwidget>
+ <customwidget>
+ <class>ConfigComboBox</class>
+ <extends>QComboBox</extends>
+ <header>common/configcombobox.h</header>
+ </customwidget>
</customwidgets>
<resources/>
<connections/>