mirror of https://github.com/alibaba/druid.git
Compare commits
7 Commits
acaa4b31b2
...
9f9486f789
| Author | SHA1 | Date |
|---|---|---|
|
|
9f9486f789 | |
|
|
0444f4f532 | |
|
|
ac484261c0 | |
|
|
31177b91f6 | |
|
|
c8b12f0701 | |
|
|
b1fda6d046 | |
|
|
1121b304c2 |
|
|
@ -4,7 +4,7 @@
|
|||
<parent>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>druid-parent</artifactId>
|
||||
<version>1.2.25</version>
|
||||
<version>1.2.26-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<artifactId>druid</artifactId>
|
||||
|
|
|
|||
|
|
@ -91,6 +91,7 @@ public enum SQLBinaryOperator {
|
|||
RegExp("REGEXP", 110),
|
||||
NotRegExp("NOT REGEXP", 110),
|
||||
Equality("=", 110),
|
||||
EqEq("==", 110),
|
||||
|
||||
BitwiseNot("!", 130),
|
||||
Concat("||", 140),
|
||||
|
|
@ -99,6 +100,7 @@ public enum SQLBinaryOperator {
|
|||
BooleanXor("XOR", 150),
|
||||
BooleanOr("OR", 160),
|
||||
Assignment(":=", 169),
|
||||
Blank("", 170),
|
||||
|
||||
PG_And("&&", 140),
|
||||
PG_ST_DISTANCE("<->", 20);
|
||||
|
|
|
|||
|
|
@ -29,16 +29,30 @@ public class SQLVariantRefExpr extends SQLExprImpl {
|
|||
|
||||
private boolean global;
|
||||
private boolean session;
|
||||
private boolean templateParameter;
|
||||
private boolean hasPrefixComma;
|
||||
|
||||
private int index = -1;
|
||||
|
||||
public SQLVariantRefExpr(String name) {
|
||||
this.name = name;
|
||||
if (name.startsWith("${") && name.endsWith("}")) {
|
||||
this.templateParameter = true;
|
||||
} else {
|
||||
this.templateParameter = false;
|
||||
}
|
||||
this.hasPrefixComma = true;
|
||||
}
|
||||
|
||||
public SQLVariantRefExpr(String name, SQLObject parent) {
|
||||
this.name = name;
|
||||
this.parent = parent;
|
||||
if (name.startsWith("${") && name.endsWith("}")) {
|
||||
this.templateParameter = true;
|
||||
} else {
|
||||
this.templateParameter = false;
|
||||
}
|
||||
this.hasPrefixComma = true;
|
||||
}
|
||||
|
||||
public SQLVariantRefExpr(String name, boolean global) {
|
||||
|
|
@ -70,6 +84,22 @@ public class SQLVariantRefExpr extends SQLExprImpl {
|
|||
this.name = name;
|
||||
}
|
||||
|
||||
public boolean isTemplateParameter() {
|
||||
return templateParameter;
|
||||
}
|
||||
|
||||
public void setTemplateParameter(boolean templateParameter) {
|
||||
this.templateParameter = templateParameter;
|
||||
}
|
||||
|
||||
public boolean isHasPrefixComma() {
|
||||
return hasPrefixComma;
|
||||
}
|
||||
|
||||
public void setHasPrefixComma(boolean hasPrefixComma) {
|
||||
this.hasPrefixComma = hasPrefixComma;
|
||||
}
|
||||
|
||||
public void output(StringBuilder buf) {
|
||||
buf.append(this.name);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ public class CKLexer extends Lexer {
|
|||
map.put("FINAL", Token.FINAL);
|
||||
map.put("TTL", Token.TTL);
|
||||
map.put("CODEC", Token.CODEC);
|
||||
map.remove("ANY");
|
||||
|
||||
return new Keywords(map);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@ import com.alibaba.druid.DbType;
|
|||
import com.alibaba.druid.sql.ast.SQLPartitionBy;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLCreateTableStatement;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.visitor.PGOutputVisitor;
|
||||
import com.alibaba.druid.sql.parser.CharTypes;
|
||||
import com.alibaba.druid.sql.visitor.VisitorFeature;
|
||||
|
||||
public class HologresOutputVisitor extends PGOutputVisitor {
|
||||
public HologresOutputVisitor(StringBuilder appender, boolean parameterized) {
|
||||
|
|
@ -27,4 +29,53 @@ public class HologresOutputVisitor extends PGOutputVisitor {
|
|||
print0(ucase ? "PARTITION BY " : "partition by ");
|
||||
partitionBy.accept(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void printComment(String comment) {
|
||||
if (comment == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isEnabled(VisitorFeature.OutputSkipMultilineComment) && comment.startsWith("/*")) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isEnabled(VisitorFeature.OutputSkipSingleLineComment)
|
||||
&& (comment.startsWith("-") || comment.startsWith("#"))) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (comment.startsWith("--")
|
||||
&& comment.length() > 2
|
||||
&& comment.charAt(2) != ' '
|
||||
&& comment.charAt(2) != '-') {
|
||||
print0("-- ");
|
||||
print0(comment.substring(2));
|
||||
} else if (comment.startsWith("#")
|
||||
&& comment.length() > 1
|
||||
&& comment.charAt(1) != ' '
|
||||
&& comment.charAt(1) != '#') {
|
||||
print0("# ");
|
||||
print0(comment.substring(1));
|
||||
} else if (comment.startsWith("/*")) {
|
||||
println();
|
||||
print0(comment);
|
||||
} else if (comment.startsWith("--")) {
|
||||
print0(comment);
|
||||
}
|
||||
|
||||
char first = '\0';
|
||||
for (int i = 0; i < comment.length(); i++) {
|
||||
char c = comment.charAt(i);
|
||||
if (CharTypes.isWhitespace(c)) {
|
||||
continue;
|
||||
}
|
||||
first = c;
|
||||
break;
|
||||
}
|
||||
|
||||
if (first == '-' || first == '#') {
|
||||
endLineComment = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2278,7 +2278,7 @@ public class Lexer {
|
|||
if (ch != ':' && ch != '#' && ch != '$' && !(ch == '@' && dialectFeatureEnabled(ScanVariableAt))) {
|
||||
throw new ParserException("illegal variable. " + info());
|
||||
}
|
||||
|
||||
boolean templateParameter = false;
|
||||
mark = pos;
|
||||
bufPos = 1;
|
||||
char ch;
|
||||
|
|
@ -2296,13 +2296,14 @@ public class Lexer {
|
|||
boolean ident = false;
|
||||
for (; ; ) {
|
||||
ch = charAt(++pos);
|
||||
if (isEOF() || ch == ';' || ch == ';' || ch == '\r' || ch == '\n') {
|
||||
if (isEOF() || (templateParameter && (ch == ';' || ch == ';' || ch == '\r'))) {
|
||||
pos--;
|
||||
bufPos--;
|
||||
break;
|
||||
}
|
||||
|
||||
if (ch == '}' && !ident) {
|
||||
templateParameter = false;
|
||||
if (isIdentifierChar(charAt(pos + 1))) {
|
||||
bufPos++;
|
||||
ident = true;
|
||||
|
|
@ -2313,6 +2314,7 @@ public class Lexer {
|
|||
|
||||
if (ident && ch == '$') {
|
||||
if (charAt(pos + 1) == '{') {
|
||||
templateParameter = true;
|
||||
bufPos++;
|
||||
ident = false;
|
||||
continue;
|
||||
|
|
@ -2323,7 +2325,7 @@ public class Lexer {
|
|||
if (isWhitespace(ch)) {
|
||||
pos--;
|
||||
break;
|
||||
} else if (ch == ',' || ch == ')' || ch == '(' || ch == ';') {
|
||||
} else if (ch == ',' || ch == ')' || ch == '(') {
|
||||
pos--;
|
||||
break;
|
||||
}
|
||||
|
|
@ -2525,10 +2527,21 @@ public class Lexer {
|
|||
}
|
||||
|
||||
if (ch == '*' && charAt(pos + 1) == '/') {
|
||||
scanChar();
|
||||
scanChar();
|
||||
if (0 == --depth) {
|
||||
break;
|
||||
int curPos = pos;
|
||||
boolean terminated = true;
|
||||
// If '*/' has leading '--' in the same line, just skip it. For example '-- xxxx */'.
|
||||
while (curPos > 0 && charAt(curPos) != '\n') {
|
||||
if (charAt(curPos) == '-' && (curPos + 1) < text.length() && charAt(curPos + 1) == '-') {
|
||||
terminated = false;
|
||||
}
|
||||
curPos--;
|
||||
}
|
||||
if (terminated) {
|
||||
scanChar();
|
||||
scanChar();
|
||||
if (0 == --depth) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2927,8 +2927,7 @@ public class SQLExprParser extends SQLParser {
|
|||
SQLSelectOrderByItem item = parseSelectOrderByItem();
|
||||
item.setParent(parent);
|
||||
items.add(item);
|
||||
while (lexer.token == Token.COMMA) {
|
||||
lexer.nextToken();
|
||||
while (lexer.nextIf(Token.COMMA) || (item.getExpr() instanceof SQLVariantRefExpr && lexer.token == IDENTIFIER)) {
|
||||
item = parseSelectOrderByItem();
|
||||
item.setParent(parent);
|
||||
items.add(item);
|
||||
|
|
@ -3532,6 +3531,14 @@ public class SQLExprParser extends SQLParser {
|
|||
SQLBinaryOperator operator = andRestGetAndOperator();
|
||||
|
||||
expr = new SQLBinaryOpExpr(expr, operator, rightExp, dbType);
|
||||
} else if (token == Token.VARIANT) {
|
||||
String value = lexer.stringVal();
|
||||
lexer.nextToken();
|
||||
SQLExpr variantExpr = new SQLVariantRefExpr(value);
|
||||
if (lexer.token == Token.IN) {
|
||||
variantExpr = inRest(variantExpr);
|
||||
}
|
||||
expr = new SQLBinaryOpExpr(expr, SQLBinaryOperator.Blank, variantExpr, dbType);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
|
|
@ -3619,6 +3626,14 @@ public class SQLExprParser extends SQLParser {
|
|||
SQLBinaryOperator op = orRestGetOrOperator();
|
||||
|
||||
expr = new SQLBinaryOpExpr(expr, op, rightExp, dbType);
|
||||
} else if (lexer.token == Token.VARIANT) {
|
||||
String value = lexer.stringVal();
|
||||
lexer.nextToken();
|
||||
SQLExpr variantExpr = new SQLVariantRefExpr(value);
|
||||
if (lexer.token == Token.IN) {
|
||||
variantExpr = inRest(variantExpr);
|
||||
}
|
||||
expr = new SQLBinaryOpExpr(expr, SQLBinaryOperator.Blank, variantExpr, dbType);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
|
|
@ -3642,7 +3657,8 @@ public class SQLExprParser extends SQLParser {
|
|||
}
|
||||
|
||||
protected SQLExpr relationalRestEqeq(SQLExpr expr) {
|
||||
return expr;
|
||||
lexer.nextToken();
|
||||
return new SQLBinaryOpExpr(expr, SQLBinaryOperator.EqEq, expr());
|
||||
}
|
||||
|
||||
protected SQLExpr relationalRestTilde(SQLExpr expr) {
|
||||
|
|
@ -3977,6 +3993,11 @@ public class SQLExprParser extends SQLParser {
|
|||
return expr;
|
||||
}
|
||||
break;
|
||||
case VARIANT:
|
||||
rightExp = new SQLVariantRefExpr(lexer.stringVal);
|
||||
expr = new SQLBinaryOpExpr(expr, SQLBinaryOperator.Blank, rightExp, dbType);
|
||||
lexer.nextToken();
|
||||
return expr;
|
||||
default:
|
||||
return expr;
|
||||
}
|
||||
|
|
@ -5946,46 +5967,47 @@ public class SQLExprParser extends SQLParser {
|
|||
|
||||
String alias;
|
||||
List<String> aliasList = null;
|
||||
switch (lexer.token) {
|
||||
case FULL:
|
||||
case TABLESPACE:
|
||||
alias = lexer.stringVal();
|
||||
lexer.nextToken();
|
||||
break;
|
||||
case AS:
|
||||
lexer.nextTokenAlias();
|
||||
if (lexer.token == Token.LITERAL_INT) {
|
||||
alias = '"' + lexer.stringVal() + '"';
|
||||
if (expr instanceof SQLVariantRefExpr && ((SQLVariantRefExpr) expr).isTemplateParameter() && lexer.token != AS) {
|
||||
alias = null;
|
||||
} else {
|
||||
switch (lexer.token) {
|
||||
case FULL:
|
||||
case TABLESPACE:
|
||||
alias = lexer.stringVal();
|
||||
lexer.nextToken();
|
||||
} else if (lexer.token == Token.LPAREN) {
|
||||
lexer.nextToken();
|
||||
aliasList = new ArrayList<String>();
|
||||
|
||||
for (; ; ) {
|
||||
String stringVal = lexer.stringVal();
|
||||
break;
|
||||
case AS:
|
||||
lexer.nextTokenAlias();
|
||||
if (lexer.token == Token.LITERAL_INT) {
|
||||
alias = '"' + lexer.stringVal() + '"';
|
||||
lexer.nextToken();
|
||||
|
||||
aliasList.add(stringVal);
|
||||
|
||||
if (lexer.token() == Token.COMMA) {
|
||||
} else if (lexer.token == Token.LPAREN) {
|
||||
lexer.nextToken();
|
||||
aliasList = new ArrayList<String>();
|
||||
for (; ; ) {
|
||||
String stringVal = lexer.stringVal();
|
||||
lexer.nextToken();
|
||||
continue;
|
||||
aliasList.add(stringVal);
|
||||
if (lexer.token() == Token.COMMA) {
|
||||
lexer.nextToken();
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
accept(Token.RPAREN);
|
||||
accept(Token.RPAREN);
|
||||
|
||||
alias = null;
|
||||
} else {
|
||||
alias = alias();
|
||||
}
|
||||
break;
|
||||
case EOF:
|
||||
alias = null;
|
||||
} else {
|
||||
alias = alias();
|
||||
}
|
||||
break;
|
||||
case EOF:
|
||||
alias = null;
|
||||
break;
|
||||
default:
|
||||
alias = as();
|
||||
break;
|
||||
break;
|
||||
default:
|
||||
alias = as();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (alias == null && isEnabled(SQLParserFeature.SelectItemGenerateAlias)
|
||||
|
|
|
|||
|
|
@ -756,6 +756,7 @@ public class SQLSelectParser extends SQLParser {
|
|||
case BANGEQ:
|
||||
case LIKE:
|
||||
case NOT:
|
||||
case VARIANT:
|
||||
where = this.exprParser.relationalRest(where);
|
||||
break;
|
||||
default:
|
||||
|
|
@ -1099,6 +1100,10 @@ public class SQLSelectParser extends SQLParser {
|
|||
} else {
|
||||
item = this.exprParser.expr();
|
||||
}
|
||||
if (lexer.nextIf(Token.AS)) {
|
||||
item = new SQLAliasedExpr(item, lexer.stringVal);
|
||||
lexer.nextToken();
|
||||
}
|
||||
|
||||
if (dialectFeatureEnabled(GroupByItemOrder)) {
|
||||
if (lexer.token == Token.DESC) {
|
||||
|
|
@ -1122,11 +1127,16 @@ public class SQLSelectParser extends SQLParser {
|
|||
|
||||
protected void parseSelectList(SQLSelectQueryBlock queryBlock) {
|
||||
final List<SQLSelectItem> selectList = queryBlock.getSelectList();
|
||||
boolean hasComma = true;
|
||||
for (; ; ) {
|
||||
final SQLSelectItem selectItem = this.exprParser.parseSelectItem();
|
||||
selectList.add(selectItem);
|
||||
selectItem.setParent(queryBlock);
|
||||
|
||||
if (!hasComma && selectItem.getExpr() instanceof SQLVariantRefExpr) {
|
||||
SQLVariantRefExpr sqlVariantRefExpr = (SQLVariantRefExpr) selectItem.getExpr();
|
||||
sqlVariantRefExpr.setHasPrefixComma(false);
|
||||
hasComma = true;
|
||||
}
|
||||
//https://github.com/alibaba/druid/issues/5708
|
||||
if (lexer.hasComment()
|
||||
&& lexer.isKeepComments()
|
||||
|
|
@ -1136,7 +1146,14 @@ public class SQLSelectParser extends SQLParser {
|
|||
}
|
||||
|
||||
if (lexer.token != Token.COMMA) {
|
||||
break;
|
||||
if (lexer.token == Token.VARIANT) {
|
||||
hasComma = false;
|
||||
continue;
|
||||
} else if (selectItem.getExpr() instanceof SQLVariantRefExpr && ((SQLVariantRefExpr) selectItem.getExpr()).isTemplateParameter() && lexer.token != Token.FROM) {
|
||||
continue;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int line = lexer.line;
|
||||
|
|
|
|||
|
|
@ -222,11 +222,11 @@ public class SQLStatementParser extends SQLParser {
|
|||
case SELECT: {
|
||||
MySqlHintStatement hintStatement = null;
|
||||
if (i == 1
|
||||
&& statementList.size() > 0
|
||||
&& !statementList.isEmpty()
|
||||
&& statementList.get(statementList.size() - i) instanceof MySqlHintStatement) {
|
||||
hintStatement = (MySqlHintStatement) statementList.get(statementList.size() - i);
|
||||
} else if (i > 0 && dialectFeatureEnabled(ParseStatementListSelectUnsupportedSyntax) && !semi
|
||||
&& !(statementList.size() > 0 && statementList.get(statementList.size() - i).isAfterSemi())
|
||||
&& !(!statementList.isEmpty() && statementList.size() - i >= 0 && statementList.get(statementList.size() - i).isAfterSemi())
|
||||
) {
|
||||
throw new ParserException("syntax error. " + lexer.info());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -105,7 +105,7 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Paramet
|
|||
|
||||
protected transient int lines;
|
||||
private TimeZone timeZone;
|
||||
private boolean endLineComment;
|
||||
protected boolean endLineComment;
|
||||
|
||||
protected SQLDialect dialect;
|
||||
|
||||
|
|
@ -586,8 +586,11 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Paramet
|
|||
lineItemCount = 0;
|
||||
println();
|
||||
}
|
||||
|
||||
print0(", ");
|
||||
if (selectItem.getExpr() instanceof SQLVariantRefExpr && !((SQLVariantRefExpr) selectItem.getExpr()).isHasPrefixComma()) {
|
||||
print0(" ");
|
||||
} else {
|
||||
print0(", ");
|
||||
}
|
||||
}
|
||||
|
||||
if (selectItem.getClass() == SQLSelectItem.class) {
|
||||
|
|
@ -1048,7 +1051,7 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Paramet
|
|||
&& ((SQLIdentifierExpr) right).getName().equalsIgnoreCase("NOTFOUND")) {
|
||||
printOpSpace = false;
|
||||
}
|
||||
if (printOpSpace) {
|
||||
if (printOpSpace && operator != SQLBinaryOperator.Blank) {
|
||||
print(' ');
|
||||
}
|
||||
}
|
||||
|
|
@ -1569,7 +1572,12 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Paramet
|
|||
if (x.isParenthesized()) {
|
||||
print('(');
|
||||
}
|
||||
printName0(x.getName());
|
||||
String replacedName = x.getName();
|
||||
if (x.getParent() instanceof SQLBinaryOpExpr
|
||||
|| x.getParent() instanceof SQLSelectItem) {
|
||||
replacedName = replaceQuota(x.getName());
|
||||
}
|
||||
printName0(replacedName);
|
||||
if (x.getCollate() != null) {
|
||||
String collate = x.getCollate();
|
||||
print(" COLLATE ");
|
||||
|
|
|
|||
|
|
@ -1,3 +1,76 @@
|
|||
select if(a=='G', b, c) from test
|
||||
--------------------
|
||||
SELECT if(a == 'G', b, c)
|
||||
FROM test
|
||||
------------------------------------------------------------------------------------------------------------------------
|
||||
select a, b, count(1) from test group by a as c, b as d
|
||||
--------------------
|
||||
SELECT a, b, count(1)
|
||||
FROM test
|
||||
GROUP BY a AS c, b AS d
|
||||
------------------------------------------------------------------------------------------------------------------------
|
||||
select c from b where c=1 ${if(len(a)=0,'and 1=1',"and a>0")} ${if(len(a)=0,'and 1=1',"and a>0")}
|
||||
--------------------
|
||||
SELECT c
|
||||
FROM b
|
||||
WHERE c = 1 ${if(len(a)=0,'and 1=1',"and a>0")} ${if(len(a)=0,'and 1=1',"and a>0")}
|
||||
------------------------------------------------------------------------------------------------------------------------
|
||||
select ${if(len(a)=0,' 1=1 ',"c")}, ${if(len(a)=0,' 1=1 ',"c")} from b
|
||||
--------------------
|
||||
SELECT ${if(len(a)=0,' 1=1 ',"c")}, ${if(len(a)=0,' 1=1 ',"c")}
|
||||
FROM b
|
||||
------------------------------------------------------------------------------------------------------------------------
|
||||
select a from test where 1=1 ${if(a=1, "and b","and c")} in d
|
||||
--------------------
|
||||
SELECT a
|
||||
FROM test
|
||||
WHERE 1 = 1 ${if(a=1, "and b","and c")} IN (d)
|
||||
------------------------------------------------------------------------------------------------------------------------
|
||||
select a from test where 1=1
|
||||
and (
|
||||
a.report_item_code in ('${gFinReportItem}') or a.report_item_code ='B002'
|
||||
${if(find('E069',gFinReportItem)>0," or (c.yn_offset_report = 'Y' and a.report_item_code ='E06802') "," ")}
|
||||
)
|
||||
--------------------
|
||||
SELECT a
|
||||
FROM test
|
||||
WHERE 1 = 1
|
||||
AND (a.report_item_code IN ('${gFinReportItem}')
|
||||
OR a.report_item_code = 'B002' ${if(find('E069',gFinReportItem)>0," or (c.yn_offset_report = 'Y' and a.report_item_code ='E06802') "," ")})
|
||||
------------------------------------------------------------------------------------------------------------------------
|
||||
select ${if(len(a)=0,' 1=1 ',"c")}, ${if(len(a)=0,' 1=1 ',"c")} from b
|
||||
--------------------
|
||||
SELECT ${if(len(a)=0,' 1=1 ',"c")}, ${if(len(a)=0,' 1=1 ',"c")}
|
||||
FROM b
|
||||
------------------------------------------------------------------------------------------------------------------------
|
||||
select b.merge_region_code as region_code,b.merge_region_name as region_name,b.govern_region_area_union as region_area_subtotal
|
||||
${if(gRegionAreaLevel='合并营运区',",b.govern_region_area_union as region_area_code,b.govern_region_area_union as region_area_name",",b.region_area_code as region_area_code,b.region_area_name as region_area_name")}
|
||||
-- ${if(len(gQtrMonth)=5,"/*","")}
|
||||
,sum(case when a.stat_date = ${gQtrMonth} then a.period_loc_amt else 0 end) as bq_amt
|
||||
from b
|
||||
--------------------
|
||||
SELECT b.merge_region_code AS region_code, b.merge_region_name AS region_name, b.govern_region_area_union AS region_area_subtotal ${if(gRegionAreaLevel='合并营运区',",b.govern_region_area_union as region_area_code,b.govern_region_area_union as region_area_name",",b.region_area_code as region_area_code,b.region_area_name as region_area_name")} -- ${if(len(gQtrMonth)=5,"/*","")}
|
||||
, sum(CASE
|
||||
WHEN a.stat_date = ${gQtrMonth} THEN a.period_loc_amt
|
||||
ELSE 0
|
||||
END) AS bq_amt
|
||||
FROM b
|
||||
------------------------------------------------------------------------------------------------------------------------
|
||||
select
|
||||
${if(gGyzy_hz=='G'," buyer_name as buyer_name, "," syr as buyer_name, ")}
|
||||
substringUTF8(buyer_name,1,positionUTF8(buyer_name,'(')-1) as tg
|
||||
from a
|
||||
--------------------
|
||||
SELECT ${if(gGyzy_hz=='G'," buyer_name as buyer_name, "," syr as buyer_name, ")}
|
||||
, substringUTF8(buyer_name, 1, positionUTF8(buyer_name, '(') - 1) AS tg
|
||||
FROM a
|
||||
------------------------------------------------------------------------------------------------------------------------
|
||||
select c from b where c=1 ${if(len(a)=0,'and 1=1',"and a>0")} ${if(len(a)=0,'and 1=1',"and a>0")}
|
||||
--------------------
|
||||
SELECT c
|
||||
FROM b
|
||||
WHERE c = 1 ${if(len(a)=0,'and 1=1',"and a>0")} ${if(len(a)=0,'and 1=1',"and a>0")}
|
||||
------------------------------------------------------------------------------------------------------------------------
|
||||
--test
|
||||
select a from b
|
||||
--------------------
|
||||
|
|
|
|||
|
|
@ -1,3 +1,33 @@
|
|||
select a from test
|
||||
-- origin
|
||||
-- ${if(gFinPeriod="季度","/*","")}
|
||||
-- origin end
|
||||
-- new
|
||||
/*
|
||||
-- new end
|
||||
where 1=1
|
||||
-- origin
|
||||
-- ${if(gFinPeriod="季度","","*/")}
|
||||
-- origin end
|
||||
-- new
|
||||
*/
|
||||
--new end
|
||||
--------------------
|
||||
SELECT a
|
||||
FROM test -- origin
|
||||
-- ${if(gFinPeriod="季度","/*","")}
|
||||
-- origin end
|
||||
-- new
|
||||
/*
|
||||
-- new end
|
||||
where 1=1
|
||||
-- origin
|
||||
-- ${if(gFinPeriod="季度","","*/")}
|
||||
-- origin end
|
||||
-- new
|
||||
*/
|
||||
-- new end
|
||||
------------------------------------------------------------------------------------------------------------------------
|
||||
SELECT sum(ret_amount) AS '应收金额'
|
||||
FROM test.test
|
||||
GROUP BY a ORDER BY '应收金额' DESC;
|
||||
|
|
|
|||
|
|
@ -12,6 +12,22 @@ select * from [test].[test]
|
|||
SELECT *
|
||||
FROM [test].[test]
|
||||
------------------------------------------------------------------------------------------------------------------------
|
||||
CREATE VIEW [a].[b]
|
||||
AS SELECT
|
||||
*
|
||||
, [c] = DATEDIFF(MILLISECOND, request_time, GETDATE()) / 1000.0
|
||||
FROM
|
||||
tbl
|
||||
WHERE
|
||||
[state] = 'Queued';
|
||||
--------------------
|
||||
CREATE VIEW [a].[b]
|
||||
AS
|
||||
SELECT *
|
||||
, [c] = DATEDIFF(MILLISECOND, request_time, GETDATE()) / 1000.0
|
||||
FROM tbl
|
||||
WHERE [state] = 'Queued';
|
||||
------------------------------------------------------------------------------------------------------------------------
|
||||
USE AdventureWorks2008R2
|
||||
--------------------
|
||||
USE AdventureWorks2008R2
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@
|
|||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>druid-spring-boot-starter</artifactId>
|
||||
<version>1.2.25</version>
|
||||
<version>1.2.26-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<!-- Spring and Spring Boot dependencies -->
|
||||
<dependency>
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
<parent>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>druid-parent</artifactId>
|
||||
<version>1.2.25</version>
|
||||
<version>1.2.26-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<artifactId>druid-spring-boot-3-starter</artifactId>
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
<parent>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>druid-parent</artifactId>
|
||||
<version>1.2.25</version>
|
||||
<version>1.2.26-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<artifactId>druid-spring-boot-starter</artifactId>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
<parent>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>druid-parent</artifactId>
|
||||
<version>1.2.25</version>
|
||||
<version>1.2.26-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<groupId>com.alibaba</groupId>
|
||||
|
|
|
|||
14
pom.xml
14
pom.xml
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>druid-parent</artifactId>
|
||||
<version>1.2.25</version>
|
||||
<version>1.2.26-SNAPSHOT</version>
|
||||
<name>${project.artifactId}</name>
|
||||
<description>A JDBC datasource implementation.</description>
|
||||
<packaging>pom</packaging>
|
||||
|
|
@ -81,12 +81,12 @@
|
|||
|
||||
<distributionManagement>
|
||||
<repository>
|
||||
<id>ossrh</id>
|
||||
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
|
||||
<id>central</id>
|
||||
<url>https://central.sonatype.org/service/local/staging/deploy/maven2/</url>
|
||||
</repository>
|
||||
<snapshotRepository>
|
||||
<id>ossrh</id>
|
||||
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
|
||||
<id>central</id>
|
||||
<url>https://central.sonatype.com/repository/maven-snapshots/</url>
|
||||
</snapshotRepository>
|
||||
</distributionManagement>
|
||||
|
||||
|
|
@ -470,8 +470,8 @@
|
|||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<serverId>ossrh</serverId>
|
||||
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
|
||||
<serverId>central</serverId>
|
||||
<nexusUrl>https://central.sonatype.org/</nexusUrl>
|
||||
<autoReleaseAfterClose>true</autoReleaseAfterClose>
|
||||
<!--
|
||||
If you are deploying to Maven Central,
|
||||
|
|
|
|||
Loading…
Reference in New Issue