Cannot run a single MySQLdb execute....

Discussion in 'Python' started by Íßêïò Ãêñ33ê, Mar 28, 2013.

  1. I'am about to go nuts with python 3.2.3

    Do you see somehtign wrong with the following statement?

    cur.execute( '''SELECT hits FROM counters WHERE url = ?''', (page,) )
    data = cur.fetchone()

    because as you can see by visiting my webpage at http://superhost.gr it produces an error and i dont have aclue why.

    Please help. i'am using MySQLdb
     
    Íßêïò Ãêñ33ê, Mar 28, 2013
    #1
    1. Advertising

  2. Re: Cannot run a single MySQLdb execute....

    On Thu, Mar 28, 2013 at 2:50 PM, Íßêïò Ãêñ33ê <> wrote:
    > I'am about to go nuts with python 3.2.3
    >
    > Do you see somehtign wrong with the following statement?
    >
    > cur.execute( '''SELECT hits FROM counters WHERE url = ?''', (page,) )
    > data = cur.fetchone()
    >
    > because as you can see by visiting my webpage at http://superhost.gr it produces an error and i dont have aclue why.
    >
    > Please help. i'am using MySQLdb


    Is this the docs for the module you're using?
    http://mysql-python.sourceforge.net/MySQLdb.html
    """
    paramstyle
    String constant stating the type of parameter marker formatting
    expected by the interface. Set to 'format' = ANSI C printf format
    codes, e.g. '...WHERE name=%s'. If a mapping object is used for
    conn.execute(), then the interface actually uses 'pyformat' = Python
    extended format codes, e.g. '...WHERE name=%(name)s'. However, the API
    does not presently allow the specification of more than one style in
    paramstyle.

    Note that any literal percent signs in the query string passed to
    execute() must be escaped, i.e. %%.

    Parameter placeholders can only be used to insert column values. They
    can not be used for other parts of SQL, such as table names,
    statements, etc.
    """

    What paramstyle are you using?

    ChrisA
     
    Chris Angelico, Mar 28, 2013
    #2
    1. Advertising

  3. Re: Cannot run a single MySQLdb execute....

    Ôç ÐÝìðôç, 28 Ìáñôßïõ 2013 6:00:17 ð.ì. UTC+2, ï ÷ñÞóôçò Chris Angelico Ýãñáøå:

    > What paramstyle are you using?


    Yes it is Chris, but i'am not sure what exactly are you asking me.
    Please if you cna pout it even simper for me, thank you.
     
    Íßêïò Ãêñ33ê, Mar 28, 2013
    #3
  4. Re: Cannot run a single MySQLdb execute....

    Ôç ÐÝìðôç, 28 Ìáñôßïõ 2013 6:00:17 ð.ì. UTC+2, ï ÷ñÞóôçò Chris Angelico Ýãñáøå:

    > What paramstyle are you using?


    Yes it is Chris, but i'am not sure what exactly are you asking me.
    Please if you cna pout it even simper for me, thank you.
     
    Íßêïò Ãêñ33ê, Mar 28, 2013
    #4
  5. Re: Cannot run a single MySQLdb execute....

    If you mean if iam using '?' or this '%s' the latter used to work flawlessly with python 2.6 but it does not in pythin 3.2.3

    both this command fail in python 3.x

    cur.execute( '''SELECT hits FROM counters WHERE url = ?''', (page,) )

    cur.execute( '''SELECT hits FROM counters WHERE url = %s''', (page,) )

    i dont have a clue why....
     
    Íßêïò Ãêñ33ê, Mar 28, 2013
    #5
  6. Re: Cannot run a single MySQLdb execute....

    If you mean if iam using '?' or this '%s' the latter used to work flawlessly with python 2.6 but it does not in pythin 3.2.3

    both this command fail in python 3.x

    cur.execute( '''SELECT hits FROM counters WHERE url = ?''', (page,) )

    cur.execute( '''SELECT hits FROM counters WHERE url = %s''', (page,) )

    i dont have a clue why....
     
    Íßêïò Ãêñ33ê, Mar 28, 2013
    #6
  7. Re: Cannot run a single MySQLdb execute....

    On Thu, Mar 28, 2013 at 3:03 PM, Íßêïò Ãêñ33ê <> wrote:
    > Ôç ÐÝìðôç, 28 Ìáñôßïõ 2013 6:00:17 ð.ì.UTC+2, ï ÷ñÞóôçò Chris Angelico Ýãñáøå:
    >
    >> What paramstyle are you using?

    >
    > Yes it is Chris, but i'am not sure what exactly are you asking me.
    > Please if you cna pout it even simper for me, thank you.


    As it says in that document, paramstyle is a top-level module
    attribute. Try printing it out. See what it says. Then match your code
    to it.

    ChrisA
     
    Chris Angelico, Mar 28, 2013
    #7
  8. Re: Cannot run a single MySQLdb execute....

    On Thu, Mar 28, 2013 at 3:08 PM, Íßêïò Ãêñ33ê <> wrote:
    > If you mean if iam using '?' or this '%s' the latter used to work flawlessly with python 2.6 but it does not in pythin 3.2.3


    Print out the value of that attribute.

    ChrisA
     
    Chris Angelico, Mar 28, 2013
    #8
  9. Re: Cannot run a single MySQLdb execute....

    Ôç ÐÝìðôç, 28 Ìáñôßïõ 2013 6:08:28 ð.ì. UTC+2, ï ÷ñÞóôçò Chris Angelico Ýãñáøå:

    > As it says in that document, paramstyle is a top-level module
    > attribute. Try printing it out. See what it says. Then match your code


    sql = '''SELECT hits FROM counters WHERE url = %s''' % page
    print( sql )
    cur.execute( sql )

    Now the error says:

    _mysql_exceptions.OperationalError: (1054, "Unknown column 'index.html' in 'where clause'") as you cna see at my webpage
     
    Íßêïò Ãêñ33ê, Mar 28, 2013
    #9
  10. Re: Cannot run a single MySQLdb execute....

    Ôç ÐÝìðôç, 28 Ìáñôßïõ 2013 6:08:28 ð.ì. UTC+2, ï ÷ñÞóôçò Chris Angelico Ýãñáøå:

    > As it says in that document, paramstyle is a top-level module
    > attribute. Try printing it out. See what it says. Then match your code


    sql = '''SELECT hits FROM counters WHERE url = %s''' % page
    print( sql )
    cur.execute( sql )

    Now the error says:

    _mysql_exceptions.OperationalError: (1054, "Unknown column 'index.html' in 'where clause'") as you cna see at my webpage
     
    Íßêïò Ãêñ33ê, Mar 28, 2013
    #10
  11. Re: Cannot run a single MySQLdb execute....

    On Thu, Mar 28, 2013 at 3:18 PM, Íßêïò Ãêñ33ê <> wrote:
    > Ôç ÐÝìðôç, 28 Ìáñôßïõ 2013 6:08:28 ð.ì.UTC+2, ï ÷ñÞóôçò Chris Angelico Ýãñáøå:
    >
    >> As it says in that document, paramstyle is a top-level module
    >> attribute. Try printing it out. See what it says. Then match your code

    >
    > sql = '''SELECT hits FROM counters WHERE url = %s''' % page
    > print( sql )
    > cur.execute( sql )
    >
    > Now the error says:
    >
    > _mysql_exceptions.OperationalError: (1054, "Unknown column 'index.html' in 'where clause'") as you cna see at my webpage


    http://www.facepalm.de/

    Do you understand SQL injection attacks and the concept of
    parameterized queries?

    ChrisA
     
    Chris Angelico, Mar 28, 2013
    #11
  12. Re: Cannot run a single MySQLdb execute....

    Ôç ÐÝìðôç, 28 Ìáñôßïõ 2013 6:26:48 ð.ì. UTC+2, ï ÷ñÞóôçò Chris Angelico Ýãñáøå:
    > On Thu, Mar 28, 2013 at 3:18 PM, Íßêïò Ãêñ33ê <> wrote:
    >
    > > Ôç ÐÝìðôç, 28 Ìáñôßïõ 2013 6:08:28 ð.ì. UTC+2, ï ÷ñÞóôçò Chris Angelico Ýãñáøå:

    >
    > >

    >
    > >> As it says in that document, paramstyle is a top-level module

    >
    > >> attribute. Try printing it out. See what it says. Then match your code

    >
    > >

    >
    > > sql = '''SELECT hits FROM counters WHERE url = %s''' % page

    >
    > > print( sql )

    >
    > > cur.execute( sql )

    >
    > >

    >
    > > Now the error says:

    >
    > >

    >
    > > _mysql_exceptions.OperationalError: (1054, "Unknown column 'index.html'in 'where clause'") as you cna see at my webpage

    >
    >
    >
    > http://www.facepalm.de/
    >
    >
    >
    > Do you understand SQL injection attacks and the concept of
    >
    > parameterized queries?
    >
    >
    >
    > ChrisA


    Yes i know i'am not supposed to use "%s" and i dotn want to but you asked me to print the sql statemnt before executing it.

    please its 6:30am here in greece and didnt had any sleep yet.
    please tell me whats wrong....
     
    Íßêïò Ãêñ33ê, Mar 28, 2013
    #12
  13. Re: Cannot run a single MySQLdb execute....

    Ôç ÐÝìðôç, 28 Ìáñôßïõ 2013 6:26:48 ð.ì. UTC+2, ï ÷ñÞóôçò Chris Angelico Ýãñáøå:
    > On Thu, Mar 28, 2013 at 3:18 PM, Íßêïò Ãêñ33ê <> wrote:
    >
    > > Ôç ÐÝìðôç, 28 Ìáñôßïõ 2013 6:08:28 ð.ì. UTC+2, ï ÷ñÞóôçò Chris Angelico Ýãñáøå:

    >
    > >

    >
    > >> As it says in that document, paramstyle is a top-level module

    >
    > >> attribute. Try printing it out. See what it says. Then match your code

    >
    > >

    >
    > > sql = '''SELECT hits FROM counters WHERE url = %s''' % page

    >
    > > print( sql )

    >
    > > cur.execute( sql )

    >
    > >

    >
    > > Now the error says:

    >
    > >

    >
    > > _mysql_exceptions.OperationalError: (1054, "Unknown column 'index.html'in 'where clause'") as you cna see at my webpage

    >
    >
    >
    > http://www.facepalm.de/
    >
    >
    >
    > Do you understand SQL injection attacks and the concept of
    >
    > parameterized queries?
    >
    >
    >
    > ChrisA


    Yes i know i'am not supposed to use "%s" and i dotn want to but you asked me to print the sql statemnt before executing it.

    please its 6:30am here in greece and didnt had any sleep yet.
    please tell me whats wrong....
     
    Íßêïò Ãêñ33ê, Mar 28, 2013
    #13
  14. Re: Cannot run a single MySQLdb execute....

    On Thu, Mar 28, 2013 at 3:30 PM, Íßêïò Ãêñ33ê <> wrote:
    > Ôç ÐÝìðôç, 28 Ìáñôßïõ 2013 6:26:48 ð.ì.UTC+2, ï ÷ñÞóôçò Chris Angelico Ýãñáøå:
    >> On Thu, Mar 28, 2013 at 3:18 PM, Íßêïò Ãêñ33ê <> wrote:
    >>
    >> > Ôç ÐÝìðôç, 28 Ìáñôßïõ 2013 6:08:28 ð.ì. UTC+2, ï ÷ñÞóôçò Chris Angelico Ýãñáøå:

    >>
    >> >

    >>
    >> >> As it says in that document, paramstyle is a top-level module

    >>
    >> >> attribute. Try printing it out. See what it says. Then match your code

    >>
    >> >

    >>
    >> > sql = '''SELECT hits FROM counters WHERE url = %s''' % page

    >>
    >> > print( sql )

    >>
    >> > cur.execute( sql )

    >>
    >> >

    >>
    >> > Now the error says:

    >>
    >> >

    >>
    >> > _mysql_exceptions.OperationalError: (1054, "Unknown column 'index.html' in 'where clause'") as you cna see at my webpage

    >>
    >>
    >>
    >> http://www.facepalm.de/
    >>
    >>
    >>
    >> Do you understand SQL injection attacks and the concept of
    >>
    >> parameterized queries?
    >>
    >>
    >>
    >> ChrisA

    >
    > Yes i know i'am not supposed to use "%s" and i dotn want to but you askedme to print the sql statemnt before executing it.
    >
    > please its 6:30am here in greece and didnt had any sleep yet.
    > please tell me whats wrong....


    No. I said to print out the paramstyle attribute. If it's that late
    and you haven't slept, get some sleep, then reread this thread. You
    may be able to respond more intelligently.

    ChrisA
     
    Chris Angelico, Mar 28, 2013
    #14
  15. Re: Cannot run a single MySQLdb execute....

    Ôç ÐÝìðôç, 28 Ìáñôßïõ 2013 6:35:14 ð.ì. UTC+2, ï ÷ñÞóôçò Chris Angelico Ýãñáøå:

    > No. I said to print out the paramstyle attribute. If it's that late
    >
    > and you haven't slept, get some sleep, then reread this thread. You
    >
    > may be able to respond more intelligently.


    What is a paramstyle attribute?

    Tell me what exactly it is in simple words and i;ll print it for you.

    I can't get any sleep because ia'am too tense with this issue.
     
    Íßêïò Ãêñ33ê, Mar 28, 2013
    #15
  16. Re: Cannot run a single MySQLdb execute....

    Ôç ÐÝìðôç, 28 Ìáñôßïõ 2013 6:35:14 ð.ì. UTC+2, ï ÷ñÞóôçò Chris Angelico Ýãñáøå:

    > No. I said to print out the paramstyle attribute. If it's that late
    >
    > and you haven't slept, get some sleep, then reread this thread. You
    >
    > may be able to respond more intelligently.


    What is a paramstyle attribute?

    Tell me what exactly it is in simple words and i;ll print it for you.

    I can't get any sleep because ia'am too tense with this issue.
     
    Íßêïò Ãêñ33ê, Mar 28, 2013
    #16
  17. Re: Cannot run a single MySQLdb execute....

    Can someone else esxcept Chris help me please?

    I'm strugling with this and cannot see whats wrong.
     
    Íßêïò Ãêñ33ê, Mar 28, 2013
    #17
  18. Re: Cannot run a single MySQLdb execute....

    Can someone else esxcept Chris help me please?

    I'm strugling with this and cannot see whats wrong.
     
    Íßêïò Ãêñ33ê, Mar 28, 2013
    #18
  19. Re: Cannot run a single MySQLdb execute....

    Íßêïò Ãêñ33ê <> :


    >> What paramstyle are you using?

    >
    >Yes it is Chris, but i'am not sure what exactly are you asking me.
    >Please if you cna pout it even simper for me, thank you.


    For instance:


    >>> import MySQLdb
    >>> MySQLdb.paramstyle

    'format'

    FWIW and HTH,
    DC
     
    David M Chess, Mar 28, 2013
    #19
  20. Re: Cannot run a single MySQLdb execute....

    Ôç ÐÝìðôç, 28 Ìáñôßïõ 2013 4:51:16 ì.ì. UTC+2, ï ÷ñÞóôçò David M Chess Ýãñáøå:
    > Íßêïò Ãêñ33ê <>
    > :
    >
    >
    >
    > >> What paramstyle are you using?

    >
    > >

    >
    > >Yes it is Chris, but i'am not sure what exactly are you asking me.

    >
    > >Please if you cna pout it even simper for me, thank you.

    >
    >
    >
    > For instance:
    >
    >
    >
    > >>> import MySQLdb

    >
    > >>> MySQLdb.paramstyle

    >
    > 'format'
    >
    >



    [~]# /usr/bin/python3
    Python 3.2.3 (default, May 23 2012, 18:47:48)
    [GCC 4.4.6 20110731 (Red Hat 4.4.6-3)] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import MySQLdb
    >>> MySQLdb.paramstyle

    'format'
    >>>
     
    Íßêïò Ãêñ33ê, Mar 28, 2013
    #20
    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. J Gao
    Replies:
    0
    Views:
    1,215
    J Gao
    Jul 28, 2003
  2. Sheila King

    MySQLdb: execute query results...

    Sheila King, Sep 1, 2003, in forum: Python
    Replies:
    1
    Views:
    2,681
    Sheila King
    Sep 1, 2003
  3. Tim Williams
    Replies:
    2
    Views:
    643
    Tim Williams
    May 28, 2004
  4. Carles Pina i Estany

    mysqldb execute timeout

    Carles Pina i Estany, Apr 20, 2007, in forum: Python
    Replies:
    0
    Views:
    610
    Carles Pina i Estany
    Apr 20, 2007
  5. John Nagle
    Replies:
    20
    Views:
    658
    M.-A. Lemburg
    Feb 7, 2008
Loading...

Share This Page