def test_eq(self): assert sql.Placeholder("foo") == sql.Placeholder("foo") assert sql.Placeholder("foo") != sql.Placeholder("bar") assert sql.Placeholder("foo") != "foo" assert sql.Placeholder() == sql.Placeholder() assert sql.Placeholder("foo") != sql.Placeholder() assert sql.Placeholder("foo") != sql.Literal("foo")
def insert_stmt(self): phs = [ sql.Placeholder(format=self.format) for i in range(len(self.schema)) ] return sql.SQL("insert into {} ({}) values ({})").format( self.table_name, sql.SQL(", ").join(self.fields_names), sql.SQL(", ").join(phs), )
def test_executemany(self, conn): cur = conn.cursor() cur.execute( """ create table test_compose ( id serial primary key, foo text, bar text, "ba'z" text) """ ) cur.executemany( sql.SQL("insert into {0} (id, {1}) values (%s, {2})").format( sql.Identifier("test_compose"), sql.SQL(", ").join( map(sql.Identifier, ["foo", "bar", "ba'z"]) ), (sql.Placeholder() * 3).join(", "), ), [(10, "a", "b", "c"), (20, "d", "e", "f")], ) cur.execute("select * from test_compose") assert cur.fetchall() == [(10, "a", "b", "c"), (20, "d", "e", "f")]
def test_bad_name(self): with pytest.raises(ValueError): sql.Placeholder(")")
def test_repr_name_binary(self, conn): ph = sql.Placeholder("foo", format=Format.BINARY) assert str(ph) == repr(ph) == "Placeholder('foo', format=BINARY)" assert ph.as_string(conn) == "%(foo)b"
def test_repr_name(self, conn): ph = sql.Placeholder("foo") assert str(ph) == repr(ph) == "Placeholder('foo')" assert ph.as_string(conn) == "%(foo)s"
def test_repr_binary(self, conn): ph = sql.Placeholder(format=Format.BINARY) assert str(ph) == repr(ph) == "Placeholder(format=BINARY)" assert ph.as_string(conn) == "%b"
def test_repr(self, conn): ph = sql.Placeholder() assert str(ph) == repr(ph) == "Placeholder()" assert ph.as_string(conn) == "%s"