Re:Show HN: Sqlbind a Python library to compose raw SQL
by chrisjc on Monday February 26, 2024 @03:15PM
(#39516249)
If I understand your code correctly, you are bypassing DBAPI's binding functionality and opening yourself up for SQL injection.
QParams = sqlbind.Dialect.some_dialect
@QParams
def make_my_query(value1: str, value2: int):
# SELECT * FROM table WHERE field1 = ? AND field2 > ?
return f'SELECT * FROM table WHERE field1 = {value1} AND field2 > {value2}'
data = connection.execute(*make_my_query(foo, bar), [foo, bar])
Edit: actually, I might've misunderstood what sqlbind is doing internally, maybe this approach doesn't quite make sense
Edit 2: Like so: https://github.com/baverman/sqlbind/issues/1