Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Cannot run a single MySQLdb execute....

Reply
Thread Tools

Cannot run a single MySQLdb execute....

 
 
Νίκος Γκρ33κ
Guest
Posts: n/a
 
      03-28-2013
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
 
Reply With Quote
 
 
 
 
Chris Angelico
Guest
Posts: n/a
 
      03-28-2013
On Thu, Mar 28, 2013 at 2:50 PM, Νίκος Γκρ33κ <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
 
Νίκος Γκρ33κ
Guest
Posts: n/a
 
      03-28-2013
Τη Πέμπτη, 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.
 
Reply With Quote
 
Νίκος Γκρ33κ
Guest
Posts: n/a
 
      03-28-2013
Τη Πέμπτη, 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.
 
Reply With Quote
 
Νίκος Γκρ33κ
Guest
Posts: n/a
 
      03-28-2013
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....
 
Reply With Quote
 
Νίκος Γκρ33κ
Guest
Posts: n/a
 
      03-28-2013
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....
 
Reply With Quote
 
Chris Angelico
Guest
Posts: n/a
 
      03-28-2013
On Thu, Mar 28, 2013 at 3:03 PM, Νίκος Γκρ33κ <(E-Mail Removed)> 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
 
Reply With Quote
 
Chris Angelico
Guest
Posts: n/a
 
      03-28-2013
On Thu, Mar 28, 2013 at 3:08 PM, Νίκος Γκρ33κ <(E-Mail Removed)> 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
 
Reply With Quote
 
Νίκος Γκρ33κ
Guest
Posts: n/a
 
      03-28-2013
Τη Πέμπτη, 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
 
Reply With Quote
 
Νίκος Γκρ33κ
Guest
Posts: n/a
 
      03-28-2013
Τη Πέμπτη, 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Cannot Read MySQLdb docs within Python interpreter Con Python 1 05-26-2008 11:25 PM
Custom Taglib problems - instead of a single instance per page, I have a single instance per application. chris brat Java 1 05-10-2006 11:16 AM
Asp.NET Javascript string, want to pass '(single quotes' within '(single quotes) Chris ASP .Net 1 03-24-2006 09:03 PM
BoundColumn single DataBind equiv but not in a single row? Randall Parker ASP .Net 1 12-12-2005 04:11 PM
The file 'bin\WebProj.dll' cannot be copied to the run directory. The requested operation cannot be performed on a file with a user-mapped section open. J Gao ASP .Net 0 07-28-2003 04:18 PM



Advertisments