Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   Cannot run a single MySQLdb execute.... (http://www.velocityreviews.com/forums/t959150-cannot-run-a-single-mysqldb-execute.html)

Νίκος Γκρ33κ 03-28-2013 03:50 AM

Cannot run a single MySQLdb execute....
 
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

Chris Angelico 03-28-2013 04:00 AM

Re: Cannot run a single MySQLdb execute....
 
On Thu, Mar 28, 2013 at 2:50 PM, Νίκος Γκρ33κ <nikos.gr33k@gmail.com> 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

Νίκος Γκρ33κ 03-28-2013 04:03 AM

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κ 03-28-2013 04:03 AM

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κ 03-28-2013 04:08 AM

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κ 03-28-2013 04:08 AM

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....

Chris Angelico 03-28-2013 04:08 AM

Re: Cannot run a single MySQLdb execute....
 
On Thu, Mar 28, 2013 at 3:03 PM, Νίκος Γκρ33κ <nikos.gr33k@gmail.com> 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 03-28-2013 04:14 AM

Re: Cannot run a single MySQLdb execute....
 
On Thu, Mar 28, 2013 at 3:08 PM, Νίκος Γκρ33κ <nikos.gr33k@gmail.com> 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

Νίκος Γκρ33κ 03-28-2013 04:18 AM

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κ 03-28-2013 04:18 AM

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


All times are GMT. The time now is 08:07 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.