mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
improved mysql parser, update support cte fix #4289
This commit is contained in:
@@ -2236,6 +2236,11 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
}
|
||||
}
|
||||
|
||||
if (x.getWith() != null) {
|
||||
x.getWith().accept(this);
|
||||
println();
|
||||
}
|
||||
|
||||
List<SQLExpr> returning = x.getReturning();
|
||||
if (returning != null && returning.size() > 0) {
|
||||
print0(ucase ? "SELECT " : "select ");
|
||||
|
||||
@@ -5257,6 +5257,10 @@ public class SQLStatementParser extends SQLParser {
|
||||
HiveMultiInsertStatement insert = (HiveMultiInsertStatement) this.parseInsert();
|
||||
insert.setWith(with);
|
||||
return insert;
|
||||
} else if (lexer.token == UPDATE) {
|
||||
SQLUpdateStatement update = this.parseUpdateStatement();
|
||||
update.setWith(with);
|
||||
return update;
|
||||
}
|
||||
|
||||
throw new ParserException("TODO. " + lexer.info());
|
||||
|
||||
@@ -3468,6 +3468,11 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Paramet
|
||||
}
|
||||
}
|
||||
|
||||
if (x.getWith() != null) {
|
||||
x.getWith().accept(this);
|
||||
println();
|
||||
}
|
||||
|
||||
print0(ucase ? "UPDATE " : "update ");
|
||||
|
||||
printTableSource(x.getTableSource());
|
||||
|
||||
@@ -123,6 +123,10 @@ public class MySqlResourceTest extends TestCase {
|
||||
exec_test("bvt/parser/mysql-32.txt");
|
||||
}
|
||||
|
||||
public void test_33() throws Exception {
|
||||
exec_test("bvt/parser/mysql-33.txt");
|
||||
}
|
||||
|
||||
public void exec_test(String resource) throws Exception {
|
||||
// System.out.println(resource);
|
||||
InputStream is = null;
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
with recursive tti as (
|
||||
select t.task_id
|
||||
from task_info t
|
||||
where t.task_id in (?)
|
||||
union
|
||||
select t.task_id
|
||||
from task_info t
|
||||
inner join tti tt on t.pid = tt.task_id
|
||||
)
|
||||
update task_info t
|
||||
join (select now() as 'now') n
|
||||
inner join tti tt on tt.task_id = t.task_id
|
||||
set t.is_del = 1,
|
||||
t.delete_time = n.now,
|
||||
t.delete_clerk_id = ?
|
||||
---------------------------
|
||||
WITH RECURSIVE tti AS (
|
||||
SELECT t.task_id
|
||||
FROM task_info t
|
||||
WHERE t.task_id IN (?)
|
||||
UNION
|
||||
SELECT t.task_id
|
||||
FROM task_info t
|
||||
INNER JOIN tti tt ON t.pid = tt.task_id
|
||||
)
|
||||
UPDATE task_info t
|
||||
JOIN (
|
||||
SELECT now() AS "now"
|
||||
) n
|
||||
INNER JOIN tti tt ON tt.task_id = t.task_id
|
||||
SET t.is_del = 1, t.delete_time = n.now, t.delete_clerk_id = ?
|
||||
Reference in New Issue
Block a user