Bubbleboy
Bubbleboy

Reputation: 71

Django: mysql query with arguments

i have a MySQL query like this

cursor.execute("GRANT USAGE ON %s.* TO %s@%s", [db, user, host])

Python generate a query like

GRANT USAGE ON 'db'.* TO 'user'@'host';

But the apostrophes around 'db' are not allowed in MySQL. Any ideas?

Upvotes: 0

Views: 123

Answers (1)

rh0dium
rh0dium

Reputation: 7032

A simple way to get around this.

grant = "GRANT USAGE ON %s.* TO '%s'@'%s'" % [db, user, host]
cursor.execute(grant)

HTH

Upvotes: 1

Related Questions