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.