MySQLdb compare lower

A

Anatoli Hristov

Hello guys,

Excuse me for the noob question, but is there a way to compare a field
in mysql as lower() somehow?

I have a situation where I compare the SKU in my DB and there are some
SKU that are with lowercase and some with uppercase, how can I solve
this in your opinion ?

def Update_SQL(price, sku):

db = MySQLdb.connect("localhost","getit","opencart",
use_unicode=True, charset="utf8")
cursor = db.cursor()
sql = "UPDATE product SET price=%s WHERE sku=%s"
cursor.execute(sql, (price, sku))
db.commit()
db.close()


Thanks
 
J

John Gordon

In said:
I have a situation where I compare the SKU in my DB and there are some
SKU that are with lowercase and some with uppercase, how can I solve
this in your opinion ?
def Update_SQL(price, sku):
db = MySQLdb.connect("localhost","getit","opencart",
use_unicode=True, charset="utf8")
cursor = db.cursor()
sql = "UPDATE product SET price=%s WHERE sku=%s"
cursor.execute(sql, (price, sku))
db.commit()
db.close()

I think this will work:

sql = 'UPDATE product SET price=%s WHERE LOWER(sku)=%s'
cursor.execute(sql, (price, sku.lower())
 
A

Anatoli Hristov

I think this will work:
sql = 'UPDATE product SET price=%s WHERE LOWER(sku)=%s'
cursor.execute(sql, (price, sku.lower())
Thanks John, this works, I was about to make double check with lower
and upper, but this saves me :)

Thanks a lot.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top