Skip to content

Commit 905fab8

Browse files
committed
Merge remote-tracking branch 'refs/remotes/origin/main'
2 parents 9eeceaa + 88aab3b commit 905fab8

5 files changed

Lines changed: 71 additions & 18 deletions

File tree

Cargo.lock

Lines changed: 10 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sqlx-core/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ hkdf = { version = "0.12.0", optional = true }
173173
event-listener = "5.4.0"
174174

175175
dotenvy = "0.15"
176-
odbc-api = { version = "19.0.1", optional = true }
176+
odbc-api = { version = "24.0.0", optional = true }
177177

178178
[dev-dependencies]
179179
sqlx = { package = "sqlx-oldapi", path = "..", features = ["postgres", "sqlite", "mysql", "runtime-tokio-rustls"] }

sqlx-core/src/any/type.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ macro_rules! impl_any_type {
88
($ty:ty) => {
99
impl crate::types::Type<crate::any::Any> for $ty {
1010
fn type_info() -> crate::any::AnyTypeInfo {
11-
// FIXME: nicer panic explaining why this isn't possible
12-
unimplemented!()
11+
panic!(
12+
"Type<Any>::type_info() is not implemented for {}. type_info should not be called on base types.",
13+
std::any::type_name::<$ty>(),
14+
);
1315
}
1416

1517
fn compatible(ty: &crate::any::AnyTypeInfo) -> bool {

sqlx-core/src/error.rs

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,49 @@ pub struct MismatchedTypeError {
4141
pub source: Option<BoxDynError>,
4242
}
4343

44+
fn rust_sql_type<DB: Database, T: Type<DB>>() -> String {
45+
if is_any_db::<DB>() {
46+
return "<unknown>".to_string();
47+
}
48+
49+
T::type_info().name().to_string()
50+
}
51+
52+
#[cfg(all(
53+
feature = "any",
54+
any(
55+
feature = "postgres",
56+
feature = "mysql",
57+
feature = "mssql",
58+
feature = "sqlite",
59+
feature = "odbc"
60+
)
61+
))]
62+
fn is_any_db<DB: Database>() -> bool {
63+
std::any::TypeId::of::<DB>() == std::any::TypeId::of::<crate::any::Any>()
64+
}
65+
66+
#[cfg(not(all(
67+
feature = "any",
68+
any(
69+
feature = "postgres",
70+
feature = "mysql",
71+
feature = "mssql",
72+
feature = "sqlite",
73+
feature = "odbc"
74+
)
75+
)))]
76+
fn is_any_db<DB: Database>() -> bool {
77+
let _ = std::any::TypeId::of::<DB>();
78+
false
79+
}
80+
4481
impl MismatchedTypeError {
4582
/// Create a new mismatched type error without a source.
4683
pub fn new<DB: Database, T: Type<DB>>(ty: &DB::TypeInfo) -> Self {
4784
Self {
4885
rust_type: type_name::<T>().to_string(),
49-
rust_sql_type: T::type_info().name().to_string(),
86+
rust_sql_type: rust_sql_type::<DB, T>(),
5087
sql_type: ty.name().to_string(),
5188
source: None,
5289
}
@@ -56,7 +93,7 @@ impl MismatchedTypeError {
5693
pub fn with_source<DB: Database, T: Type<DB>>(ty: &DB::TypeInfo, source: BoxDynError) -> Self {
5794
Self {
5895
rust_type: type_name::<T>().to_string(),
59-
rust_sql_type: T::type_info().name().to_string(),
96+
rust_sql_type: rust_sql_type::<DB, T>(),
6097
sql_type: ty.name().to_string(),
6198
source: Some(source),
6299
}
@@ -182,19 +219,33 @@ impl Error {
182219
}
183220

184221
pub(crate) fn mismatched_types<DB: Database, T: Type<DB>>(ty: &DB::TypeInfo) -> BoxDynError {
222+
let rust_sql_type = rust_sql_type::<DB, T>();
185223
Box::new(MismatchedTypeError {
186224
rust_type: format!(
187225
"{} ({}compatible with SQL type `{}`)",
188226
type_name::<T>(),
189227
if T::compatible(ty) { "" } else { "in" },
190-
T::type_info().name()
228+
rust_sql_type
191229
),
192-
rust_sql_type: T::type_info().name().to_string(),
230+
rust_sql_type,
193231
sql_type: ty.name().to_string(),
194232
source: None,
195233
})
196234
}
197235

236+
#[cfg(all(test, feature = "any", feature = "postgres"))]
237+
mod tests {
238+
use crate::any::Any;
239+
use crate::error::mismatched_types;
240+
use crate::postgres::PgTypeInfo;
241+
242+
#[test]
243+
fn mismatched_types_any_does_not_panic() {
244+
let ty = crate::any::AnyTypeInfo::from(PgTypeInfo::with_name("TEXT"));
245+
assert!(std::panic::catch_unwind(|| mismatched_types::<Any, i32>(&ty)).is_ok());
246+
}
247+
}
248+
198249
/// An error that was returned from the database.
199250
pub trait DatabaseError: 'static + Send + Sync + StdError {
200251
/// The primary, human-readable error message.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ fn map_buffer_desc(
248248
// Binary types
249249
DataType::Binary { .. } | DataType::Varbinary { .. } | DataType::LongVarbinary { .. } => {
250250
BufferDesc::Binary {
251-
length: max_column_size,
251+
max_bytes: max_column_size,
252252
}
253253
}
254254
// Text types

0 commit comments

Comments
 (0)