1

I have some python code:

def GetAge(tournaments):         
    cursor = cnxTurnier.cursor()
    for rows in tournaments:
        TurID = rows[0]         
        TurID = int(TurID)       
        query = ("SELECT JahrgID FROM altersklassen WHERE TurnierID = %s")

        cursor.execute(query, TurID)

        altersklassen = cursor.fetchall()

Im using the mysql.connector on python3.4

tournaments is the result of another SQL Query. Then I export the ID of this query and want to get additional informations (1:n relations). MYSQL is telling me that there is an error in my SQL Sytax near to %i. But why TurID is not replacing it? I've got the weird feeling, that the connector re-parses the TurID into something different than MYSQl is expecting. The SELECT is working direct in MYSQL when I replace the %i.

Can anyone tell me what is wrong with my code an wether the TurID = int(TurID) is needed?

I've tried several things over the day and read different documentations, I can't see the issue. Is maybe the whole idea to solve this wrong? I want to have additional informations to another query from another table (1:n relationship).

1

1 Answer 1

2

MySQL - or rather, the Python wrapper MySQLdb - is not expecting %i at all. All parameters should be %s.

Sign up to request clarification or add additional context in comments.

1 Comment

This would explain the problem I've changed it, but it's still telling me: mysql.connector.errors.ProgrammingError: 1064 (42000): You have an error in SQL syntax; check the manual that corresponds to your MySQL server version the right syntax to use near '%s' at line 1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.