MySQLdb compare lower

Discussion in 'Python' started by Anatoli Hristov, Dec 11, 2012.

  1. 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
     
    Anatoli Hristov, Dec 11, 2012
    #1
    1. Advertising

  2. Anatoli Hristov

    John Gordon Guest

    In <> Anatoli Hristov <> 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
    B is for Basil, assaulted by bears
    -- Edward Gorey, "The Gashlycrumb Tinies"
     
    John Gordon, Dec 11, 2012
    #2
    1. Advertising

  3. > 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.
     
    Anatoli Hristov, Dec 11, 2012
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Cameron Simpson

    Re: MySQLdb compare lower

    Cameron Simpson, Dec 11, 2012, in forum: Python
    Replies:
    0
    Views:
    157
    Cameron Simpson
    Dec 11, 2012
  2. Dennis Lee Bieber

    Re: MySQLdb compare lower

    Dennis Lee Bieber, Dec 12, 2012, in forum: Python
    Replies:
    0
    Views:
    155
    Dennis Lee Bieber
    Dec 12, 2012
  3. Cameron Simpson

    Re: MySQLdb compare lower

    Cameron Simpson, Dec 13, 2012, in forum: Python
    Replies:
    0
    Views:
    161
    Cameron Simpson
    Dec 13, 2012
  4. Dennis Lee Bieber

    Re: MySQLdb compare lower

    Dennis Lee Bieber, Dec 13, 2012, in forum: Python
    Replies:
    0
    Views:
    153
    Dennis Lee Bieber
    Dec 13, 2012
  5. Cameron Simpson

    Re: MySQLdb compare lower

    Cameron Simpson, Dec 14, 2012, in forum: Python
    Replies:
    0
    Views:
    143
    Cameron Simpson
    Dec 14, 2012
Loading...

Share This Page