Skip to content

Commit bdc62ba

Browse files
committed
feat: Add ODBC test configuration and workflow
This commit introduces a new ODBC test configuration in Cargo.toml and adds a corresponding GitHub Actions workflow for running ODBC tests with SQLite. The workflow includes steps for installing necessary dependencies and executing tests.
1 parent ce5f82e commit bdc62ba

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed

.github/workflows/sqlx.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,3 +343,36 @@ jobs:
343343
cargo test --no-default-features --features any,mssql,macros,migrate,all-types,runtime-${{ matrix.runtime }}-${{ matrix.tls }}
344344
env:
345345
DATABASE_URL: mssql://sa:Password123!@localhost/sqlx
346+
347+
odbc:
348+
name: ODBC (SQLite ODBC)
349+
runs-on: ubuntu-22.04
350+
needs: check
351+
steps:
352+
- uses: actions/checkout@v4
353+
- uses: dtolnay/rust-toolchain@stable
354+
- uses: Swatinem/rust-cache@v2
355+
with:
356+
prefix-key: v1-sqlx
357+
shared-key: odbc
358+
save-if: ${{ github.ref == 'refs/heads/main' }}
359+
- name: Install unixODBC and SQLite ODBC
360+
run: |
361+
sudo apt-get update
362+
sudo apt-get install -y unixodbc odbcinst odbcinst1debian2 odbc-sqlite3 sqlite3
363+
# Configure a system DSN named SQLX_ODBC using SQLite3 driver
364+
echo '[SQLite3]\nDescription=SQLite ODBC Driver\nDriver=libsqlite3odbc.so\nSetup=libsqlite3odbc.so\nThreading=2\n' | sudo tee -a /etc/odbcinst.ini
365+
echo '[SQLX_ODBC]\nDescription=SQLx SQLite DSN\nDriver=SQLite3\nDatabase=${{ github.workspace }}/tests/sqlite/sqlite.db\n' | sudo tee -a /etc/odbc.ini
366+
# Sanity check DSN
367+
echo 'select 1;' | isql -v SQLX_ODBC || true
368+
- name: Run clippy for odbc
369+
run: |
370+
cargo clippy \
371+
--no-default-features \
372+
--features odbc,all-types,runtime-tokio-rustls,macros,migrate \
373+
-- -D warnings
374+
- name: Run ODBC tests (SQLite DSN)
375+
run: |
376+
cargo test --no-default-features --features any,odbc,macros,all-types,runtime-tokio-rustls -- --test odbc
377+
env:
378+
DATABASE_URL: DSN=SQLX_ODBC

Cargo.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,15 @@ name = "mssql"
327327
path = "tests/mssql/mssql.rs"
328328
required-features = ["mssql"]
329329

330+
#
331+
# ODBC
332+
#
333+
334+
[[test]]
335+
name = "odbc"
336+
path = "tests/odbc/odbc.rs"
337+
required-features = ["odbc"]
338+
330339
[[test]]
331340
name = "mssql-types"
332341
path = "tests/mssql/types.rs"

tests/odbc/odbc.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
use sqlx_oldapi::odbc::Odbc;
2+
use sqlx_oldapi::Connection;
3+
use sqlx_test::new;
4+
5+
#[sqlx_macros::test]
6+
async fn it_connects_and_pings() -> anyhow::Result<()> {
7+
let mut conn = new::<Odbc>().await?;
8+
conn.ping().await?;
9+
conn.close().await?;
10+
Ok(())
11+
}
12+
13+
#[sqlx_macros::test]
14+
async fn it_can_work_with_transactions() -> anyhow::Result<()> {
15+
let mut conn = new::<Odbc>().await?;
16+
let tx = conn.begin().await?;
17+
tx.rollback().await?;
18+
Ok(())
19+
}
20+
21+

0 commit comments

Comments
 (0)