Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #34646 > unrolled thread
| Started by | Anatoli Hristov <tolidtm@gmail.com> |
|---|---|
| First post | 2012-12-11 22:01 +0100 |
| Last post | 2012-12-11 23:39 +0100 |
| Articles | 3 — 2 participants |
Back to article view | Back to comp.lang.python
MySQLdb compare lower Anatoli Hristov <tolidtm@gmail.com> - 2012-12-11 22:01 +0100
Re: MySQLdb compare lower John Gordon <gordon@panix.com> - 2012-12-11 22:15 +0000
Re: MySQLdb compare lower Anatoli Hristov <tolidtm@gmail.com> - 2012-12-11 23:39 +0100
| From | Anatoli Hristov <tolidtm@gmail.com> |
|---|---|
| Date | 2012-12-11 22:01 +0100 |
| Subject | MySQLdb compare lower |
| Message-ID | <mailman.742.1355259688.29569.python-list@python.org> |
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
[toc] | [next] | [standalone]
| From | John Gordon <gordon@panix.com> |
|---|---|
| Date | 2012-12-11 22:15 +0000 |
| Message-ID | <ka8ba8$bpo$1@reader1.panix.com> |
| In reply to | #34646 |
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"
[toc] | [prev] | [next] | [standalone]
| From | Anatoli Hristov <tolidtm@gmail.com> |
|---|---|
| Date | 2012-12-11 23:39 +0100 |
| Message-ID | <mailman.751.1355265586.29569.python-list@python.org> |
| In reply to | #34652 |
> 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.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web