Skip to content

Commit

Permalink
Add tests for all types
Browse files Browse the repository at this point in the history
  • Loading branch information
JelteF committed Sep 19, 2024
1 parent a342746 commit b50d061
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/pgduckdb_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ extern "C" {
#include "miscadmin.h"
#include "catalog/pg_type.h"
#include "executor/tuptable.h"
#include "utils/builtins.h"
#include "utils/numeric.h"
#include "utils/uuid.h"
#include "utils/array.h"
Expand Down Expand Up @@ -730,7 +731,10 @@ ConvertPostgresParameterToDuckValue(Datum value, Oid postgres_type) {
// test so I don't know.
// case JSONOID:
case VARCHAROID: {
return duckdb::Value((const char *)value);
// FIXME: TextDatumGetCstring allocates so it needs a
// guard, but it's a macro not a function, so our current gaurd
// template does not handle it.
return duckdb::Value(TextDatumGetCString(value));
}
case DATEOID:
return duckdb::Value::DATE(duckdb::date_t(static_cast<int32_t>(value + PGDUCKDB_DUCK_DATE_OFFSET)));
Expand Down
53 changes: 53 additions & 0 deletions test/pycheck/prepared_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from .utils import Cursor

import datetime


def test_prepared(cur: Cursor):
cur.sql("CREATE TABLE test_table (id int)")
Expand Down Expand Up @@ -34,3 +36,54 @@ def test_prepared(cur: Cursor):
assert cur.sql(q2, (1,)) == 1
assert cur.sql(q2, (3,)) == 1
assert cur.sql(q2, (4,)) == 0


def test_extended(cur: Cursor):
cur.sql("""
CREATE TABLE t(
bool BOOLEAN,
i2 SMALLINT,
i4 INT,
i8 BIGINT,
fl4 REAL,
fl8 DOUBLE PRECISION,
t1 TEXT,
t2 VARCHAR,
t3 BPCHAR,
d DATE,
ts TIMESTAMP);
""")

row = (
True,
2,
4,
8,
4.0,
8.0,
"t1",
"t2",
"t3",
datetime.date(2024, 5, 4),
datetime.datetime(2020, 1, 1, 1, 2, 3),
)
cur.sql("INSERT INTO t VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)", row)

assert (True,) * len(row) == cur.sql(
"""
SELECT
bool = %s,
i2 = %s,
i4 = %s,
i8 = %s,
fl4 = %s,
fl8 = %s,
t1 = %s,
t2 = %s,
t3 = %s,
d = %s,
ts = %s
FROM t;
""",
row,
)

0 comments on commit b50d061

Please sign in to comment.