@@ -620,6 +620,48 @@ public void testBatchAndNoBatch() throws SQLException {
620620 }
621621
622622
623+ @ Test (groups = {"IT" })
624+ public void testSelectCountStarWithPreparedStatement () throws SQLException {
625+ if (Compatibility .skipDriverBugLowerThen ("0.4.5" )) {
626+ return ;
627+ }
628+ try (Connection conn = getConn ();
629+ Statement s = conn .createStatement ()) {
630+ s .execute ("create or replace table t1(a int, b string)" );
631+ s .execute ("insert into t1 values(1, 'a')" );
632+ s .execute ("insert into t1 values(2, 'b')" );
633+
634+ // COUNT(*) should not be parsed as a parameter
635+ String countSql = "SELECT COUNT(*) FROM t1" ;
636+ try (PreparedStatement ps = conn .prepareStatement (countSql )) {
637+ Assert .assertEquals (ps .getParameterMetaData ().getParameterCount (), 0 ,
638+ "COUNT(*) should have 0 parameters" );
639+ ResultSet rs = ps .executeQuery ();
640+ Assert .assertTrue (rs .next ());
641+ Assert .assertEquals (rs .getInt (1 ), 2 );
642+ }
643+
644+ // SUM with column should not be parsed as a parameter
645+ String sumSql = "SELECT SUM(a) FROM t1" ;
646+ try (PreparedStatement ps = conn .prepareStatement (sumSql )) {
647+ Assert .assertEquals (ps .getParameterMetaData ().getParameterCount (), 0 ,
648+ "SUM(a) should have 0 parameters" );
649+ ResultSet rs = ps .executeQuery ();
650+ Assert .assertTrue (rs .next ());
651+ Assert .assertEquals (rs .getInt (1 ), 3 );
652+ }
653+
654+ // SELECT with actual parameter marker should still work
655+ String selectWithParam = "SELECT COUNT(*) FROM t1 WHERE a = ?" ;
656+ try (PreparedStatement ps = conn .prepareStatement (selectWithParam )) {
657+ ps .setInt (1 , 1 );
658+ ResultSet rs = ps .executeQuery ();
659+ Assert .assertTrue (rs .next ());
660+ Assert .assertEquals (rs .getInt (1 ), 1 );
661+ }
662+ }
663+ }
664+
623665 @ Test (groups = {"IT" })
624666 public void testSelectWithPreparedStatement ()
625667 throws SQLException {
0 commit comments