fix(iris): paginate table data via %VID window and fix count quoting
This commit is contained in:
3 files changed
+93
-19
No files matched your search
@@ -335,7 +335,7 @@ pub fn build_table_data_select_sql_with_database(
|
||||
if options.use_driver_row_offset {
|
||||
format!("SELECT {select_columns} FROM {table_alias}{where_clause}{order}")
|
||||
} else {
|
||||
format!("SELECT TOP {limit} {select_columns} FROM {table_alias}{where_clause}{order}")
|
||||
build_iris_table_select_sql(&select_columns, &table_alias, &where_clause, &order, limit, offset)
|
||||
}
|
||||
}
|
||||
TablePaginationStrategy::InformixFirst => {
|
||||
@@ -670,6 +670,31 @@ fn quoted_table_columns_or_star(database_type: Option<DatabaseType>, columns: &[
|
||||
.join(", ")
|
||||
}
|
||||
|
||||
/// Builds one page of a Caché/IRIS table read.
|
||||
///
|
||||
/// InterSystems SQL has `TOP` but no `OFFSET` clause — both Caché 2016 and IRIS
|
||||
/// reject `SELECT TOP n ... OFFSET m` — so later pages bound a derived table
|
||||
/// with `TOP(offset + limit)` and drop the leading rows with `%VID`, the row
|
||||
/// number InterSystems assigns to the rows a query produces. Running the same
|
||||
/// `TOP limit` statement for every page was the reason the grid kept showing
|
||||
/// the first page (#8929).
|
||||
fn build_iris_table_select_sql(
|
||||
select_columns: &str,
|
||||
table_alias: &str,
|
||||
where_clause: &str,
|
||||
order: &str,
|
||||
limit: usize,
|
||||
offset: usize,
|
||||
) -> String {
|
||||
if offset == 0 {
|
||||
return format!("SELECT TOP {limit} {select_columns} FROM {table_alias}{where_clause}{order}");
|
||||
}
|
||||
let window = offset.saturating_add(limit);
|
||||
format!(
|
||||
"SELECT * FROM (SELECT TOP {window} {select_columns} FROM {table_alias}{where_clause}{order}) WHERE %VID > {offset}"
|
||||
)
|
||||
}
|
||||
|
||||
fn build_rownum_table_select_sql(
|
||||
table: &str,
|
||||
where_clause: &str,
|
||||
|
||||
@@ -1173,6 +1173,46 @@ fn builds_iris_table_data_sql_with_literal_top_and_ordinary_object() {
|
||||
assert!(!sql.contains(" LIMIT "));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn iris_table_data_pages_use_a_vid_window_instead_of_a_repeated_top() {
|
||||
let options = TableDataSelectSqlOptions {
|
||||
database_type: Some(DatabaseType::Iris),
|
||||
schema: Some("Ens".to_string()),
|
||||
table_name: "AlarmResponse".to_string(),
|
||||
table_type: None,
|
||||
primary_keys: vec!["ID".to_string()],
|
||||
columns: vec!["ID".to_string(), "Status".to_string()],
|
||||
fallback_order_columns: Vec::new(),
|
||||
order_by: Some("ID ASC".to_string()),
|
||||
limit: Some(25),
|
||||
offset: Some(0),
|
||||
where_input: Some("WHERE Status = 'Open'".to_string()),
|
||||
include_row_id: false,
|
||||
..Default::default()
|
||||
};
|
||||
// First page keeps the historical TOP-only statement.
|
||||
assert_eq!(
|
||||
build_table_data_select_sql(options.clone()),
|
||||
"SELECT TOP 25 * FROM Ens.AlarmResponse WHERE (Status = 'Open') ORDER BY ID ASC"
|
||||
);
|
||||
// Later pages must move the window: InterSystems SQL has no OFFSET clause,
|
||||
// so the page is derived from TOP(offset + limit) and `%VID` drops the rows
|
||||
// before the offset (#8929).
|
||||
assert_eq!(
|
||||
build_table_data_select_sql(TableDataSelectSqlOptions { offset: Some(100), ..options.clone() }),
|
||||
"SELECT * FROM (SELECT TOP 125 * FROM Ens.AlarmResponse WHERE (Status = 'Open') ORDER BY ID ASC) WHERE %VID > 100"
|
||||
);
|
||||
// The JDBC driver applies the offset itself, so its statement stays unwrapped.
|
||||
assert_eq!(
|
||||
build_table_data_select_sql(TableDataSelectSqlOptions {
|
||||
offset: Some(100),
|
||||
use_driver_row_offset: true,
|
||||
..options
|
||||
}),
|
||||
"SELECT * FROM Ens.AlarmResponse WHERE (Status = 'Open') ORDER BY ID ASC"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn iris_table_data_sql_quotes_only_delimited_object_names() {
|
||||
let sql = build_table_data_select_sql(TableDataSelectSqlOptions {
|
||||
|
||||
Reference in new issue
Block a user