Skip to content

Conversation

@herwinw
Copy link

@herwinw herwinw commented Mar 31, 2025

Short description of our use case: We're currently using the pg gem with a lot of either hand crafted or generated queries with the postgresql style arguments. This means code like this:

dbh.exec('SELECT $1::bigint, $2', 42, 'The anwser')

This format is not compatible with the db style placeholders. Instead of having to migrate big bang style, this change exposes PQSendQueryParams which can handle this format. This allows us to change the backend from pg to db-postgres and then we can slowly migrate to the db style placeholders.

This change also adds support for the bytea data type (this is kind of connected to the arguments), this might be a backwards incompatible change, where the old code returned a hexdump of the bytea string, which is now returned as a Ruby string with binary encoding.

Types of Changes

  • New feature.
  • Breaking change (minor)

Contribution

Comment on lines +198 to +199
paramValues = FFI::MemoryPointer.new(:pointer, params.size)
paramValues.write_array_of_pointer(params.map { |param| FFI::MemoryPointer.from_string(param) })
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this is GC safe, or if we need an additional variable to save the the result of the params.map operation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant