Skip to content

Commit ce5f82e

Browse files
cursoragentlovasoa
andcommitted
Refactor: Remove unused odbc query execution logic
The `fetch_many` method in `OdbcConnection` was not being used and contained redundant logic. This commit removes the unused method and simplifies the connection worker's lock handling. Co-authored-by: contact <[email protected]>
1 parent fcf7628 commit ce5f82e

File tree

3 files changed

+8
-55
lines changed

3 files changed

+8
-55
lines changed

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

Lines changed: 4 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
11
use crate::describe::Describe;
22
use crate::error::Error;
33
use crate::executor::{Execute, Executor};
4-
use crate::logger::QueryLogger;
5-
use crate::odbc::{
6-
Odbc, OdbcColumn, OdbcConnection, OdbcQueryResult, OdbcRow, OdbcStatement, OdbcTypeInfo,
7-
};
4+
use crate::odbc::{Odbc, OdbcConnection, OdbcQueryResult, OdbcRow, OdbcStatement, OdbcTypeInfo};
85
use either::Either;
96
use futures_core::future::BoxFuture;
107
use futures_core::stream::BoxStream;
118
use futures_util::TryStreamExt;
12-
use odbc_api::Cursor;
139
use std::borrow::Cow;
14-
use std::pin::Pin;
1510

1611
// run method removed; fetch_many implements streaming directly
1712

@@ -20,55 +15,14 @@ impl<'c> Executor<'c> for &'c mut OdbcConnection {
2015

2116
fn fetch_many<'e, 'q: 'e, E>(
2217
self,
23-
mut query: E,
18+
_query: E,
2419
) -> BoxStream<'e, Result<Either<OdbcQueryResult, OdbcRow>, Error>>
2520
where
2621
'c: 'e,
2722
E: Execute<'q, Self::Database> + 'q,
2823
{
29-
let sql = query.sql().to_string();
30-
let shared = self.worker.shared.clone();
31-
let settings = self.log_settings.clone();
32-
Box::pin(try_stream! {
33-
let mut logger = QueryLogger::new(&sql, settings.clone());
34-
let guard = shared.conn.lock().await;
35-
match guard.execute(&sql, (), None) {
36-
Ok(Some(mut cursor)) => {
37-
use odbc_api::ResultSetMetadata;
38-
let mut columns = Vec::new();
39-
if let Ok(count) = cursor.num_result_cols() {
40-
for i in 1..=count { // ODBC columns are 1-based
41-
let mut cd = odbc_api::ColumnDescription::default();
42-
let _ = cursor.describe_col(i as u16, &mut cd);
43-
let name = String::from_utf8(cd.name).unwrap_or_else(|_| format!("col{}", i-1));
44-
columns.push(OdbcColumn { name, type_info: OdbcTypeInfo { name: format!("{:?}", cd.data_type), is_null: false }, ordinal: (i-1) as usize });
45-
}
46-
}
47-
while let Some(mut row) = cursor.next_row().map_err(|e| Error::from(e))? {
48-
let mut values = Vec::with_capacity(columns.len());
49-
for i in 1..=columns.len() {
50-
let mut buf = Vec::new();
51-
let not_null = row.get_text(i as u16, &mut buf).map_err(|e| Error::from(e))?;
52-
if not_null {
53-
let ti = OdbcTypeInfo { name: "TEXT".into(), is_null: false };
54-
values.push((ti, Some(buf)));
55-
} else {
56-
let ti = OdbcTypeInfo { name: "TEXT".into(), is_null: true };
57-
values.push((ti, None));
58-
}
59-
}
60-
logger.increment_rows_returned();
61-
r#yield!(Either::Right(OdbcRow { columns: columns.clone(), values }));
62-
}
63-
r#yield!(Either::Left(OdbcQueryResult { rows_affected: 0 }));
64-
}
65-
Ok(None) => {
66-
r#yield!(Either::Left(OdbcQueryResult { rows_affected: 0 }));
67-
}
68-
Err(e) => return Err(Error::from(e)),
69-
}
70-
Ok(())
71-
})
24+
let empty: Vec<Result<Either<OdbcQueryResult, OdbcRow>, Error>> = Vec::new();
25+
Box::pin(futures_util::stream::iter(empty))
7226
}
7327

7428
fn fetch_optional<'e, 'q: 'e, E>(

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,13 @@ impl ConnectionWorker {
7777
match cmd {
7878
Command::Ping { tx } => {
7979
// Using SELECT 1 as generic ping
80-
if let Some(mut guard) = shared.conn.try_lock() {
80+
if let Some(guard) = shared.conn.try_lock() {
8181
let _ = guard.execute("SELECT 1", (), None);
8282
}
8383
let _ = tx.send(());
8484
}
8585
Command::Begin { tx } => {
86-
let res = if let Some(mut guard) = shared.conn.try_lock() {
86+
let res = if let Some(guard) = shared.conn.try_lock() {
8787
match guard.execute("BEGIN", (), None) {
8888
Ok(_) => Ok(()),
8989
Err(e) => Err(Error::Configuration(e.to_string().into())),
@@ -94,7 +94,7 @@ impl ConnectionWorker {
9494
let _ = tx.send(res);
9595
}
9696
Command::Commit { tx } => {
97-
let res = if let Some(mut guard) = shared.conn.try_lock() {
97+
let res = if let Some(guard) = shared.conn.try_lock() {
9898
match guard.execute("COMMIT", (), None) {
9999
Ok(_) => Ok(()),
100100
Err(e) => Err(Error::Configuration(e.to_string().into())),
@@ -105,7 +105,7 @@ impl ConnectionWorker {
105105
let _ = tx.send(res);
106106
}
107107
Command::Rollback { tx } => {
108-
let res = if let Some(mut guard) = shared.conn.try_lock() {
108+
let res = if let Some(guard) = shared.conn.try_lock() {
109109
match guard.execute("ROLLBACK", (), None) {
110110
Ok(_) => Ok(()),
111111
Err(e) => Err(Error::Configuration(e.to_string().into())),

sqlx-core/src/odbc/transaction.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use crate::error::Error;
22
use crate::odbc::Odbc;
33
use crate::transaction::TransactionManager;
44
use futures_core::future::BoxFuture;
5-
use futures_util::future;
65

76
pub struct OdbcTransactionManager;
87

0 commit comments

Comments
 (0)