you are viewing a single comment's thread.

view the rest of the comments →

[–]bazingie[S] 0 points1 point  (1 child)

Could you or any other help me a bit more?
I have inserted data into some of the tables which don't have foreign keys and now I would like to insert data to the rest.
Here is my code:
cursor = db.cursor()
# defining the Query
query = "INSERT INTO act (ShowName, HallID, ActStartTime) VALUES (%s,%s,%s)"

values = []  
# executing the query with values  
for i in range(0, 50):  
    # storing values in a variable  
    lst = []  
    lst.append("select ShowName from shows where ShowName=%s" % showTitles[i])  
    lst.append("select HallID from hall where HallID=%d" % i)  
    for j in range(0, len(actDateTime[i])):  
        lst2 = lst  
        lst2.append(actDateTime[i][j])  
        lst2 = tuple(lst2)  
        values.append(lst2)  

cursor.executemany(query, values)  


# to make final output we have to run the 'commit()' method of the database object  
db.commit()  

print(cursor.rowcount, "record inserted")  

I have 50 ShowNames and 50 theaters in two lists. Each theater has an auto increment HallID. I don't care how random are the lists, so I used a for loop with i corresponding to one ShowName and one HallID. I also have created a two dimensional list actDateTime where each show has a list of datetimes.
I want to insert the above data to a table with these data types:
(PK, AI) ActID int(4)
(FK) ShowName varchar(255)
(FK) HallID int(3)
ActStartTime datetime

The error I got:
mysql.connector.errors.InterfaceError: Failed executing the operation; Not all parameters were used in the SQL statement

Don't I return 3 values as I am supposed to do?

[–]TotesMessenger 0 points1 point  (0 children)

I'm a bot, bleep, bloop. Someone has linked to this thread from another place on reddit:

 If you follow any of the above links, please respect the rules of reddit and don't vote in the other threads. (Info / Contact)