2

Tried what it said in these questions but didn't help: Python MySQL Parameterized Queries
Python MySQLdb TypeError: not all arguments converted during string formatting

It keeps given me this error: "You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '%s AND e.MeetId = m.MeetId ORDER by e.eventId' at line 4")

When I use a number, for example, put in 1 for the "meetId" in the query, it works. I'm trying to get it to work with inputs but nothing seems to work.

Every different file is separated with asterisks, Here is the code:

   ********mainFile.py********

   from dbconfig import*
   import pymysql
   from datetime import datetime, date, time
   import sys

  db = get_mysql_param();
  cnx = pymysql.connect(user=db['user'], password=db['password'],
                        host=db['host'],
                        database=db['database'])

cursor = cnx.cursor()

meetId = input("MeetId: ")

query = """
     SELECT DISTINCT e.eventId as eventId, e.Title as title, concat(s.fname, 
       " ", s.lname) as sName, 
       if (Isnull(p.Comment), '', comment) as comment FROM Event e, Swimmer 
       s, Participation p, Meet m WHERE 
       s.SwimmerId = p.SwimmerId AND p.EventId = e.EventId AND 
       m.MeetId = %s AND e.MeetId = m.MeetId ORDER by e.eventId
       """


cursor.execute(query,(meetId, ))



******dbconfig.py file*******
      import configparser 

      #  simplistic and no error handling.
     def get_mysql_param(filename='dbconfig.ini', section='mysql'):

           config = configparser.ConfigParser()
           config.read(filename)

           return config['mysql']

******dbconfig.ini file*****
[mysql]
host = localhost
database = clystms
user = **********
password = *********

The problem is "m.MeetId = %s", it doesn't want to replace the "%s" in the query with whatever I input.

Larvitar
  • 43
  • 1
  • 6
  • Can you show the connection objects and all `import` lines? – Parfait Apr 07 '18 at 18:43
  • I included all the files, every section in that code is separated with asterisk saying which file it is – Larvitar Apr 08 '18 at 01:09
  • I'm scratching my head. My guess is what you post here is NOT the same as code causing the error. Carefully check in your actual code if you are passing any parameter value. That MySQL warning would raise if you just ran `cursor.execute(query)` without *params* as nothing is binding to the placeholder, `%s`. – Parfait Apr 08 '18 at 03:52

0 Answers0