Skip to content

Commit 55c64a4

Browse files
author
Paweł Salawa
committed
#5407 SQLite updated to 3.51.1. Updated syntax files, AST and formatter to support syntax updates.
1 parent 068b10a commit 55c64a4

11 files changed

Lines changed: 3582 additions & 3362 deletions

File tree

ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# ChangeLog
22

33
### 3.4.18
4+
- CHANGE: #5407 SQLite updated to 3.51.1. Updated syntax files, AST and formatter to support syntax updates.
45
- BUGFIX: #5308 #5358 Fixed handling true/false literals in expressions and on/off/yes/no literals in PRAGMA values.
56
- BUGFIX: #5386 Fixed vertical scroll position when refreshing grid data view.
67
- BUGFIX: #5348 Fix name-based filtering in Functions/Collations editors and repair Implementation Language dropdown in Collations Editor.

Plugins/SqlEnterpriseFormatter/formatexpr.cpp

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,13 @@ void FormatExpr::formatInternal()
9999
if (expr->star)
100100
withOperator("*").withParFuncRight();
101101
else
102-
withStatementList(expr->exprList, "funcArgs", FormatStatement::ListSeparator::EXPR_COMMA).withParFuncRight();
102+
{
103+
withStatementList(expr->exprList, "funcArgs", FormatStatement::ListSeparator::EXPR_COMMA);
104+
if (!expr->sortColumns.isEmpty())
105+
withKeyword("ORDER").withKeyword("BY").withStatementList(expr->sortColumns);
106+
107+
withParFuncRight();
108+
}
103109

104110
break;
105111
}
@@ -114,13 +120,32 @@ void FormatExpr::formatInternal()
114120
if (expr->star)
115121
withOperator("*").withParFuncRight();
116122
else
117-
withStatementList(expr->exprList, "funcArgs", FormatStatement::ListSeparator::EXPR_COMMA).withParFuncRight();
123+
{
124+
withStatementList(expr->exprList, "funcArgs", FormatStatement::ListSeparator::EXPR_COMMA);
125+
if (!expr->sortColumns.isEmpty())
126+
withKeyword("ORDER").withKeyword("BY").withStatementList(expr->sortColumns);
127+
128+
withParFuncRight();
129+
}
118130

119131
if (expr->filterOver)
120132
withStatement(expr->filterOver);
121133

122134
break;
123135
}
136+
case SqliteExpr::Mode::ORDERED_SET_AGGREGATE:
137+
{
138+
withId(expr->function).withParFuncLeft();
139+
if (expr->distinctKw)
140+
withKeyword("DISTINCT");
141+
else if (expr->allKw)
142+
withKeyword("ALL");
143+
144+
withStatementList(expr->exprList, "funcArgs", FormatStatement::ListSeparator::EXPR_COMMA).withParFuncRight();
145+
withKeyword("WITHIN").withKeyword("GROUP");
146+
withParFuncLeft().withKeyword("ORDER").withKeyword("BY").withStatement(expr->expr1, "orderByExpr1").withParFuncRight();
147+
break;
148+
}
124149
case SqliteExpr::Mode::SUB_EXPR:
125150
withParExprLeft().withStatement(expr->expr1).withParExprRight();
126151
break;

Plugins/SqlEnterpriseFormatter/formatraise.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "formatraise.h"
22
#include "parser/ast/sqliteraise.h"
3+
#include "parser/ast/sqliteexpr.h"
34

45
FormatRaise::FormatRaise(SqliteRaise *raise) :
56
raise(raise)
@@ -10,7 +11,7 @@ void FormatRaise::formatInternal()
1011
{
1112
withKeyword("RAISE").withParFuncLeft().withKeyword(SqliteRaise::raiseType(raise->type));
1213
if (raise->type != SqliteRaise::Type::IGNORE)
13-
withCommaOper().withStringOrId(raise->message);
14+
withCommaOper().withStatement(raise->expr);
1415

1516
withParFuncRight();
1617
}

SQLiteStudio3/coreSQLiteStudio/parser/ast/sqliteexpr.cpp

