Skip to content

Commit 48ccc78

Browse files
committed
Merge pull request #4064 from weiznich/fix/mysqlclient_regression_with_old_versions
Fix a potential regression with old mysqlclient-sys versions
1 parent f6da5f5 commit 48ccc78

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

diesel/src/mysql/connection/bind.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -389,13 +389,13 @@ impl BindData {
389389
length,
390390
capacity,
391391
flags,
392-
is_null: ffi::FALSE,
393-
is_truncated: Some(ffi::FALSE),
392+
is_null: super::raw::ffi_false(),
393+
is_truncated: Some(super::raw::ffi_false()),
394394
}
395395
}
396396

397397
fn is_truncated(&self) -> bool {
398-
self.is_truncated.unwrap_or(ffi::FALSE) != ffi::FALSE
398+
self.is_truncated.unwrap_or(super::raw::ffi_false()) != super::raw::ffi_false()
399399
}
400400

401401
fn is_fixed_size_buffer(&self) -> bool {
@@ -711,7 +711,9 @@ impl From<(ffi::enum_field_types, Flags)> for MysqlType {
711711
something has gone wrong. Please open an issue at \
712712
the diesel github repo."
713713
),
714-
714+
// depending on the bindings version
715+
// there might be no unlisted field type
716+
#[allow(unreachable_patterns)]
715717
t => unreachable!(
716718
"Unsupported type encountered: {t:?}. \
717719
If you ever see this error, something has gone wrong. \

diesel/src/mysql/connection/raw.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,19 @@ use crate::result::{ConnectionError, ConnectionResult, QueryResult};
1111

1212
pub(super) struct RawConnection(NonNull<ffi::MYSQL>);
1313

14+
// old versions of mysqlclient do not expose
15+
// ffi::FALSE, so we need to have our own compatibility
16+
// wrapper here
17+
//
18+
// Depending on the bindings version ffi::my_bool
19+
// might be an actual bool or a i8. For the former
20+
// case `default()` corresponds to `false` for the later
21+
// to `0` which is both interpreted as false
22+
#[inline(always)]
23+
pub(super) fn ffi_false() -> ffi::my_bool {
24+
Default::default()
25+
}
26+
1427
impl RawConnection {
1528
pub(super) fn new() -> Self {
1629
perform_thread_unsafe_library_initialization();
@@ -175,7 +188,7 @@ impl RawConnection {
175188
}
176189

177190
fn more_results(&self) -> bool {
178-
unsafe { ffi::mysql_more_results(self.0.as_ptr()) != ffi::FALSE }
191+
unsafe { ffi::mysql_more_results(self.0.as_ptr()) != ffi_false() }
179192
}
180193

181194
fn next_result(&self) -> QueryResult<()> {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy