Skip to content

Commit 4f6adc1

Browse files
committed
fmt: apply formatting in ODBC worker and tests
1 parent 4d0ccdd commit 4f6adc1

File tree

3 files changed

+23
-35
lines changed

3 files changed

+23
-35
lines changed

.github/workflows/sqlx.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -378,13 +378,15 @@ jobs:
378378
cargo test --no-default-features --features odbc,all-types,runtime-tokio-rustls -- --test odbc-types
379379
env:
380380
DATABASE_URL: DSN=SQLX_PG_5432;UID=postgres;PWD=password
381+
- name: Detect SQLite ODBC driver name
382+
id: detect_sqlite
383+
run: |
384+
if odbcinst -q -d | grep -q '^\[SQLite3\]'; then echo "driver=SQLite3" >> $GITHUB_OUTPUT; elif odbcinst -q -d | grep -q '^\[SQLite\]'; then echo "driver=SQLite" >> $GITHUB_OUTPUT; else echo 'No SQLite ODBC driver installed'; exit 1; fi
381385
- name: Run ODBC tests (SQLite driver)
382386
run: |
383-
set -e
384-
if odbcinst -q -d | grep -q '^\[SQLite3\]'; then SQLITE_DRIVER=SQLite3; elif odbcinst -q -d | grep -q '^\[SQLite\]'; then SQLITE_DRIVER=SQLite; else echo 'No SQLite ODBC driver installed'; exit 1; fi
385-
echo "Using SQLite ODBC driver: ${SQLITE_DRIVER}"
387+
echo "Using SQLite ODBC driver: ${{ steps.detect_sqlite.outputs.driver }}"
386388
cargo test --no-default-features --features any,odbc,macros,all-types,runtime-tokio-rustls -- --test any-odbc
387389
cargo test --no-default-features --features odbc,all-types,runtime-tokio-rustls -- --test odbc
388390
cargo test --no-default-features --features odbc,all-types,runtime-tokio-rustls -- --test odbc-types
389391
env:
390-
DATABASE_URL: Driver={${{ env.SQLITE_DRIVER }}};Database=./tests/odbc/sqlite.db
392+
DATABASE_URL: Driver={${{ steps.detect_sqlite.outputs.driver }}};Database=./tests/odbc/sqlite.db

sqlx-core/src/odbc/connection/worker.rs

Lines changed: 14 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ enum Command {
4444
},
4545
}
4646

