Skip to content

Commit 28852da

Browse files
committed
refactor: Remove lifetime parameters from OdbcArguments and related types
This commit simplifies the OdbcArguments and OdbcArgumentValue structures by removing unnecessary lifetime parameters. The changes enhance code clarity and maintainability while ensuring that the functionality remains intact across the ODBC module. Additionally, adjustments were made to various encoding implementations to reflect these changes.
1 parent 2d3fd2b commit 28852da

File tree

17 files changed

+73
-95
lines changed

17 files changed

+73
-95
lines changed

sqlx-core/src/any/arguments.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,7 @@ pub(crate) enum AnyArgumentBufferKind<'q> {
4848
),
4949

5050
#[cfg(feature = "odbc")]
51-
Odbc(
52-
crate::odbc::OdbcArguments<'q>,
53-
std::marker::PhantomData<&'q ()>,
54-
),
51+
Odbc(crate::odbc::OdbcArguments, std::marker::PhantomData<&'q ()>),
5552
}
5653

5754
// control flow inferred type bounds would be fun
@@ -140,7 +137,7 @@ impl<'q> From<AnyArguments<'q>> for crate::postgres::PgArguments {
140137

141138
#[cfg(feature = "odbc")]
142139
#[allow(irrefutable_let_patterns)]
143-
impl<'q> From<AnyArguments<'q>> for crate::odbc::OdbcArguments<'q> {
140+
impl<'q> From<AnyArguments<'q>> for crate::odbc::OdbcArguments {
144141
fn from(args: AnyArguments<'q>) -> Self {
145142
let mut buf = AnyArgumentBuffer(AnyArgumentBufferKind::Odbc(
146143
Default::default(),

sqlx-core/src/odbc/arguments.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,20 @@ use crate::odbc::Odbc;
44
use crate::types::Type;
55

66
#[derive(Default)]
7-
pub struct OdbcArguments<'q> {
8-
pub(crate) values: Vec<OdbcArgumentValue<'q>>,
7+
pub struct OdbcArguments {
8+
pub(crate) values: Vec<OdbcArgumentValue>,
99
}
1010

1111
#[derive(Debug, Clone)]
12-
pub enum OdbcArgumentValue<'q> {
12+
pub enum OdbcArgumentValue {
1313
Text(String),
1414
Bytes(Vec<u8>),
1515
Int(i64),
1616
Float(f64),
1717
Null,
18-
// Borrowed placeholder to satisfy lifetimes; not used for now
19-
Phantom(std::marker::PhantomData<&'q ()>),
2018
}
2119

22-
impl<'q> Arguments<'q> for OdbcArguments<'q> {
20+
impl<'q> Arguments<'q> for OdbcArguments {
2321
type Database = Odbc;
2422

2523
fn reserve(&mut self, additional: usize, _size: usize) {
@@ -48,7 +46,7 @@ where
4846
}
4947
}
5048

51-
fn encode(self, buf: &mut Vec<OdbcArgumentValue<'q>>) -> crate::encode::IsNull {
49+
fn encode(self, buf: &mut Vec<OdbcArgumentValue>) -> crate::encode::IsNull {
5250
match self {
5351
Some(v) => v.encode(buf),
5452
None => {
@@ -58,7 +56,7 @@ where
5856
}
5957
}
6058

61-
fn encode_by_ref(&self, buf: &mut Vec<OdbcArgumentValue<'q>>) -> crate::encode::IsNull {
59+
fn encode_by_ref(&self, buf: &mut Vec<OdbcArgumentValue>) -> crate::encode::IsNull {
6260
match self {
6361
Some(v) => v.encode_by_ref(buf),
6462
None => {

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

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
use crate::describe::Describe;
22
use crate::error::Error;
33
use crate::executor::{Execute, Executor};
4-
use crate::odbc::{
5-
Odbc, OdbcArgumentValue, OdbcConnection, OdbcQueryResult, OdbcRow, OdbcStatement, OdbcTypeInfo,
6-
};
4+
use crate::odbc::{Odbc, OdbcConnection, OdbcQueryResult, OdbcRow, OdbcStatement, OdbcTypeInfo};
75
use either::Either;
86
use futures_core::future::BoxFuture;
97
use futures_core::stream::BoxStream;
@@ -17,28 +15,17 @@ impl<'c> Executor<'c> for &'c mut OdbcConnection {
1715

1816
fn fetch_many<'e, 'q: 'e, E>(
1917
self,
20-
mut _query: E,
18+
mut query: E,
2119
) -> BoxStream<'e, Result<Either<OdbcQueryResult, OdbcRow>, Error>>
2220
where
2321
'c: 'e,
2422
E: Execute<'q, Self::Database> + 'q,
2523
{
26-
let sql = _query.sql().to_string();
27-
let mut args = _query.take_arguments();
24+
let sql = query.sql().to_string();
25+
let mut args = query.take_arguments();
2826
Box::pin(try_stream! {
29-
let rx = if let Some(mut a) = args.take() {
30-
let vals: Vec<OdbcArgumentValue<'static>> = std::mem::take(&mut a.values)
31-
.into_iter()
32-
.map(|v| match v {
33-
OdbcArgumentValue::Text(s) => OdbcArgumentValue::Text(s),
34-
OdbcArgumentValue::Bytes(b) => OdbcArgumentValue::Bytes(b),
35-
OdbcArgumentValue::Int(i) => OdbcArgumentValue::Int(i),
36-
OdbcArgumentValue::Float(f) => OdbcArgumentValue::Float(f),
37-
OdbcArgumentValue::Null => OdbcArgumentValue::Null,
38-
OdbcArgumentValue::Phantom(_) => OdbcArgumentValue::Null,
39-
})
40-
.collect();
41-
self.worker.execute_stream_with_args(&sql, vals).await?
27+
let rx = if let Some(a) = args.take() {
28+
self.worker.execute_stream_with_args(&sql, a.values).await?
4229
} else {
4330
self.worker.execute_stream(&sql).await?
4431
};

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

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ enum Command {
4646
},
4747
ExecuteWithArgs {
4848
sql: Box<str>,
49-
args: Vec<OdbcArgumentValue<'static>>,
49+
args: Vec<OdbcArgumentValue>,
5050
tx: flume::Sender<Result<Either<OdbcQueryResult, OdbcRow>, Error>>,
5151
},
5252
}
@@ -193,7 +193,7 @@ impl ConnectionWorker {
193193
pub(crate) async fn execute_stream_with_args(
194194
&mut self,
195195
sql: &str,
196-
args: Vec<OdbcArgumentValue<'static>>,
196+
args: Vec<OdbcArgumentValue>,
197197
) -> Result<flume::Receiver<Result<Either<OdbcQueryResult, OdbcRow>, Error>>, Error> {
198198
let (tx, rx) = flume::bounded(64);
199199
self.command_tx
@@ -255,7 +255,7 @@ fn execute_sql(
255255
fn execute_sql_with_params(
256256
conn: &odbc_api::Connection<'static>,
257257
sql: &str,
258-
args: Vec<OdbcArgumentValue<'static>>,
258+
args: Vec<OdbcArgumentValue>,
259259
tx: &flume::Sender<Result<Either<OdbcQueryResult, OdbcRow>, Error>>,
260260
) {
261261
if args.is_empty() {
@@ -271,17 +271,13 @@ fn execute_sql_with_params(
271271
dispatch_execute(conn, sql, &params[..], tx);
272272
}
273273

274-
fn to_param(
275-
arg: OdbcArgumentValue<'static>,
276-
) -> Box<dyn odbc_api::parameter::InputParameter + 'static> {
274+
fn to_param(arg: OdbcArgumentValue) -> Box<dyn odbc_api::parameter::InputParameter + 'static> {
277275
match arg {
278276
OdbcArgumentValue::Int(i) => Box::new(i.into_parameter()),
279277
OdbcArgumentValue::Float(f) => Box::new(f.into_parameter()),
280278
OdbcArgumentValue::Text(s) => Box::new(s.into_parameter()),
281279
OdbcArgumentValue::Bytes(b) => Box::new(b.into_parameter()),
282-
OdbcArgumentValue::Null | OdbcArgumentValue::Phantom(_) => {
283-
Box::new(Option::<String>::None.into_parameter())
284-
}
280+
OdbcArgumentValue::Null => Box::new(Option::<String>::None.into_parameter()),
285281
}
286282
}
287283

sqlx-core/src/odbc/database.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ impl<'r> HasValueRef<'r> for Odbc {
3232
impl<'q> HasArguments<'q> for Odbc {
3333
type Database = Odbc;
3434

35-
type Arguments = crate::odbc::OdbcArguments<'q>;
35+
type Arguments = crate::odbc::OdbcArguments;
3636

37-
type ArgumentBuffer = Vec<crate::odbc::OdbcArgumentValue<'q>>;
37+
type ArgumentBuffer = Vec<crate::odbc::OdbcArgumentValue>;
3838
}
3939

4040
impl<'q> HasStatement<'q> for Odbc {

sqlx-core/src/odbc/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pub trait OdbcExecutor<'c>: Executor<'c, Database = Odbc> {}
3939
impl<'c, T: Executor<'c, Database = Odbc>> OdbcExecutor<'c> for T {}
4040

4141
// NOTE: required due to the lack of lazy normalization
42-
impl_into_arguments_for_arguments!(crate::odbc::OdbcArguments<'q>);
42+
impl_into_arguments_for_arguments!(crate::odbc::OdbcArguments);
4343
impl_executor_for_pool_connection!(Odbc, OdbcConnection, OdbcRow);
4444
impl_executor_for_transaction!(Odbc, OdbcRow);
4545
impl_column_index_for_row!(OdbcRow);

sqlx-core/src/odbc/statement.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ impl<'q> Statement<'q> for OdbcStatement<'q> {
3434
}
3535

3636
// ODBC arguments placeholder
37-
impl_statement_query!(crate::odbc::OdbcArguments<'_>);
37+
impl_statement_query!(crate::odbc::OdbcArguments);
3838
}
3939

4040
impl ColumnIndex<OdbcStatement<'_>> for &'_ str {

sqlx-core/src/odbc/types/bigdecimal.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ impl Type<Odbc> for BigDecimal {
2323
}
2424

2525
impl<'q> Encode<'q, Odbc> for BigDecimal {
26-
fn encode(self, buf: &mut Vec<OdbcArgumentValue<'q>>) -> crate::encode::IsNull {
26+
fn encode(self, buf: &mut Vec<OdbcArgumentValue>) -> crate::encode::IsNull {
2727
buf.push(OdbcArgumentValue::Text(self.to_string()));
2828
crate::encode::IsNull::No
2929
}
3030

31-
fn encode_by_ref(&self, buf: &mut Vec<OdbcArgumentValue<'q>>) -> crate::encode::IsNull {
31+
fn encode_by_ref(&self, buf: &mut Vec<OdbcArgumentValue>) -> crate::encode::IsNull {
3232
buf.push(OdbcArgumentValue::Text(self.to_string()));
3333
crate::encode::IsNull::No
3434
}

sqlx-core/src/odbc/types/bool.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ impl Type<Odbc> for bool {
1818
}
1919

2020
impl<'q> Encode<'q, Odbc> for bool {
21-
fn encode(self, buf: &mut Vec<OdbcArgumentValue<'q>>) -> crate::encode::IsNull {
21+
fn encode(self, buf: &mut Vec<OdbcArgumentValue>) -> crate::encode::IsNull {
2222
buf.push(OdbcArgumentValue::Int(if self { 1 } else { 0 }));
2323
crate::encode::IsNull::No
2424
}
2525

26-
fn encode_by_ref(&self, buf: &mut Vec<OdbcArgumentValue<'q>>) -> crate::encode::IsNull {
26+
fn encode_by_ref(&self, buf: &mut Vec<OdbcArgumentValue>) -> crate::encode::IsNull {
2727
buf.push(OdbcArgumentValue::Int(if *self { 1 } else { 0 }));
2828
crate::encode::IsNull::No
2929
}

sqlx-core/src/odbc/types/bytes.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,24 @@ impl Type<Odbc> for &[u8] {
2525
}
2626

2727
impl<'q> Encode<'q, Odbc> for Vec<u8> {
28-
fn encode(self, buf: &mut Vec<OdbcArgumentValue<'q>>) -> crate::encode::IsNull {
28+
fn encode(self, buf: &mut Vec<OdbcArgumentValue>) -> crate::encode::IsNull {
2929
buf.push(OdbcArgumentValue::Bytes(self));
3030
crate::encode::IsNull::No
3131
}
3232

33-
fn encode_by_ref(&self, buf: &mut Vec<OdbcArgumentValue<'q>>) -> crate::encode::IsNull {
33+
fn encode_by_ref(&self, buf: &mut Vec<OdbcArgumentValue>) -> crate::encode::IsNull {
3434
buf.push(OdbcArgumentValue::Bytes(self.clone()));
3535
crate::encode::IsNull::No
3636
}
3737
}
3838

3939
impl<'q> Encode<'q, Odbc> for &'q [u8] {
40-
fn encode(self, buf: &mut Vec<OdbcArgumentValue<'q>>) -> crate::encode::IsNull {
40+
fn encode(self, buf: &mut Vec<OdbcArgumentValue>) -> crate::encode::IsNull {
4141
buf.push(OdbcArgumentValue::Bytes(self.to_vec()));
4242
crate::encode::IsNull::No
4343
}
4444

45-
fn encode_by_ref(&self, buf: &mut Vec<OdbcArgumentValue<'q>>) -> crate::encode::IsNull {
45+
fn encode_by_ref(&self, buf: &mut Vec<OdbcArgumentValue>) -> crate::encode::IsNull {
4646
buf.push(OdbcArgumentValue::Bytes(self.to_vec()));
4747
crate::encode::IsNull::No
4848
}

0 commit comments

Comments
 (0)