Ejemplo n.º 1
0
def test_format():
    new_query, make_args = convert(
        "format", "SELECT %s, %s, \"f1_%%\", E'txt_%%' "
        "FROM t WHERE a=%s AND b='75%%' AND c = '%' -- Comment with %")
    expected = "SELECT $1, $2, \"f1_%%\", E'txt_%%' FROM t WHERE a=$3 AND " \
        "b='75%%' AND c = '%' -- Comment with %"
    assert new_query == expected
    assert make_args((1, 2, 3)) == (1, 2, 3)

    sql = r"""COMMENT ON TABLE test_schema.comment_test """ \
        r"""IS 'the test % '' " \ table comment'"""
    new_query, make_args = convert("format", sql)
    assert new_query == sql
Ejemplo n.º 2
0
def test_qmark():
    new_query, make_args = convert(
        "qmark", "SELECT ?, ?, \"field_?\" FROM t "
        "WHERE a='say ''what?''' AND b=? AND c=E'?\\'test\\'?'")
    expected = "SELECT NULL, NULL, \"field_?\" FROM t WHERE " \
        "a='say ''what?''' AND b=NULL AND c=E'?\\'test\\'?'"
    assert new_query == expected
    assert make_args((1, 2, 3)) == (1, 2, 3)
Ejemplo n.º 3
0
def test_format_multiline():
    new_query, make_args = convert("format", "SELECT -- Comment\n%s FROM t")
    assert new_query == "SELECT -- Comment\n$1 FROM t"
Ejemplo n.º 4
0
def test_numeric_default_parameter():
    new_query, make_args = convert("numeric", "make_interval(days := 10)")

    assert new_query == "make_interval(days := 10)"
    assert make_args((1, 2, 3)) == (1, 2, 3)
Ejemplo n.º 5
0
def test_numeric():
    new_query, make_args = convert(
        "numeric", "SELECT sum(x)::decimal(5, 2) :2, :1, * FROM t WHERE a=:3")
    expected = "SELECT sum(x)::decimal(5, 2) $2, $1, * FROM t WHERE a=$3"
    assert new_query == expected
    assert make_args((1, 2, 3)) == (1, 2, 3)
Ejemplo n.º 6
0
def test_qmark_2():
    new_query, make_args = convert(
        "qmark", "SELECT ?, ?, * FROM t WHERE a=? AND b='are you ''sure?'")
    expected = "SELECT NULL, NULL, * FROM t WHERE a=NULL AND b='are you ''sure?'"
    assert new_query == expected
    assert make_args((1, 2, 3)) == (1, 2, 3)