Why isn't this query working in python?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Gabriel Genellina

    #16
    Re: Why isn't this query working in python?

    En Mon, 28 May 2007 14:53:57 -0300, Dennis Lee Bieber
    <wlfraed@ix.net com.comescribió :
    On Sun, 27 May 2007 20:35:28 -0400, Carsten Haese <carsten@uniqsy s.com>
    declaimed the following in comp.lang.pytho n:
    >
    >On Sun, 2007-05-27 at 16:39 -0400, davelist@mac.co m wrote:
    sql = """SELECT payment_id FROM amember_payment s WHERE
    member_id=%s AND expire_date NOW() AND completed=1 AND (product_id
    >>11 AND product_id <21)""", (self.uid)
    >
    It's confusing, as the example shown is not the common form for
    parameter passing on the .execute() call -- without the .execute() it is
    unclear. I presume the .execute() is using *sql to unpack the tuple...
    Yes, the original message said self.amember_cu rsor.execute(*s ql)
    It IS confusing...

    --
    Gabriel Genellina

    Comment

    • erikcw

      #17
      Re: Why isn't this query working in python?

      On May 28, 2:47 pm, "Gabriel Genellina" <gagsl-...@yahoo.com.a r>
      wrote:
      En Mon, 28 May 2007 14:53:57 -0300, Dennis Lee Bieber
      <wlfr...@ix.net com.comescribió :
      >
      On Sun, 27 May 2007 20:35:28 -0400, Carsten Haese <cars...@uniqsy s.com>
      declaimed the following in comp.lang.pytho n:
      >
      On Sun, 2007-05-27 at 16:39 -0400, davel...@mac.co m wrote:
      sql = """SELECT payment_id FROM amember_payment s WHERE
      member_id=%s AND expire_date NOW() AND completed=1 AND (product_id
      >>11 AND product_id <21)""", (self.uid)
      >
      It's confusing, as the example shown is not the common form for
      parameter passing on the .execute() call -- without the .execute() it is
      unclear. I presume the .execute() is using *sql to unpack the tuple...
      >
      Yes, the original message said self.amember_cu rsor.execute(*s ql)
      It IS confusing...
      >
      --
      Gabriel Genellina
      This is how I've always writing my queries. I learned it from some
      tutorial I found on Google when I started - what is the preferred/
      pythonic way to write this query?

      Thanks!
      Erik

      Comment

      • Steve Holden

        #18
        Re: Why isn't this query working in python?

        erikcw wrote:
        On May 28, 2:47 pm, "Gabriel Genellina" <gagsl-...@yahoo.com.a r>
        wrote:
        >En Mon, 28 May 2007 14:53:57 -0300, Dennis Lee Bieber
        ><wlfr...@ix.ne tcom.comescribi ó:
        >>
        >>On Sun, 27 May 2007 20:35:28 -0400, Carsten Haese <cars...@uniqsy s.com>
        >>declaimed the following in comp.lang.pytho n:
        >>>On Sun, 2007-05-27 at 16:39 -0400, davel...@mac.co m wrote:
        >>>>> sql = """SELECT payment_id FROM amember_payment s WHERE
        >>>>>member_id= %s AND expire_date NOW() AND completed=1 AND (product_id
        >>>>>>>11 AND product_id <21)""", (self.uid)
        >> It's confusing, as the example shown is not the common form for
        >>parameter passing on the .execute() call -- without the .execute() it is
        >>unclear. I presume the .execute() is using *sql to unpack the tuple...
        >Yes, the original message said self.amember_cu rsor.execute(*s ql)
        >It IS confusing...
        >>
        >--
        >Gabriel Genellina
        >
        This is how I've always writing my queries. I learned it from some
        tutorial I found on Google when I started - what is the preferred/
        pythonic way to write this query?
        >
        Use separate names for the SQL statement and the argument tuple, then
        pass them as two separate arguments to cursor.execute( ).

        Apart from anything else this makes it somewhat easier to use the same
        statement with different arguments. But it is no different in principle
        than what you are doing now, so the change won't remove your bug, I'm
        afraid.

        Could you show us a query (with actual results, if you can publish them)
        that works manually but doesn't work in Python? There has to be
        something pretty simple wrong here.

        regards
        Steve
        --
        Steve Holden +1 571 484 6266 +1 800 494 3119
        Holden Web LLC/Ltd http://www.holdenweb.com
        Skype: holdenweb http://del.icio.us/steve.holden
        ------------------ Asciimercial ---------------------
        Get on the web: Blog, lens and tag your way to fame!!
        holdenweb.blogs pot.com squidoo.com/pythonology
        tagged items: del.icio.us/steve.holden/python
        All these services currently offer free registration!
        -------------- Thank You for Reading ----------------

        Comment

        Working...