fix(jdbc): skip SQL-level row limiting for JDBC connections

This commit is contained in:
t8y2 committed 2026-06-17 01:00:09 +08:00
1 parent 63bb6a21ca
commit 0411fd46b6
5 files changed
+26 -1

No files matched your search

@@ -123,6 +123,11 @@ pub fn build_table_data_select_sql(options: TableDataSelectSqlOptions) -> String
let offset =
options.offset.filter(|offset| *offset > 0).map(|offset| format!(" OFFSET {offset}")).unwrap_or_default();
// JDBC connections rely on Statement.setMaxRows() for row limiting instead of
// SQL-level LIMIT, which is not universally supported across all JDBC drivers.
if database_type == Some(DatabaseType::Jdbc) {
return format!("SELECT {select_columns} FROM {table_alias}{where_clause}{order};");
}
format!("SELECT {select_columns} FROM {table_alias}{where_clause}{order} LIMIT {limit}{offset};")
}
@@ -170,6 +175,11 @@ pub fn build_table_select_sql(options: TableSelectSqlOptions<'_>) -> String {
return format!("SELECT TOP ({limit}) {select_columns} FROM {table}{order_by}");
}
// JDBC connections rely on Statement.setMaxRows() for row limiting.
if database_type == Some(DatabaseType::Jdbc) {
return format!("SELECT {select_columns} FROM {table}{order_by};");
}
format!("SELECT {select_columns} FROM {table}{order_by} LIMIT {limit};")
}
+3 -1
View File
@@ -82,6 +82,8 @@ fn builds_select_sql_with_limit_syntax_for_database_type() {
}),
"SELECT \"id\", \"name\" FROM \"DB2INST1\".\"USERS\" ORDER BY \"id\" ASC FETCH FIRST 100 ROWS ONLY"
);
// JDBC connections skip SQL-level row limiting — the JDBC agent handles
// it via Statement.setMaxRows() which is universally supported.
assert_eq!(
build_table_select_sql(TableSelectSqlOptions {
database_type: Some(DatabaseType::Jdbc),
@@ -91,7 +93,7 @@ fn builds_select_sql_with_limit_syntax_for_database_type() {
order_columns: &[],
limit: 100,
}),
"SELECT * FROM dwd_test_df LIMIT 100;"
"SELECT * FROM dwd_test_df;"
);
assert_eq!(
build_table_select_sql(TableSelectSqlOptions {