Lines changed: 92 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "sqliteselect.h"
44
#include "sqlitecolumntype.h"
55
#include "sqlitefilterover.h"
6+
#include "sqliteorderby.h"
67
#include "parser/statementtokenbuilder.h"
78
#include "common/utils_sql.h"
89
#include "common/global.h"
@@ -27,6 +28,7 @@ SqliteExpr::SqliteExpr(const SqliteExpr& other) :
2728
DEEP_COPY_FIELD(SqliteSelect, select);
2829
DEEP_COPY_FIELD(SqliteRaise, raiseFunction);
2930
DEEP_COPY_FIELD(SqliteFilterOver, filterOver);
31+
DEEP_COPY_COLLECTION(SqliteOrderBy, sortColumns);
3032
}
3133

3234
SqliteExpr::~SqliteExpr()
@@ -176,6 +178,21 @@ void SqliteExpr::initFunction(const QString& fnName, int distinct, const QList<S
176178
expr->setParent(this);
177179
}
178180

181+
void SqliteExpr::initFunction(const QString &fnName, int distinct, const QList<SqliteExpr *> &exprList, const QList<SqliteOrderBy*>& columns)
182+
{
183+
mode = SqliteExpr::Mode::FUNCTION;
184+
function = fnName;
185+
this->exprList = exprList;
186+
initDistinct(distinct);
187+
this->sortColumns = columns;
188+
189+
for (SqliteOrderBy* orderBy : columns)
190+
orderBy->setParent(this);
191+
192+
for (SqliteExpr* expr : exprList)
193+
expr->setParent(this);
194+
}
195+
179196
void SqliteExpr::initFunction(const QString& fnName, bool star)
180197
{
181198
mode = SqliteExpr::Mode::FUNCTION;
@@ -198,6 +215,25 @@ void SqliteExpr::initWindowFunction(const QString& fnName, int distinct, const Q
198215
filterOver->setParent(this);
199216
}
200217

218+
void SqliteExpr::initWindowFunction(const QString &fnName, int distinct, const QList<SqliteExpr *> &exprList, const QList<SqliteOrderBy*>& columns, SqliteFilterOver *filterOver)
219+
{
220+
mode = SqliteExpr::Mode::WINDOW_FUNCTION;
221+
this->function = fnName;
222+
this->exprList = exprList;
223+
initDistinct(distinct);
224+
this->sortColumns = columns;
225+
this->filterOver = filterOver;
226+
227+
for (SqliteOrderBy* orderBy : columns)
228+
orderBy->setParent(this);
229+
230+
for (SqliteExpr* expr : exprList)
231+
expr->setParent(this);
232+
233+
if (filterOver)
234+
filterOver->setParent(this);
235+
}
236+
201237
void SqliteExpr::initWindowFunction(const QString& fnName, SqliteFilterOver* filterOver)
202238
{
203239
mode = SqliteExpr::Mode::WINDOW_FUNCTION;
@@ -209,6 +245,15 @@ void SqliteExpr::initWindowFunction(const QString& fnName, SqliteFilterOver* fil
209245
filterOver->setParent(this);
210246
}
211247

248+
void SqliteExpr::initOrderedSetAggregate(const QString &fnName, int distinct, const QList<SqliteExpr *> &exprList, SqliteExpr *expr)
249+
{
250+
mode = SqliteExpr::Mode::ORDERED_SET_AGGREGATE;
251+
this->function = fnName;
252+
this->exprList = exprList;
253+
initDistinct(distinct);
254+
this->expr1 = expr;
255+
}
256+
212257
void SqliteExpr::initBinOp(SqliteExpr *expr1, const QString& op, SqliteExpr *expr2)
213258
{
214259
mode = SqliteExpr::Mode::BINARY_OP;
@@ -386,10 +431,10 @@ void SqliteExpr::initCase(SqliteExpr *expr1, const QList<SqliteExpr*>& exprList,
386431
expr->setParent(this);
387432
}
388433

389-
void SqliteExpr::initRaise(const QString& type, const QString& text)
434+
void SqliteExpr::initRaise(const QString& type, SqliteExpr *expr)
390435
{
391436
mode = SqliteExpr::Mode::RAISE;
392-
raiseFunction = new SqliteRaise(type, text);
437+
raiseFunction = new SqliteRaise(type, expr);
393438
}
394439

395440
void SqliteExpr::detectDoubleQuotes(bool recursively)
@@ -602,7 +647,17 @@ TokenList SqliteExpr::rebuildTokensFromContents()
602647
if (star)
603648
builder.withOperator("*").withParRight();
604649
else
605-
builder.withStatementList(exprList).withParRight();
650+
{
651+
builder.withStatementList(exprList);
652+
if (!sortColumns.isEmpty())
653+
{
654+
builder
655+
.withSpace().withKeyword("ORDER")
656+
.withSpace().withKeyword("BY")
657+
.withSpace().withStatementList(sortColumns);
658+
}
659+
builder.withParRight();
660+
}
606661

607662
break;
608663
case SqliteExpr::Mode::WINDOW_FUNCTION:
@@ -615,10 +670,42 @@ TokenList SqliteExpr::rebuildTokensFromContents()
615670
if (star)
616671
builder.withOperator("*").withParRight();
617672
else
618-
builder.withStatementList(exprList).withParRight();
619-
673+
{
674+
builder.withStatementList(exprList);
675+
if (!sortColumns.isEmpty())
676+
{
677+
builder
678+
.withSpace().withKeyword("ORDER")
679+
.withSpace().withKeyword("BY")
680+
.withSpace().withStatementList(sortColumns);
681+
}
682+
builder.withParRight();
683+
}
620684
builder.withSpace().withStatement(filterOver);
621685
break;
686+
case SqliteExpr::Mode::ORDERED_SET_AGGREGATE:
687+
builder.withOther(function).withParLeft();
688+
if (distinctKw)
689+
builder.withKeyword("DISTINCT");
690+
else if (allKw)
691+
builder.withKeyword("ALL");
692+
693+
builder
694+
.withStatementList(exprList)
695+
.withParRight()
696+
.withSpace()
697+
.withKeyword("WITHIN")
698+
.withSpace()
699+
.withKeyword("GROUP")
700+
.withSpace()
701+
.withParLeft()
702+
.withKeyword("ORDER")
703+
.withSpace()
704+
.withKeyword("BY")
705+
.withSpace()
706+
.withStatement(expr1)
707+
.withParRight();
708+
break;
622709
case SqliteExpr::Mode::SUB_EXPR:
623710
builder.withParLeft().withStatement(expr1).withParRight();
624711
break;

SQLiteStudio3/coreSQLiteStudio/parser/ast/sqliteexpr.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class SqliteFilterOver;
1010
class SqliteSelect;
1111
class SqliteColumnType;
1212
class SqliteRaise;
13+
class SqliteOrderBy;
1314

1415
class API_EXPORT SqliteExpr : public SqliteStatement
1516
{
@@ -42,7 +43,8 @@ class API_EXPORT SqliteExpr : public SqliteStatement
4243
CASE,
4344
SUB_SELECT,
4445
RAISE,
45-
WINDOW_FUNCTION
46+
WINDOW_FUNCTION,
47+
ORDERED_SET_AGGREGATE
4648
};
4749

4850
enum class NotNull
@@ -84,9 +86,13 @@ class API_EXPORT SqliteExpr : public SqliteStatement
8486
void initCollate(SqliteExpr* expr, const QString& value);
8587
void initCast(SqliteExpr* expr, SqliteColumnType* type);
8688
void initFunction(const QString& fnName, int distinct, const QList<SqliteExpr*>& exprList);
89+
void initFunction(const QString& fnName, int distinct, const QList<SqliteExpr*>& exprList, const QList<SqliteOrderBy*>& columns);
8790
void initFunction(const QString& fnName, bool star = false);
8891
void initWindowFunction(const QString& fnName, int distinct, const QList<SqliteExpr*>& exprList, SqliteFilterOver* filterOver);
92+
void initWindowFunction(const QString& fnName, int distinct, const QList<SqliteExpr*>& exprList,
93+
const QList<SqliteOrderBy*>& columns, SqliteFilterOver* filterOver);
8994
void initWindowFunction(const QString& fnName, SqliteFilterOver* filterOver);
95+
void initOrderedSetAggregate(const QString& fnName, int distinct, const QList<SqliteExpr*>& exprList, SqliteExpr* expr);
9096
void initBinOp(SqliteExpr* expr1, const QString& op, SqliteExpr* expr2);
9197
void initUnaryOp(SqliteExpr* expr, const QString& op);
9298
void initPtrOp(SqliteExpr* expr1, const QString& op, SqliteExpr* expr2);
@@ -101,7 +107,7 @@ class API_EXPORT SqliteExpr : public SqliteStatement
101107
void initExists(SqliteSelect* select);
102108
void initSubSelect(SqliteSelect* select);
103109
void initCase(SqliteExpr* expr1, const QList<SqliteExpr*>& exprList, SqliteExpr* expr2);
104-
void initRaise(const QString& type, const QString& text = QString());
110+
void initRaise(const QString& type, SqliteExpr* expr = nullptr);
105111
void detectDoubleQuotes(bool recursively = true);
106112
bool replace(SqliteExpr* toBeReplaced, SqliteExpr* replaceWith);
107113

@@ -134,6 +140,7 @@ class API_EXPORT SqliteExpr : public SqliteStatement
134140
SqliteRaise* raiseFunction = nullptr;
135141
bool possibleDoubleQuotedString = false;
136142
bool originallySingleQuoteString = false;
143+
QList<SqliteOrderBy*> sortColumns;
137144

138145
protected:
139146
QStringList getColumnsInStatement();

SQLiteStudio3/coreSQLiteStudio/parser/ast/sqliteraise.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,27 @@
11
#include "sqliteraise.h"
22
#include "parser/statementtokenbuilder.h"
3+
#include "common/global.h"
4+
#include "sqliteexpr.h"
35

46
SqliteRaise::SqliteRaise()
57
{
68
}
79

810
SqliteRaise::SqliteRaise(const SqliteRaise& other) :
9-
SqliteStatement(other), type(other.type), message(other.message)
11+
SqliteStatement(other), type(other.type)
1012
{
13+
DEEP_COPY_FIELD(SqliteExpr, expr);
1114
}
1215

1316
SqliteRaise::SqliteRaise(const QString &type)
1417
{
1518
this->type = raiseType(type);
1619
}
1720

18-
SqliteRaise::SqliteRaise(const QString &type, const QString &text)
21+
SqliteRaise::SqliteRaise(const QString &type, SqliteExpr *value)
1922
{
2023
this->type = raiseType(type);
21-
message = text;
24+
this->expr = value;
2225
}
2326

2427
SqliteStatement*SqliteRaise::clone()
@@ -63,7 +66,7 @@ TokenList SqliteRaise::rebuildTokensFromContents()
6366
StatementTokenBuilder builder;
6467
builder.withKeyword("RAISE").withSpace().withParLeft().withKeyword(raiseType(type));
6568
if (type != Type::IGNORE)
66-
builder.withOperator(",").withSpace().withString(message);
69+
builder.withOperator(",").withSpace().withStatement(expr);
6770

6871
builder.withParRight();
6972
return builder.build();

SQLiteStudio3/coreSQLiteStudio/parser/ast/sqliteraise.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#include "sqlitestatement.h"
55
#include <QString>
66

7+
class SqliteExpr;
8+
79
class API_EXPORT SqliteRaise : public SqliteStatement
810
{
911
Q_OBJECT
@@ -21,15 +23,15 @@ class API_EXPORT SqliteRaise : public SqliteStatement
2123
SqliteRaise();
2224
SqliteRaise(const SqliteRaise& other);
2325
explicit SqliteRaise(const QString& type);
24-
SqliteRaise(const QString& type, const QString& text);
26+
SqliteRaise(const QString& type, SqliteExpr* value);
2527

2628
SqliteStatement* clone();
2729

2830
static Type raiseType(const QString& value);
2931
static QString raiseType(Type value);
3032

3133
Type type = Type::null;
32-
QString message = QString();
34+
SqliteExpr* expr = nullptr;
3335

3436
protected:
3537
TokenList rebuildTokensFromContents();

SQLiteStudio3/coreSQLiteStudio/parser/keywords.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ void initKeywords()
179179
keywords3["WHERE"] = TK3_WHERE;
180180
keywords3["WINDOW"] = TK3_WINDOW;
181181
keywords3["WITH"] = TK3_WITH;
182+
keywords3["WITHIN"] = TK3_WITHIN;
182183
keywords3["WITHOUT"] = TK3_WITHOUT;
183184

184185
rowIdKeywords << "_ROWID_"

0 commit comments

Comments
 (0)