From 44aaea45bcdb24451786a47b40dbdcefb64ed457 Mon Sep 17 00:00:00 2001 From: akwei Date: Sat, 29 Sep 2012 16:39:00 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E8=A7=A3=E6=9E=90=E5=99=A8bu?= =?UTF-8?q?g=EF=BC=8C=E6=9C=AA=E4=BF=AE=E6=94=B9=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../halo/dal/analysis/antlr/v3/AntlrV3SQL.g | 29 +++++++++++++++---- .../java/halo/dal/analysis/antlr/v3/sql.txt | 10 +++++-- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/src/main/java/halo/dal/analysis/antlr/v3/AntlrV3SQL.g b/src/main/java/halo/dal/analysis/antlr/v3/AntlrV3SQL.g index 8df90cb..4f6875c 100644 --- a/src/main/java/halo/dal/analysis/antlr/v3/AntlrV3SQL.g +++ b/src/main/java/halo/dal/analysis/antlr/v3/AntlrV3SQL.g @@ -37,15 +37,29 @@ sql_update sql_select : - SELECT select_columns FROM tables - ((FULL|CROSS|INNER|LEFT|RIGHT) JOIN table (ON column_name '=' column_name)?)* - (WHERE kv ( and_or (kv | column_name op '\(' sql_select '\)') )*)? - (orderby|groupby|having)* + SELECT select_columns FROM (sqlAfterFrom|inner_select) (WHERE kv_sql)? (orderby|groupby|having)* + ; + +sqlAfterFrom + : + tables ((FULL|CROSS|INNER|LEFT|RIGHT) JOIN table (ON column_name '=' column_name)?)*; + +kv_sql_wrapper + : + kv_sql | '\(' kv_sql '\)' + ; +kv_sql : + kv ( and_or (kv | '\(' kv (and_or kv)* '\)') )* + ; + +inner_select + : + '\(' sql_select '\)' ; func : - BASIC_NAME '\(' (BASIC_NAME|'*') '\)' + BASIC_NAME '\(' (BASIC_NAME|'*')? '\)' ; func_and_alias @@ -117,9 +131,10 @@ insertColumn **/ } ; + kv : - (column_name op PRE_SET) + (column_name op (PRE_SET|'\(' PRE_SET '\)')) { colExprs.add(new String[]{$column_name.text,$op.text}); /** @@ -136,6 +151,8 @@ kv : column_name op column_name | column_name op func2 + | + column_name op '\(' sql_select '\)' ; func2 : diff --git a/src/main/java/halo/dal/analysis/antlr/v3/sql.txt b/src/main/java/halo/dal/analysis/antlr/v3/sql.txt index 1890769..a4b4e24 100644 --- a/src/main/java/halo/dal/analysis/antlr/v3/sql.txt +++ b/src/main/java/halo/dal/analysis/antlr/v3/sql.txt @@ -8,7 +8,7 @@ GATEWAYEVE0_.START_DATE AS START15_1_ FROM gateway_event1 GATEWAYEVE0_ , table2 as t2 WHERE 1=? and 1=2 or 3.5=6.7 and b='s do' and time=sysdate() or name=substring(a.b,'c',b,b.c,'') and kk=substring('') -and name between ? and ? +and name >= ? and name > ? and uid in (select * from user where sex=? order by gid desc group by ss having a=b.c) AND GATEWAYEVE0_.EVENT_STATUS=? @@ -18,7 +18,7 @@ FROM SELECT n.ID AS nodeId, n.name AS nodeName , f.name AS taskflowName, f.version AS taskflowVersion FROM HT_TASK_FLOW_NODE_WA_2 n, HT_TASK_FLOW_WA_2 f - WHERE n.owner = ? AND name between ? and ? and + WHERE n.owner = ? AND name >= ? and name <= ? and ( n.STATUS IN (?) AND n.GMT_MODIFIED < ? AND n.IS_AUTO = 'Y' AND n.task_flow_id = f.id ) @@ -40,4 +40,8 @@ sysdate() substring(a.b,'c',b,b.c,'') -substring('') \ No newline at end of file +substring('') + +select * from( +select id, name, rownumber() over(order by id asc) as rowid from db2.table_name +) temp where temp.rowid >= startNumber and temp.rowid <= endNumber \ No newline at end of file