Pg: Add perl2bin() and bin2perl() conversion methods

This commit is contained in:
Yorhel 2025-04-30 17:07:44 +02:00
parent af9340f908
commit beeefcf337
4 changed files with 69 additions and 2 deletions

View file

@ -758,7 +758,31 @@ C<set_type()> to configure appropriate conversions for these types.
=back
I<TODO:> Methods to convert between the various formats.
Utility functions:
=over
=item $conn->perl2bin($oid, $val)
=item $conn->bin2perl($oid, $bin)
Convert the value for a specific type between the Perl representation and the
PostgreSQL binary format, using the current type configuration of the
connection. This is the same conversion used internally by this module to send
bind parameters and receive query results, and map to the C<send> and C<recv>
functions of C<< $conn->set_type() >>.
These methods throw an error if C<$oid> is not a known type or if the given
data is not valid for the type. However, these methods should not be used for
strict validation: the conversion routines are usually written under the
assumption that the data has been received directly from Postgres or is about
to be sent to (and further validated by) Postgres. For some types,
C<perl2bin()> may return invalid data on invalid input and C<bin2perl()> may
accept invalid binary data.
=back
I<TODO:> Methods to convert between bin and text formats.
I<TODO:> Methods to query type info.