Skip to content

Commit

Permalink
[BUG] Fix binding of NULL value parameters in prepared statements (#496)
Browse files Browse the repository at this point in the history
Fix binding of NULL value parameters in prepared statements

Co-authored-by: anon <[email protected]>
  • Loading branch information
voldemarich and anon authored Jul 10, 2023
1 parent 1ed6e92 commit 7205537
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -832,10 +832,21 @@ impl TryFrom<&BytesMut> for Bind {

for _ in 0..num_param_values {
let param_len = cursor.get_i32();
let mut param = BytesMut::with_capacity(param_len as usize);
param.resize(param_len as usize, b'0');
cursor.copy_to_slice(&mut param);
param_values.push((param_len, param));
// There is special occasion when the parameter is NULL
// In that case, param length is defined as -1
// So if the passed parameter len is over 0
if param_len > 0 {
let mut param = BytesMut::with_capacity(param_len as usize);
param.resize(param_len as usize, b'0');
cursor.copy_to_slice(&mut param);
// we push and the length and the parameter into vector
param_values.push((param_len, param));
} else {
// otherwise we push a tuple with -1 and 0-len BytesMut
// which means that after encountering -1 postgres proceeds
// to processing another parameter
param_values.push((param_len, BytesMut::new()));
}
}

let num_result_column_format_codes = cursor.get_i16();
Expand Down

0 comments on commit 7205537

Please sign in to comment.