47-
4847
impl ConnectionWorker {
4948
pub async fn establish(options: OdbcConnectOptions) -> Result<Self, Error> {
5049
let (establish_tx, establish_rx) = oneshot::channel();
@@ -168,18 +167,14 @@ fn establish_connection(
168167
// to 'static, as ODBC connection borrows it. This is acceptable for long-lived
169168
// process and mirrors SQLite approach to background workers.
170169
let env = Box::leak(Box::new(
171-
odbc_api::Environment::new()
172-
.map_err(|e| Error::Configuration(e.to_string().into()))?,
170+
odbc_api::Environment::new().map_err(|e| Error::Configuration(e.to_string().into()))?,
173171
));
174172

175173
env.connect_with_connection_string(options.connection_string(), Default::default())
176174
.map_err(|e| Error::Configuration(e.to_string().into()))
177175
}
178176

179-
fn process_command(
180-
cmd: Command,
181-
conn: &odbc_api::Connection<'static>,
182-
) -> bool {
177+
fn process_command(cmd: Command, conn: &odbc_api::Connection<'static>) -> bool {
183178
match cmd {
184179
Command::Ping { tx } => handle_ping(conn, tx),
185180
Command::Begin { tx } => handle_transaction(conn, "BEGIN", tx),
@@ -232,7 +227,7 @@ fn handle_prepare(
232227
}
233228
Err(e) => Err(Error::from(e)),
234229
};
235-
230+
236231
let _ = tx.send(result);
237232
}
238233

@@ -244,7 +239,6 @@ fn execute_simple(conn: &odbc_api::Connection<'static>, sql: &str) -> Result<(),
244239
}
245240
}
246241

247-
248242
// SQL execution functions
249243
fn execute_sql(
250244
conn: &odbc_api::Connection<'static>,
@@ -253,15 +247,14 @@ fn execute_sql(
253247
tx: &flume::Sender<Result<Either<OdbcQueryResult, OdbcRow>, Error>>,
254248
) {
255249
let params = prepare_parameters(args);
256-
250+
257251
if params.is_empty() {
258252
dispatch_execute(conn, sql, (), tx);
259253
} else {
260254
dispatch_execute(conn, sql, &params[..], tx);
261255
}
262256
}
263257

264-
265258
fn prepare_parameters(
266259
args: Option<OdbcArguments>,
267260
) -> Vec<Box<dyn odbc_api::parameter::InputParameter>> {
@@ -295,33 +288,27 @@ fn dispatch_execute<P>(
295288
}
296289
}
297290

298-
299291
fn handle_cursor<C>(
300292
cursor: &mut C,
301293
tx: &flume::Sender<Result<Either<OdbcQueryResult, OdbcRow>, Error>>,
302294
) where
303295
C: Cursor + ResultSetMetadata,
304296
{
305297
let columns = collect_columns(cursor);
306-
298+
307299
if let Err(e) = stream_rows(cursor, &columns, tx) {
308300
send_error(tx, e);
309301
return;
310302
}
311-
303+
312304
send_empty_result(tx);
313305
}
314306

315-
fn send_empty_result(
316-
tx: &flume::Sender<Result<Either<OdbcQueryResult, OdbcRow>, Error>>,
317-
) {
307+
fn send_empty_result(tx: &flume::Sender<Result<Either<OdbcQueryResult, OdbcRow>, Error>>) {
318308
let _ = tx.send(Ok(Either::Left(OdbcQueryResult { rows_affected: 0 })));
319309
}
320310

321-
fn send_error(
322-
tx: &flume::Sender<Result<Either<OdbcQueryResult, OdbcRow>, Error>>,
323-
error: Error,
324-
) {
311+
fn send_error(tx: &flume::Sender<Result<Either<OdbcQueryResult, OdbcRow>, Error>>, error: Error) {
325312
let _ = tx.send(Err(error));
326313
}
327314

@@ -331,7 +318,7 @@ where
331318
C: ResultSetMetadata,
332319
{
333320
let count = cursor.num_result_cols().unwrap_or(0);
334-
321+
335322
(1..=count)
336323
.map(|i| create_column(cursor, i as u16))
337324
.collect()
@@ -343,7 +330,7 @@ where
343330
{
344331
let mut cd = odbc_api::ColumnDescription::default();
345332
let _ = cursor.describe_col(index, &mut cd);
346-
333+
347334
OdbcColumn {
348335
name: decode_column_name(cd.name, index),
349336
type_info: OdbcTypeInfo::new(cd.data_type),
@@ -369,7 +356,7 @@ where
369356
columns: columns.to_vec(),
370357
values,
371358
};
372-
359+
373360
if tx.send(Ok(Either::Right(row_data))).is_err() {
374361
// Receiver dropped, stop processing
375362
break;
@@ -395,7 +382,7 @@ fn collect_column_value(
395382
column: &OdbcColumn,
396383
) -> Result<(OdbcTypeInfo, Option<Vec<u8>>), Error> {
397384
let col_idx = (index + 1) as u16;
398-
385+
399386
// Try text first
400387
match try_get_text(row, col_idx) {
401388
Ok(value) => Ok((column.type_info.clone(), value)),
@@ -409,10 +396,7 @@ fn collect_column_value(
409396
}
410397
}
411398

412-
fn try_get_text(
413-
row: &mut CursorRow<'_>,
414-
col_idx: u16,
415-
) -> Result<Option<Vec<u8>>, odbc_api::Error> {
399+
fn try_get_text(row: &mut CursorRow<'_>, col_idx: u16) -> Result<Option<Vec<u8>>, odbc_api::Error> {
416400
let mut buf = Vec::new();
417401
match row.get_text(col_idx, &mut buf)? {
418402
true => Ok(Some(buf)),
@@ -429,4 +413,4 @@ fn try_get_binary(
429413
true => Ok(Some(buf)),
430414
false => Ok(None),
431415
}
432-
}
416+
}

tests/any/odbc.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,9 @@ async fn it_prepares_and_reports_metadata_via_any_odbc() -> anyhow::Result<()> {
273273
async fn it_errors_on_wrong_parameter_count_via_any_odbc() -> anyhow::Result<()> {
274274
let mut conn = odbc_conn().await?;
275275

276-
let res = sqlx_oldapi::query("SELECT ? AS value").fetch_one(&mut conn).await;
276+
let res = sqlx_oldapi::query("SELECT ? AS value")
277+
.fetch_one(&mut conn)
278+
.await;
277279
assert!(res.is_err());
278280

279281
conn.close().await?;

0 commit comments

Comments
 (0)