Skip to content

How to use PostgreSQL extended protocol with ODBC driver executing a parameterized sentence. #117

Description

@omeuid

Hi,

Is there a way to configure the ODBC driver to use the extended protocol when running a parameterized query?

Let's assume the following Python client.

import pyodbc

def connect_to_odbc(uri):
conn = pyodbc.connect(uri)
return conn

def execute_query(conn, query):
cursor = conn.cursor()
cursor.execute(query, 1)
result = cursor.fetchall()
return result

uri = 'DSN=MyDSN'

conn = connect_to_odbc(uri)
query = 'SELECT * from mytable where id = ?'

result = execute_query(conn, query)

for row in result:
print(row)

conn.close()

If the DSN is configured with 'server side prepare' option set to 1 (and also batch size is set to 1):

  • I expected that the driver would send P/B/E messages.
  • However, what I'm observing is that the driver only sends a Q message, with the parameter already replaced.

Could you confirm if this is the expected behaviour?

Is there anything that I can configure in the driver in order to get the behaviour that I was expecting?

Regards

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions