0

I am switching from SQLite to MySQL and getting some problems with my Queries. At the moment i am trying to SELECT from a Table where the PackageName is like a variable from a Text Input in my GUI.

The Query looks like this:

test = self.ms.ExecQuery("SELECT PackageID,PackageName,ServiceFee,Cost,LatestChanges FROM Package WHERE PackageName=?", (self.search_entry.GetValue(),))

and my ExecQuery looks like this:

def ExecQuery(self, sql):
    cur = self._Getconnect()
    cur.execute(sql)
    relist = cur.fetchall()
    cur.close()
    self.conn.close()

    return relist

And the error i am getting:

TypeError: ExecQuery() takes 2 positional arguments but 3 were given

What do i need to change to get this running?

K-Doe
  • 509
  • 8
  • 29
  • Please note a comma(`,`) after your second parameter. Was it intentional? – PM 77-1 Mar 04 '20 at 18:08
  • 1
    Read the message! You're trying to pass the PackageName value in a tuple as a third parameter to ExecQuery but have only defined it to accept 2 parameters. You're also give the sql to the cursor execute function, but not the tuple which would give it the value to compare to PackageName. You could add the parameter after sql. Tale a look at https://stackoverflow.com/questions/3394835/use-of-args-and-kwargs if what you want to do is have this parameter optional. – Mic Mar 04 '20 at 23:30
  • Thank you, having it optional was working well. – K-Doe Mar 05 '20 at 06:54

1 Answers1

0

You have sql as the 2nd parameter in your ExecQuery, yet you are passing in a sql query as the 1st parameter:

test = self.ms.ExecQuery("SELECT PackageID,PackageName,ServiceFee,Cost,LatestChanges FROM Package WHERE PackageName=?", (self.search_entry.GetValue(),))
Morpheus
  • 1,616
  • 1
  • 21
  • 31