fix(oracle): skip rowid for view data queries
This commit is contained in:
1 parent
7e7c4944e9
commit
223ecbec20
16 files changed
+78
-31
No files matched your search
@@ -29,8 +29,13 @@ pub fn build_table_data_select_sql(options: TableDataSelectSqlOptions) -> String
|
||||
};
|
||||
let order_by = options.order_by.as_deref().filter(|order| !order.trim().is_empty()).or(default_order_by.as_deref());
|
||||
let order = order_by.map(|order_by| format!(" ORDER BY {order_by}")).unwrap_or_default();
|
||||
// Oracle join views can raise ORA-01445 when ROWID is selected; keep the
|
||||
// synthetic ROWID fallback scoped to base-table reads.
|
||||
let include_oracle_row_id = options.include_row_id
|
||||
&& database_type == Some(DatabaseType::Oracle)
|
||||
&& !is_view_table_type(options.table_type.as_deref());
|
||||
|
||||
let select_columns = if options.include_row_id && database_type == Some(DatabaseType::Oracle) {
|
||||
let select_columns = if include_oracle_row_id {
|
||||
format!("ROWIDTOCHAR(t.ROWID) AS \"{DBX_ROWID_COLUMN}\", t.*")
|
||||
} else {
|
||||
build_select_columns(
|
||||
@@ -40,7 +45,7 @@ pub fn build_table_data_select_sql(options: TableDataSelectSqlOptions) -> String
|
||||
)
|
||||
};
|
||||
let rownum_select_columns = quoted_table_columns_or_star(database_type, &options.columns);
|
||||
let page_select_columns = if options.include_row_id && database_type == Some(DatabaseType::Oracle) {
|
||||
let page_select_columns = if include_oracle_row_id {
|
||||
if options.columns.is_empty() {
|
||||
"*".to_string()
|
||||
} else {
|
||||
@@ -49,11 +54,8 @@ pub fn build_table_data_select_sql(options: TableDataSelectSqlOptions) -> String
|
||||
} else {
|
||||
rownum_select_columns.clone()
|
||||
};
|
||||
let table_alias = if options.include_row_id && database_type.is_some_and(uses_fetch_first) {
|
||||
format!("{table} t")
|
||||
} else {
|
||||
table
|
||||
};
|
||||
let table_alias =
|
||||
if include_oracle_row_id && database_type.is_some_and(uses_fetch_first) { format!("{table} t") } else { table };
|
||||
|
||||
match table_pagination_strategy(database_type) {
|
||||
TablePaginationStrategy::IrisTop => {
|
||||
@@ -88,11 +90,8 @@ pub fn build_table_data_select_sql(options: TableDataSelectSqlOptions) -> String
|
||||
)
|
||||
}
|
||||
TablePaginationStrategy::Rownum => {
|
||||
let rownum_inner_select_columns = if options.include_row_id && database_type == Some(DatabaseType::Oracle) {
|
||||
&select_columns
|
||||
} else {
|
||||
&rownum_select_columns
|
||||
};
|
||||
let rownum_inner_select_columns =
|
||||
if include_oracle_row_id { &select_columns } else { &rownum_select_columns };
|
||||
build_rownum_table_select_sql(
|
||||
&table_alias,
|
||||
&where_clause,
|
||||
@@ -136,6 +135,10 @@ pub fn build_table_data_select_sql(options: TableDataSelectSqlOptions) -> String
|
||||
}
|
||||
}
|
||||
|
||||
fn is_view_table_type(table_type: Option<&str>) -> bool {
|
||||
table_type.is_some_and(|value| value.to_ascii_uppercase().contains("VIEW"))
|
||||
}
|
||||
|
||||
pub fn build_table_select_sql(options: TableSelectSqlOptions<'_>) -> String {
|
||||
let database_type = options.database_type;
|
||||
let table = qualified_table_name(database_type, options.schema, options.table_name);
|
||||
|
||||
@@ -699,6 +699,23 @@ fn builds_oracle_and_neo4j_table_data_queries() {
|
||||
}),
|
||||
"SELECT \"__DBX_ROWID\", \"ID\", \"NAME\" FROM (SELECT ROWIDTOCHAR(t.ROWID) AS \"__DBX_ROWID\", t.* FROM \"DBXTEST\".\"DBX_LOAD_TABLE_006\" t) WHERE ROWNUM <= 100"
|
||||
);
|
||||
assert_eq!(
|
||||
build_table_data_select_sql(TableDataSelectSqlOptions {
|
||||
database_type: Some(DatabaseType::Oracle),
|
||||
schema: Some("DBXTEST".to_string()),
|
||||
table_name: "DBX_JOIN_VIEW".to_string(),
|
||||
table_type: Some("VIEW".to_string()),
|
||||
primary_keys: vec![DBX_ROWID_COLUMN.to_string()],
|
||||
columns: vec!["ID".to_string(), "NAME".to_string()],
|
||||
fallback_order_columns: Vec::new(),
|
||||
order_by: None,
|
||||
limit: Some(100),
|
||||
offset: None,
|
||||
where_input: None,
|
||||
include_row_id: true,
|
||||
}),
|
||||
"SELECT \"ID\", \"NAME\" FROM (SELECT \"ID\", \"NAME\" FROM \"DBXTEST\".\"DBX_JOIN_VIEW\") WHERE ROWNUM <= 100"
|
||||
);
|
||||
assert_eq!(
|
||||
build_table_data_select_sql(TableDataSelectSqlOptions {
|
||||
database_type: Some(DatabaseType::Neo4j),
|
||||
|
||||
Reference in new issue
Block a user