77import com .clickhouse .client .api .query .QuerySettings ;
88import com .clickhouse .client .api .sql .SQLUtils ;
99import com .clickhouse .jdbc .internal .ExceptionUtils ;
10+ import com .clickhouse .jdbc .internal .FeatureManager ;
1011import com .clickhouse .jdbc .internal .ParsedStatement ;
1112import org .slf4j .Logger ;
1213import org .slf4j .LoggerFactory ;
@@ -29,6 +30,7 @@ public class StatementImpl implements Statement, JdbcV2Wrapper {
2930 ConnectionImpl connection ;
3031 protected int queryTimeout ;
3132 protected boolean isPoolable = false ; // Statement is not poolable by default
33+ private final FeatureManager featureManager ;
3234
3335 // State
3436 private volatile boolean closed ;
@@ -60,6 +62,7 @@ public StatementImpl(ConnectionImpl connection) throws SQLException {
6062 this .resultSets = new ConcurrentLinkedQueue <>();
6163 this .resultSetAutoClose = connection .getJdbcConfig ().isSet (DriverProperties .RESULTSET_AUTO_CLOSE );
6264 this .escapeProcessingEnabled = true ;
65+ this .featureManager = new FeatureManager (connection .getJdbcConfig ());
6366 }
6467
6568 protected void ensureOpen () throws SQLException {
@@ -458,22 +461,22 @@ public boolean getMoreResults(int current) throws SQLException {
458461 return false ; // false indicates that no more results (or it is an update count)
459462 }
460463
461- // @Override
464+ // @Override -- because doesn't exist in Java 8
462465 public String enquoteLiteral (String val ) throws SQLException {
463466 return SQLUtils .enquoteLiteral (val );
464467 }
465468
466- // @Override
469+ // @Override -- because doesn't exist in Java 8
467470 public String enquoteIdentifier (String identifier , boolean alwaysQuote ) throws SQLException {
468471 return SQLUtils .enquoteIdentifier (identifier , alwaysQuote );
469472 }
470473
471- // @Override
474+ // @Override -- because doesn't exist in Java 8
472475 public boolean isSimpleIdentifier (String identifier ) throws SQLException {
473476 return SQLUtils .isSimpleIdentifier (identifier );
474477 }
475478
476- // @Override
479+ // @Override -- because doesn't exist in Java 8
477480 public String enquoteNCharLiteral (String val ) throws SQLException {
478481 if (val == null ) {
479482 throw new NullPointerException ();
@@ -489,31 +492,37 @@ public ResultSet getGeneratedKeys() throws SQLException {
489492
490493 @ Override
491494 public int executeUpdate (String sql , int autoGeneratedKeys ) throws SQLException {
495+ featureManager .unsupportedFeatureThrow ("executeUpdate(String, int)" , autoGeneratedKeys != Statement .NO_GENERATED_KEYS );
492496 return executeUpdate (sql );
493497 }
494498
495499 @ Override
496500 public int executeUpdate (String sql , int [] columnIndexes ) throws SQLException {
501+ featureManager .unsupportedFeatureThrow ("executeUpdate(String, int[])" );
497502 return executeUpdate (sql );
498503 }
499504
500505 @ Override
501506 public int executeUpdate (String sql , String [] columnNames ) throws SQLException {
507+ featureManager .unsupportedFeatureThrow ("executeUpdate(String, String[])" );
502508 return executeUpdate (sql );
503509 }
504510
505511 @ Override
506512 public boolean execute (String sql , int autoGeneratedKeys ) throws SQLException {
513+ featureManager .unsupportedFeatureThrow ("execute(String, int)" , autoGeneratedKeys != Statement .NO_GENERATED_KEYS );
507514 return execute (sql );
508515 }
509516
510517 @ Override
511518 public boolean execute (String sql , int [] columnIndexes ) throws SQLException {
519+ featureManager .unsupportedFeatureThrow ("execute(String, int[])" );
512520 return execute (sql );
513521 }
514522
515523 @ Override
516524 public boolean execute (String sql , String [] columnNames ) throws SQLException {
525+ featureManager .unsupportedFeatureThrow ("execute(String, String[])" );
517526 return execute (sql );
518527 }
519528
@@ -573,20 +582,23 @@ public long getLargeUpdateCount() throws SQLException {
573582 public void setLargeMaxRows (long max ) throws SQLException {
574583 ensureOpen ();
575584 maxRows = max ;
576- // This method override user set overflow mode on purpose:
577- // 1. Spec clearly states that after calling this method with a limit > 0 all rows over limit are dropped.
578- // 2. Calling this method should not cause throwing exception for future queries what only `break` can guarantee
579- // 3. If user wants different behavior then they are can use connection properties.
580- if (max > 0 ) {
581- localSettings .setOption (ClientConfigProperties .serverSetting (ServerSettings .MAX_RESULT_ROWS ), maxRows );
582- localSettings .setOption (ClientConfigProperties .serverSetting (ServerSettings .RESULT_OVERFLOW_MODE ),
583- ServerSettings .RESULT_OVERFLOW_MODE_BREAK );
584- } else {
585- // overriding potential client settings (set thru connection setup)
586- // there is no no limit value so we use very large limit.
587- localSettings .setOption (ClientConfigProperties .serverSetting (ServerSettings .MAX_RESULT_ROWS ), Long .MAX_VALUE );
588- localSettings .setOption (ClientConfigProperties .serverSetting (ServerSettings .RESULT_OVERFLOW_MODE ),
589- ServerSettings .RESULT_OVERFLOW_MODE_BREAK );
585+
586+ if (connection .getJdbcConfig ().isFlagSet (DriverProperties .USE_MAX_RESULT_ROWS )) {
587+ // This method override user set overflow mode on purpose:
588+ // 1. Spec clearly states that after calling this method with a limit > 0 all rows over limit are dropped.
589+ // 2. Calling this method should not cause throwing exception for future queries what only `break` can guarantee
590+ // 3. If user wants different behavior then they are can use connection properties.
591+ if (max > 0 ) {
592+ localSettings .setOption (ClientConfigProperties .serverSetting (ServerSettings .MAX_RESULT_ROWS ), maxRows );
593+ localSettings .setOption (ClientConfigProperties .serverSetting (ServerSettings .RESULT_OVERFLOW_MODE ),
594+ ServerSettings .RESULT_OVERFLOW_MODE_BREAK );
595+ } else {
596+ // overriding potential client settings (set thru connection setup)
597+ // there is no no limit value so we use very large limit.
598+ localSettings .setOption (ClientConfigProperties .serverSetting (ServerSettings .MAX_RESULT_ROWS ), Long .MAX_VALUE );
599+ localSettings .setOption (ClientConfigProperties .serverSetting (ServerSettings .RESULT_OVERFLOW_MODE ),
600+ ServerSettings .RESULT_OVERFLOW_MODE_BREAK );
601+ }
590602 }
591603 }
592604
0 commit comments