Skip to content

Conversation

@mcraveiro
Copy link
Contributor

Summary

Add support for parameterized queries using PostgreSQL's $1, $2, ... placeholder syntax. This enables safe parameter binding for:

  • Calling PostgreSQL functions without defining custom types
  • Executing dynamic queries with SQL injection protection
  • Passing NULL values via std::optional or std::nullopt

API

// Variadic execute with automatic type conversion
conn->execute("SELECT my_func($1, $2)", tenant_id, user_email);

// Supported types: string, numeric, bool, optional, nullptr
conn->execute("INSERT INTO t (a, b, c) VALUES ($1, $2, $3)",
              std::string("text"), 42, std::nullopt);

Implementation

  • Add PostgresV2Result::make() overload using PQexecParams
  • Add variadic execute() template to Connection with to_param() helper
  • Internal execute_params() method handles the actual libpq call

Test plan

  • execute_with_string_params - string and int parameters
  • execute_with_null_param - NULL via std::optional
  • execute_with_numeric_params - int, double, bool
  • execute_call_function - calling PL/pgSQL function

🤖 Generated with Claude Code

Support variadic execute with $1, $2, ... placeholders for safe parameter
binding. This allows calling PostgreSQL functions without defining custom
types.

Example:
  conn->execute("SELECT my_func($1, $2)", arg1, arg2);

Supported types: string, numeric, bool, optional, nullptr/nullopt for NULL.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
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