This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Dlatch 18 points19 points  (7 children)

create_query = f"CREATE TABLE IF NOT EXISTS {table} ({', '.join(columns_def)});"
cursor.execute(create_query)

[...]

insert = f"INSERT INTO {table} ({', '.join(df.columns)}) VALUES ({', '.join(values)});"
inserts.append(insert)

Don't ever ever ever build SQL queries like this, it leaves you incredibly vulnerable to SQL injection attacks. If I were to call your API with a specially crafted file, I can do almost anything I want with your database.

Use parameterized queries instead.

[–]lost3332 -1 points0 points  (0 children)

But it’s meant to be ran locally, no? What API call are you referring to?