So I have a list of formatted strings that i want to insert into a database, They are formatted so the database will accept this type of string.
Here is an example of the format:
mylist = [('123456789'), ('987654321'), ('1234554321'),....('9999999999')]
mylist[0] = ('123456789')
The format must be kept to ensure they are entered correctly.
I want to ensure that it is secure against sql injection,
I know this works:
database = connection.cursor()
for data in mylist:
command = " INSERT INTO my_table(my_value) VALUES %s" %data
database.execute(command)
connection.commit()
However I'm unsure if this is correct way to prevent sql injection
What I would prefer to do but it wont work is:
database = connection.cursor()
for data in mylist:
command = " INSERT INTO my_table(my_value) VALUES %s"
database.execute(command, (data))
connection.commit()
The error I receive is:
'str' object is not callable
I've seen online here that this is correct so why wont it work