fix(jdbc): don't quote identifiers or use table aliases for JDBC
This commit is contained in:
parent
0411fd46b6
commit
34b37006be
|
|
@ -48,12 +48,3 @@ pub(super) fn is_simple_informix_identifier(name: &str) -> bool {
|
|||
(first.is_ascii_alphabetic() || first == '_')
|
||||
&& chars.all(|ch| ch.is_ascii_alphanumeric() || ch == '_' || ch == '$')
|
||||
}
|
||||
|
||||
pub(super) fn is_simple_jdbc_identifier(name: &str) -> bool {
|
||||
let mut chars = name.chars();
|
||||
let Some(first) = chars.next() else {
|
||||
return false;
|
||||
};
|
||||
(first.is_ascii_alphabetic() || first == '_')
|
||||
&& chars.all(|ch| ch.is_ascii_alphanumeric() || ch == '_' || ch == '$')
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use crate::models::connection::DatabaseType;
|
||||
|
||||
use super::capabilities::{is_schema_aware, is_simple_informix_identifier, is_simple_jdbc_identifier};
|
||||
use super::capabilities::{is_schema_aware, is_simple_informix_identifier};
|
||||
|
||||
pub fn qualified_table_name(database_type: Option<DatabaseType>, schema: Option<&str>, table_name: &str) -> String {
|
||||
if database_type == Some(DatabaseType::Iotdb) {
|
||||
|
|
@ -30,8 +30,10 @@ pub fn qualified_table_name(database_type: Option<DatabaseType>, schema: Option<
|
|||
pub fn quote_table_identifier(database_type: Option<DatabaseType>, name: &str) -> String {
|
||||
match database_type {
|
||||
Some(DatabaseType::Iotdb) => name.to_string(),
|
||||
Some(DatabaseType::Jdbc) if is_simple_jdbc_identifier(name) => name.to_string(),
|
||||
Some(DatabaseType::Jdbc) => format!("`{}`", name.replace('`', "``")),
|
||||
// JDBC connections use the driver-reported identifier quote string
|
||||
// (DatabaseMetaData.getIdentifierQuoteString()) inside the JDBC agent,
|
||||
// so the Rust layer passes identifiers through unquoted.
|
||||
Some(DatabaseType::Jdbc) => name.to_string(),
|
||||
Some(
|
||||
DatabaseType::Mysql
|
||||
| DatabaseType::Goldendb
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ pub fn build_table_data_select_sql(options: TableDataSelectSqlOptions) -> String
|
|||
let where_clause = if predicate.is_empty() { String::new() } else { format!(" WHERE ({predicate})") };
|
||||
let row_id_alias =
|
||||
if options.include_row_id && database_type == Some(DatabaseType::Oracle) { Some("t") } else { None };
|
||||
let default_order_alias = if database_type == Some(DatabaseType::Jdbc) { Some("dbx_t") } else { row_id_alias };
|
||||
let default_order_alias = if database_type == Some(DatabaseType::Jdbc) { None } else { row_id_alias };
|
||||
let default_order_by = if database_type == Some(DatabaseType::InfluxDb) {
|
||||
// InfluxQL only allows sorting of timestamp column
|
||||
Some("time DESC".to_string())
|
||||
|
|
@ -58,8 +58,6 @@ pub fn build_table_data_select_sql(options: TableDataSelectSqlOptions) -> String
|
|||
};
|
||||
let table_alias = if options.include_row_id && database_type.is_some_and(uses_fetch_first) {
|
||||
format!("{table} t")
|
||||
} else if database_type == Some(DatabaseType::Jdbc) && default_order_by.is_some() {
|
||||
format!("{table} dbx_t")
|
||||
} else {
|
||||
table
|
||||
};
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ fn quotes_identifiers_by_database_type() {
|
|||
assert_eq!(quote_table_identifier(Some(DatabaseType::Postgres), "user\"name"), "\"user\"\"name\"");
|
||||
assert_eq!(quote_table_identifier(Some(DatabaseType::Informix), "users_1"), "users_1");
|
||||
assert_eq!(quote_table_identifier(Some(DatabaseType::Jdbc), "users_1"), "users_1");
|
||||
assert_eq!(quote_table_identifier(Some(DatabaseType::Jdbc), "user name"), "`user name`");
|
||||
assert_eq!(quote_table_identifier(Some(DatabaseType::Jdbc), "user name"), "user name");
|
||||
assert_eq!(quote_table_identifier(Some(DatabaseType::Iotdb), "root.test.device2"), "root.test.device2");
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue