Close #378.
- Fix segfault occurring when a loader fails initialization (:ticket:`#372`).
- Fix invalid SAVEPOINT issued when entering `Connection.transaction()` within
a pipeline using an implicit transaction (:ticket:`#374`).
+- Fix queries with repeated named parameters in `ClientCursor` (:ticket:`#378`).
Current release
chunks.append(ph)
else:
chunks.append(seen[part.item][0])
+ order.append(part.item)
# last part
chunks.append(parts[-1].pre)
assert cur._query.params == (b"'wat'",)
+@pytest.mark.parametrize(
+ "query, params, want",
+ [
+ ("select %(x)s", {"x": 1}, (1,)),
+ ("select %(x)s, %(y)s", {"x": 1, "y": 2}, (1, 2)),
+ ("select %(x)s, %(x)s", {"x": 1}, (1, 1)),
+ ],
+)
+def test_query_params_named(conn, query, params, want):
+ cur = conn.cursor()
+ cur.execute(query, params)
+ rec = cur.fetchone()
+ assert rec == want
+
+
def test_query_params_executemany(conn):
cur = conn.cursor()
assert n[0] == n[1] == n[2], f"objects leaked: {n[1] - n[0]}, {n[2] - n[1]}"
-def test_mogrify(conn):
+@pytest.mark.parametrize(
+ "query, params, want",
+ [
+ ("select 'hello'", (), "select 'hello'"),
+ ("select %s, %s", ([1, dt.date(2020, 1, 1)],), "select 1, '2020-01-01'::date"),
+ ("select %(foo)s, %(foo)s", ({"foo": "x"},), "select 'x', 'x'"),
+ ],
+)
+def test_mogrify(conn, query, params, want):
cur = conn.cursor()
- q = cur.mogrify("select 'hello'")
- assert q == "select 'hello'"
-
- q = cur.mogrify("select %s, %s", [1, dt.date(2020, 1, 1)])
- assert q == "select 1, '2020-01-01'::date"
+ got = cur.mogrify(query, *params)
+ assert got == want
@pytest.mark.parametrize("encoding", ["utf8", crdb_encoding("latin9")])
assert cur._query.params == (b"'wat'",)
+@pytest.mark.parametrize(
+ "query, params, want",
+ [
+ ("select %(x)s", {"x": 1}, (1,)),
+ ("select %(x)s, %(y)s", {"x": 1, "y": 2}, (1, 2)),
+ ("select %(x)s, %(x)s", {"x": 1}, (1, 1)),
+ ],
+)
+async def test_query_params_named(aconn, query, params, want):
+ cur = aconn.cursor()
+ await cur.execute(query, params)
+ rec = await cur.fetchone()
+ assert rec == want
+
+
async def test_query_params_executemany(aconn):
cur = aconn.cursor()
assert n[0] == n[1] == n[2], f"objects leaked: {n[1] - n[0]}, {n[2] - n[1]}"
-async def test_mogrify(aconn):
+@pytest.mark.parametrize(
+ "query, params, want",
+ [
+ ("select 'hello'", (), "select 'hello'"),
+ ("select %s, %s", ([1, dt.date(2020, 1, 1)],), "select 1, '2020-01-01'::date"),
+ ("select %(foo)s, %(foo)s", ({"foo": "x"},), "select 'x', 'x'"),
+ ],
+)
+async def test_mogrify(aconn, query, params, want):
cur = aconn.cursor()
- q = cur.mogrify("select 'hello'")
- assert q == "select 'hello'"
-
- q = cur.mogrify("select %s, %s", [1, dt.date(2020, 1, 1)])
- assert q == "select 1, '2020-01-01'::date"
+ got = cur.mogrify(query, *params)
+ assert got == want
@pytest.mark.parametrize("encoding", ["utf8", crdb_encoding("latin9")])