Skip to content

Commit

Permalink
Make describe statement work
Browse files Browse the repository at this point in the history
  • Loading branch information
lhofhansl committed Sep 15, 2024
1 parent 95cfb78 commit 2e840a8
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions buenavista/postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,12 @@ class ServerResponse:

TYPE_OIDS = {
# see Postgres pg_type_d.h
20: ("INT8OID", "!q"),
21: ("INT2OID", "!h"),
23: ("INT4OID", "!i"),
700:("FLOAT4OID", "!f"),
701:("FLOAT8OID", "!d")
0: ("date/time", None, datetime.datetime(1900, 1, 1)),
20: ("INT8OID", "!q", 42),
21: ("INT2OID", "!h", 42),
23: ("INT4OID", "!i", 42),
700:("FLOAT4OID", "!f", 42.0),
701:("FLOAT8OID", "!d", 42.0)
#...

# BOOLOID 16
Expand Down Expand Up @@ -256,8 +257,14 @@ def describe_portal(self, name: str) -> QueryResult:

def describe_statement(self, name: str) -> QueryResult:
sql, param_oids = self.stmts[name]
# TODO: create default params from param_oids
return self.execute_sql(sql)
params = []
for typeoid in param_oids:
type = TYPE_OIDS.get(typeoid)
if type:
params.append(type[2])
else:
raise Exception(f"Unsupported parameter type: {typeoid}")
return self.execute_sql(sql, params)

def execute_portal(self, name: str) -> QueryResult:
if name in self.result_cache:
Expand Down

0 comments on commit 2e840a8

Please sign in to comment.