Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   MySQLdb compare lower (http://www.velocityreviews.com/forums/t955386-mysqldb-compare-lower.html)

Anatoli Hristov 12-11-2012 09:01 PM

MySQLdb compare lower
 
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

John Gordon 12-11-2012 10:15 PM

Re: MySQLdb compare lower
 
In <mailman.742.1355259688.29569.python-list@python.org> Anatoli Hristov <tolidtm@gmail.com> writes:

> 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())

--
John Gordon A is for Amy, who fell down the stairs
gordon@panix.com B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"


Anatoli Hristov 12-11-2012 10:39 PM

Re: MySQLdb compare lower
 
> 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.


All times are GMT. The time now is 10:10 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.