python - SQLite execute statement for variable-length rows -
i've read advice here using parametrized execute call sql escaping you, seems work when know number of columns in advance.
i'm looping on csv files, 1 each table, , populating local db testing purposes. each table has different numbers of columns, can't use:
sql = "insert table_a values (%s, %s)" cursor.execute(sql, (val1, val2))
i can build sql statement string quite flexibly, doesn't give me use of cursor.execute's sql-escaping facilities, if input contains apostrophes or similar, fails.
it seems there should simple way this. there?
if know number of parameters, can create list of them:
count = ... sql = "insert ... values(" + ",".join(count * ["?"]) + ")" params = [] in ...: params += ['whatever'] cursor.execute(sql, params)
Comments
Post a Comment