heyurs
heyurs

Reputation: 3

Issue during inserting data in sql database

I am trying to insert some data into SQL database using a python script, but I am facing an error, I am not sure why. Here is what I am doing

create_query = """INSERT INTO bcmdb.bcmdbuser.Groups (ParentGroupID, ChildGroupID, DirectChild) 
                           VALUES (100, ?, 0) """
record = (id_s)
cursor.execute(create_query, record)
conn.commit()

I am using "pypyodbc" to connect to database and its working fine, the issue this code produce is

TypeError: Params must be in a list, tuple or Row.

In cursor.execute(create_query, record) line specifically.

Any idea will be really appreciated.

Upvotes: 0

Views: 52

Answers (1)

Jorge Bugal
Jorge Bugal

Reputation: 439

That's a problem with one-valued tuples in Python. They must have a trailing comma. Try like this:

create_query = """INSERT INTO bcmdb.bcmdbuser.Groups (ParentGroupID, ChildGroupID, DirectChild) 
                           VALUES (100, ?, 0) """
record = (id_s,)
cursor.execute(create_query, record)
conn.commit()

Upvotes: 1

Related Questions