Skip to content

Conversation

voldemarich
Copy link
Contributor

Hello.

I tried to use the pgcat in a project of mine and noticed that it is impossible to use the transaction mode with anonymous prepared statements with parameters under some conditions.

When I started digging, I've found out there is an error defined as follows:

pgcat_1 | 16: 0x56003524c7f9 - <pgcat::messages::Bind as core::convert::TryFrom<&bytes::bytes_mut::BytesMut>>::try_from::h6544c9b6f20afed0 pgcat_1 | 17: 0x56003514beb2 - pgcat::client::Client<S,T>::rewrite_bind::{{closure}}::hc9caf116b38777a6 pgcat_1 | 18: 0x560035150374 - pgcat::client::Client<S,T>::handle::{{closure}}::h067dca183cd6d153 pgcat_1 | 19: 0x560035148981 - pgcat::client::client_entrypoint::{{closure}}::h2c1c12e23450a320 pgcat_1 | 20: 0x560035189d20 - pgcat::main::{{closure}}::{{closure}}::h449e3005ae55b1cc 

It occurred only when there has been a parameterized query and one of the parameters has been NULL.

Postgresql documentation states that there is one special occasion when the reported parameter length is -1: that is NULL value.

The length of the parameter value, in bytes (this count does not include itself). Can be zero. As a special case, -1 indicates a NULL parameter value. No value bytes follow in the NULL case.

BytesMut::with_capacity(param_len as usize);

is unusable provided param_len <= 0.

Please accept the PR or modify it in accordance to your code conventions (not a Rust programmer here) to be able to use parameterized statements consistently.

@voldemarich voldemarich changed the title Fix binding of NULL value parameters in prepared statements [BUG] Fix binding of NULL value parameters in prepared statements Jul 6, 2023
@levkk
Copy link
Contributor

levkk commented Jul 10, 2023

Great catch, thank you!

@levkk levkk merged commit 7205537 into postgresml:main Jul 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants