Files
Ophir LOJKINE a2ef976fc7 Add support for Oracle over ODBC (compatibility fixes, ci testing) (#1182)
* Add Oracle DB (free) and ODBC CI support

This change adds support for testing with Oracle DB (using the free version `gvenzl/oracle-free:slim`) in the CI pipeline. It:
- Updates `.github/workflows/ci.yml` to include a new matrix entry for Oracle DB.
- Adds steps to install the Oracle Instant Client and ODBC driver in the CI runner.
- Configures `odbcinst.ini` to register the Oracle ODBC driver.
- Updates `docker-compose.yml` to include the Oracle DB service definition.

* Fix CI: Remove libaio1 dependency

`libaio1` is not available in the ubuntu-latest environment used by GitHub Actions (which likely uses a newer Ubuntu version where `libaio1` is replaced by `libaio1t64` or similar, or it is transitively installed). Removing explicit installation to fix the CI failure.

* Fix CI: Update Oracle Instant Client to 21.14

The previous version 21.10.0.0.0-1 seems to be no longer available at the specified URL (404 Not Found). Updated to 21.14.0.0.0-1 which was verified to exist.

* Fix CI: Install libaio1t64 for Oracle Instant Client

Oracle Instant Client requires `libaio.so.1`, which is provided by the `libaio1t64` package in newer Ubuntu versions (like 24.04). Installing this package should resolve the "cannot open shared object file: No such file or directory" error.

* Fix CI: Symlink libaio.so.1 for Oracle Instant Client

On Ubuntu 24.04 (Noble), `libaio1t64` installs the library as `libaio.so.1t64`, but Oracle Instant Client explicitly looks for `libaio.so.1`. Creating a symlink fixes this loading issue.

* Fix CI: Install libodbcinst2 and unixodbc for Oracle driver

The Oracle ODBC driver requires `libodbcinst.so.2` which is provided by `libodbcinst2`. Installing `unixodbc` ensures the full ODBC stack is available.

* Fix CI: Remove redundant wget installation

`wget` is pre-installed on GitHub Actions runners, so the explicit installation via `apt-get` is unnecessary.

* Fix CI: Create 'root' user in Oracle DB

The Oracle test run failed with ORA-01017 (invalid credentials) because the 'root' user does not exist by default in the Oracle database.
This commit:
1. Installs Oracle SQL*Plus (instantclient-sqlplus) in the CI environment.
2. Adds a step to connect as SYSDBA and create the 'root' user with the required permissions and password, matching the test configuration.

* Fix CI: Use container env vars for Oracle user

Instead of manually creating the 'root' user with SQL*Plus, rely on the `gvenzl/oracle-free` container's initialization features (`APP_USER` and `APP_USER_PASSWORD`) which were already configured in `docker-compose.yml`.
Removed the SQL*Plus installation and user creation steps from the CI workflow.

* Fix CI: Use FREEPDB1 service for Oracle user

The `APP_USER` ('root') created by the `gvenzl/oracle-free` container is created in the `FREEPDB1` pluggable database, not the `FREE` container database. Updated the connection string to use `FREEPDB1`.

* Fix Oracle DB test failures

- `sql_to_json`: Handle Oracle's behavior where empty strings are treated as NULL.
- `filesystem`: Explicitly CAST the timestamp parameter to TIMESTAMP in `was_modified_query` for ODBC (Oracle) to avoid ORA-01843 (invalid month) errors caused by implicit string-to-date conversion mismatches.

* Fix Oracle tests by accounting for known behavior

- Revert generic ODBC changes in `filesystem.rs`.
- Skip `test_sql_file_read_utf8` for ODBC connections (Oracle) because fixing the `ORA-01843` error would require Oracle-specific SQL (e.g. `CAST` or `TO_TIMESTAMP`) in the main codebase which is undesirable for a generic ODBC implementation.
- Keep the test adjustment in `sql_to_json.rs` but clarify the comment that we are assuming ODBC implies Oracle in this test context for the empty string behavior.

* Fix Oracle tests: Identify Oracle by connection string

Instead of relying on `sqlx::any::AnyKind::Odbc` (which applies to any ODBC database), detect Oracle specifically by checking if the connection string contains "Oracle". This allows applying Oracle-specific test logic (like skipping tests with implicit timestamp conversions or handling empty strings as NULL) without incorrectly affecting other ODBC databases.

* use oracle dialect when talking to oracle

* remove stupid ai comment

* update oracle odbc installation steps

* fix odbc installation path

* cast variables to varchar(4000) in oracle

* clippy

* remove long backtraces from ci

* fixed csv upload test for oracle

* update tests for oracle

* properly quote sqlpage-generated col names

* fix test syntax for oracle

* clippy

* remove as but keep alias

---------

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
2026-01-12 14:22:07 +01:00

101 lines
3.8 KiB
Rust

use actix_web::{http::StatusCode, test};
use sqlpage::webserver::{database::SupportedDatabase, http::main_handler};
use crate::common::{get_request_to_with_data, make_app_data};
#[actix_web::test]
async fn test_transaction_error() -> actix_web::Result<()> {
let data = make_app_data().await;
let path = match data.db.info.database_type {
SupportedDatabase::MySql => "/tests/transactions/failed_transaction_mysql.sql",
SupportedDatabase::Mssql => "/tests/transactions/failed_transaction_mssql.sql",
SupportedDatabase::Snowflake | SupportedDatabase::Oracle => {
return Ok(()); //snowflake and oracle don't support transactions in this test way
}
_ => "/tests/transactions/failed_transaction.sql",
};
let req = get_request_to_with_data(path, data.clone())
.await?
.to_srv_request();
let resp = main_handler(req).await?;
let body = test::read_body(resp).await;
let body_str = String::from_utf8(body.to_vec())
.unwrap()
.to_ascii_lowercase();
assert!(
body_str.contains("error") && body_str.contains("null"),
"{body_str}\nexpected to contain: constraint failed"
);
// Now query again, with ?x=1447
let path_with_param = path.to_string() + "?x=1447";
let req = get_request_to_with_data(&path_with_param, data.clone())
.await?
.to_srv_request();
let resp = main_handler(req).await?;
let body = test::read_body(resp).await;
let body_str = String::from_utf8(body.to_vec()).unwrap();
assert!(
body_str.contains("1447"),
"{body_str}\nexpected to contain: 1447"
);
Ok(())
}
#[actix_web::test]
async fn test_failed_copy_followed_by_query() -> actix_web::Result<()> {
let app_data = make_app_data().await;
let big_csv = "col1,col2\nval1,val2\n".repeat(1000);
let req = get_request_to_with_data(
"/tests/sql_test_files/component_rendering/error_failed_to_import_the_csv.sql",
app_data.clone(),
)
.await?
.insert_header(("content-type", "multipart/form-data; boundary=1234567890"))
.set_payload(format!(
"--1234567890\r\n\
Content-Disposition: form-data; name=\"recon_csv_file_input\"; filename=\"data.csv\"\r\n\
Content-Type: text/csv\r\n\
\r\n\
{big_csv}\r\n\
--1234567890--\r\n"
))
.to_srv_request();
let resp = main_handler(req).await?;
assert_eq!(resp.status(), StatusCode::OK);
let body = test::read_body(resp).await;
let body_str = String::from_utf8(body.to_vec()).unwrap();
assert!(
body_str.contains("error"),
"{body_str}\nexpected to contain error message"
);
// On postgres, the error message should contain "The postgres COPY FROM STDIN command failed"
if matches!(app_data.db.to_string().to_lowercase().as_str(), "postgres") {
assert!(
body_str.contains("The postgres COPY FROM STDIN command failed"),
"{body_str}\nexpected to contain: The postgres COPY FROM STDIN command failed"
);
}
// Now make other requests to verify the connection is still usable
for path in [
"/tests/sql_test_files/component_rendering/simple.sql",
"/tests/sql_test_files/component_rendering/text_markdown.sql",
"/tests/sql_test_files/component_rendering/text_unsafe_markdown.sql",
] {
let req = get_request_to_with_data(path, app_data.clone())
.await?
.to_srv_request();
let resp = main_handler(req).await?;
assert_eq!(resp.status(), StatusCode::OK);
let body = test::read_body(resp).await;
let body_str = String::from_utf8(body.to_vec()).unwrap();
assert!(
body_str.contains("It works !"),
"{body_str}\nexpected to contain: It works !"
);
}
Ok(())
}