fix(jdbc): skip SQL-level row limiting for JDBC connections
This commit is contained in:
parent
63bb6a21ca
commit
0411fd46b6
|
|
@ -787,6 +787,11 @@ fn build_data_compare_select_sql(
|
|||
);
|
||||
}
|
||||
|
||||
// JDBC connections rely on Statement.setMaxRows() for row limiting.
|
||||
if database_type == DatabaseType::Jdbc {
|
||||
return format!("SELECT {select_columns} FROM {table}{order_by};");
|
||||
}
|
||||
|
||||
let offset_sql = if offset > 0 { format!(" OFFSET {offset}") } else { String::new() };
|
||||
format!("SELECT {select_columns} FROM {table}{order_by} LIMIT {row_limit}{offset_sql};")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -111,6 +111,9 @@ pub fn build_database_search_sql(options: DatabaseSearchSqlOptions) -> Option<Da
|
|||
format!("SELECT TOP {limit} * FROM {table} WHERE ({where_clause})")
|
||||
} else if options.database_type.is_some_and(uses_fetch_first) {
|
||||
format!("SELECT * FROM {table} WHERE ({where_clause}) FETCH FIRST {limit} ROWS ONLY")
|
||||
} else if options.database_type == Some(DatabaseType::Jdbc) {
|
||||
// JDBC connections rely on Statement.setMaxRows() for row limiting.
|
||||
format!("SELECT * FROM {table} WHERE ({where_clause});")
|
||||
} else {
|
||||
format!("SELECT * FROM {table} WHERE ({where_clause}) LIMIT {limit};")
|
||||
};
|
||||
|
|
|
|||
|
|
@ -207,6 +207,11 @@ pub fn build_paginated_query_sql(options: PaginatedQuerySqlOptions) -> QuerySqlB
|
|||
return ok(add_fetch_first_limit(&statement, safe_limit, safe_offset));
|
||||
}
|
||||
|
||||
// JDBC connections rely on Statement.setMaxRows() for row limiting.
|
||||
if options.database_type == Some(DatabaseType::Jdbc) {
|
||||
return ok(format!("{statement};"));
|
||||
}
|
||||
|
||||
ok(add_standard_limit(&statement, safe_limit, safe_offset))
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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};")
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Reference in New Issue