Skip to content

Commit 4fa1572

Browse files
simonzsimonzkl
authored andcommitted
fix(mysql): restore bind buffer length for newer mariadb versions
1 parent 143b254 commit 4fa1572

File tree

1 file changed

+20
-1
lines changed
  • diesel/src/mysql/connection/stmt

1 file changed

+20
-1
lines changed

diesel/src/mysql/connection/stmt/mod.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,14 @@ impl Statement {
117117
/// you must call this function again before calling `mysql_stmt_fetch`.
118118
pub unsafe fn bind_result(&self, binds: *mut ffi::MYSQL_BIND) -> QueryResult<()> {
119119
unsafe {
120+
let prev_length = *(*binds).length;
120121
ffi::mysql_stmt_bind_result(self.stmt.as_ptr(), binds);
122+
123+
// HACK: Newer libmariadb versions initialise length to 0 for fixed-size
124+
// types. Restore length to previous value if this is the case.
125+
if *(*binds).length == 0 {
126+
*(*binds).length = prev_length;
127+
}
121128
}
122129
self.did_an_error_occur()
123130
}
@@ -178,7 +185,19 @@ impl StatementUse<'_> {
178185
}
179186

180187
pub(super) fn populate_row_buffers(&self, binds: &mut OutputBinds) -> QueryResult<Option<()>> {
181-
let next_row_result = unsafe { ffi::mysql_stmt_fetch(self.inner.stmt.as_ptr()) };
188+
let next_row_result = unsafe {
189+
let prev_length = *(*(*self.inner.stmt.as_ptr()).bind).length;
190+
let result = ffi::mysql_stmt_fetch(self.inner.stmt.as_ptr());
191+
192+
// HACK: Newer libmariadb versions initialise length to 0 for fixed-size
193+
// types. Restore length to previous value if this is the case.
194+
if *(*(*self.inner.stmt.as_ptr()).bind).length == 0 {
195+
*(*(*self.inner.stmt.as_ptr()).bind).length = prev_length;
196+
}
197+
198+
result
199+
};
200+
182201
if next_row_result < 0 {
183202
self.inner.did_an_error_occur().map(Some)
184203
} else {

0 commit comments

Comments
 (0)