@@ -317,6 +317,44 @@ public void testLimit2() throws JSQLParserException {
317
317
assertSqlCanBeParsedAndDeparsed (statement );
318
318
}
319
319
320
+ public void testLimit3 () throws JSQLParserException {
321
+ String statement = "SELECT * FROM mytable WHERE mytable.col = 9 LIMIT ?1, 2" ;
322
+
323
+ Select select = (Select ) parserManager .parse (new StringReader (statement ));
324
+
325
+ assertEquals (2 , ((PlainSelect ) select .getSelectBody ()).getLimit ().getRowCount ());
326
+ assertEquals (1 , (int )((PlainSelect ) select .getSelectBody ()).getLimit ().getOffsetJdbcParameter ().getIndex ());
327
+ assertFalse (((PlainSelect ) select .getSelectBody ()).getLimit ().isLimitAll ());
328
+
329
+ statement = "SELECT * FROM mytable WHERE mytable.col = 9 LIMIT 1, ?2" ;
330
+ select = (Select ) parserManager .parse (new StringReader (statement ));
331
+ assertEquals (1 , ((PlainSelect ) select .getSelectBody ()).getLimit ().getOffset ());
332
+ assertFalse (((PlainSelect ) select .getSelectBody ()).getLimit ().getOffsetJdbcParameter () != null );
333
+ assertEquals (2 , (int )((PlainSelect ) select .getSelectBody ()).getLimit ().getRowCountJdbcParameter ().getIndex ());
334
+ assertFalse (((PlainSelect ) select .getSelectBody ()).getLimit ().isLimitAll ());
335
+
336
+ statement = "SELECT * FROM mytable WHERE mytable.col = 9 LIMIT ?1, ?2" ;
337
+ select = (Select ) parserManager .parse (new StringReader (statement ));
338
+ assertEquals (0 , ((PlainSelect ) select .getSelectBody ()).getLimit ().getOffset ());
339
+ assertEquals (1 , (int )((PlainSelect ) select .getSelectBody ()).getLimit ().getOffsetJdbcParameter ().getIndex ());
340
+ assertEquals (2 , (int )((PlainSelect ) select .getSelectBody ()).getLimit ().getRowCountJdbcParameter ().getIndex ());
341
+ assertFalse (((PlainSelect ) select .getSelectBody ()).getLimit ().isLimitAll ());
342
+
343
+ statement = "SELECT * FROM mytable WHERE mytable.col = 9 LIMIT 1, ?" ;
344
+ select = (Select ) parserManager .parse (new StringReader (statement ));
345
+ assertEquals (1 , ((PlainSelect ) select .getSelectBody ()).getLimit ().getOffset ());
346
+ assertFalse (((PlainSelect ) select .getSelectBody ()).getLimit ().getOffsetJdbcParameter () != null );
347
+ assertNull (((PlainSelect ) select .getSelectBody ()).getLimit ().getRowCountJdbcParameter ().getIndex ());
348
+ assertFalse (((PlainSelect ) select .getSelectBody ()).getLimit ().isLimitAll ());
349
+
350
+ statement = "SELECT * FROM mytable WHERE mytable.col = 9 LIMIT ?, ?" ;
351
+ select = (Select ) parserManager .parse (new StringReader (statement ));
352
+ assertEquals (0 , ((PlainSelect ) select .getSelectBody ()).getLimit ().getOffset ());
353
+ assertNull (((PlainSelect ) select .getSelectBody ()).getLimit ().getOffsetJdbcParameter ().getIndex ());
354
+ assertNull (((PlainSelect ) select .getSelectBody ()).getLimit ().getRowCountJdbcParameter ().getIndex ());
355
+ assertFalse (((PlainSelect ) select .getSelectBody ()).getLimit ().isLimitAll ());
356
+ }
357
+
320
358
public void testLimitSqlServer1 () throws JSQLParserException {
321
359
String statement = "SELECT * FROM mytable WHERE mytable.col = 9 ORDER BY mytable.id OFFSET 3 ROWS FETCH NEXT 5 ROWS ONLY" ;
322
360
@@ -2286,6 +2324,10 @@ public void testProblemKeywordCommitIssue341() throws JSQLParserException {
2286
2324
assertSqlCanBeParsedAndDeparsed ("SELECT id, commit FROM table1" );
2287
2325
}
2288
2326
2327
+ public void testProblemSqlIssue352 () throws JSQLParserException {
2328
+ assertSqlCanBeParsedAndDeparsed ( "SELECT @rowNO from (SELECT @rowNO from dual) r" , true );
2329
+ }
2330
+
2289
2331
public void testProblemIsIssue331 () throws JSQLParserException {
2290
2332
assertSqlCanBeParsedAndDeparsed ("SELECT C_DocType.C_DocType_ID,NULL,COALESCE(C_DocType_Trl.Name,C_DocType.Name) AS Name,C_DocType.IsActive FROM C_DocType LEFT JOIN C_DocType_TRL ON (C_DocType.C_DocType_ID=C_DocType_Trl.C_DocType_ID AND C_DocType_Trl.AD_Language='es_AR') WHERE C_DocType.AD_Client_ID=1010016 AND C_DocType.AD_Client_ID IN (0,1010016) AND C_DocType.c_doctype_id in ( select c_doctype2.c_doctype_id from c_doctype as c_doctype2 where substring( c_doctype2.printname,6, length(c_doctype2.printname) ) = ( select letra from c_letra_comprobante as clc where clc.c_letra_comprobante_id = 1010039) ) AND ( (1010094!=0 AND C_DocType.ad_org_id = 1010094) OR 1010094=0 ) ORDER BY 3 LIMIT 2000" , true );
2291
2333
}
0 commit comments