MySQLdbd error. Perhpas it isn't installed?

  • Thread starter Íßêïò Ãêñ33ê
  • Start date
Í

Íßêïò Ãêñ33ê

Ôç ÔåôÜñôç, 27 Ìáñôßïõ 2013 9:28:35 ì.ì.. UTC+2, ï ÷ñÞóôçò Chris Angelico Ýãñáøå:
cur.execute('''SELECT hits FROM counters WHERE url = ?''', (page, ))
This is what you need to do.


The following works in python 2.6

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

is there a difefrence between the above and the follwong which works in python 3.x

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

I'am confused. Which one is the correct?

Also now http://superhost.gr seems to stuck in the following line which i try to open an acii file to slect a random line, please take a look.
 
D

Dennis Lee Bieber

A brief look at the documentation tells me that MySQL uses '?' as the
placeholder instead of '%s':

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

What documentation is that from... MySQLdb has used %s for ages (if
you look at the source code of the adapter, it actually uses Python's
string interpolation to fill in the SQL /after/ it has escaped/quoted
each parameter.

Now, I don't know about the recent "pure Python" MySQL adapter...
 
Í

Íßêïò Ãêñ33ê

Ôç ÐÝìðôç, 28 Ìáñôßïõ 2013 12:48:54 ð.ì. UTC+2, ï ÷ñÞóôçò Dennis Lee Bieber Ýãñáøå:
What documentation is that from... MySQLdb has used %s for ages (if

you look at the source code of the adapter, it actually uses Python's

string interpolation to fill in the SQL /after/ it has escaped/quoted

each parameter.



Now, I don't know about the recent "pure Python" MySQL adapter...

--

Wulfraed Dennis Lee Bieber AF6VN

(e-mail address removed) HTTP://wlfraed.home.netcom.com/

So dod i have to use '%s' or (?) what is better? and as for the synatx thati asked in my previous post? what is the correct one?
 
Í

Íßêïò Ãêñ33ê

Ôç ÐÝìðôç, 28 Ìáñôßïõ 2013 12:48:54 ð.ì. UTC+2, ï ÷ñÞóôçò Dennis Lee Bieber Ýãñáøå:
What documentation is that from... MySQLdb has used %s for ages (if

you look at the source code of the adapter, it actually uses Python's

string interpolation to fill in the SQL /after/ it has escaped/quoted

each parameter.



Now, I don't know about the recent "pure Python" MySQL adapter...

--

Wulfraed Dennis Lee Bieber AF6VN

(e-mail address removed) HTTP://wlfraed.home.netcom.com/

So dod i have to use '%s' or (?) what is better? and as for the synatx thati asked in my previous post? what is the correct one?
 
Í

Íßêïò Ãêñ33ê

The following works in python 3.2

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

is there a difefrence between the above and the follwong which works in python 2.6

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

Also whats better? use '%s' or '?' and why?

I'am confused. Which one is the correct?

Also now http://superhost.gr seems to stuck in the following line which i try to open an acii file to slect a random line, please take a look.
 
Í

Íßêïò Ãêñ33ê

The following works in python 3.2

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

is there a difefrence between the above and the follwong which works in python 2.6

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

Also whats better? use '%s' or '?' and why?

I'am confused. Which one is the correct?

Also now http://superhost.gr seems to stuck in the following line which i try to open an acii file to slect a random line, please take a look.
 
Í

Íßêïò Ãêñ33ê

I think i have figured this out:

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

is a tuple of two objects. The first is the result of
cur.execute( '''SELECT hits FROM counters WHERE url = %s''')
and the second is
(page,)


cur.execute( '''SELECT hits FROM counters WHERE url = %s''' , (page,) )
is the result of the execute method of the cur object called with two arguments.



Is this correct?
 
Í

Íßêïò Ãêñ33ê

I think i have figured this out:

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

is a tuple of two objects. The first is the result of
cur.execute( '''SELECT hits FROM counters WHERE url = %s''')
and the second is
(page,)


cur.execute( '''SELECT hits FROM counters WHERE url = %s''' , (page,) )
is the result of the execute method of the cur object called with two arguments.



Is this correct?
 
C

Chris Angelico

The following works in python 3.2

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

This is an email list and newsgroup. You don't need tags like that.

I don't know what you mean by "works". Check out the operator precedence table:

http://docs.python.org/3.3/reference/expressions.html#operator-precedence

Figure out what the above expression will do, then decide for yourself
whether page is having any effect on it.

ChrisA
 
C

Chris Angelico

I think i have figured this out:

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

is a tuple of two objects. The first is the result of
cur.execute( '''SELECT hits FROM counters WHERE url = %s''')
and the second is
(page,)


cur.execute( '''SELECT hits FROM counters WHERE url = %s''' , (page,) )
is the result of the execute method of the cur object called with two arguments.




Is this correct?

Ah, crossed in the post. Yes, this is correct, as you can confirm with
the operator precedence table that I posted above. (Experienced
programmers would have the universal precedences in their heads, but
the same applies.)

ChrisA
 
Í

Íßêïò Ãêñ33ê

Thank you for verifying this,

Also now http://superhost.gr seems to stuck in the following line which i try to open an acii file to slect a random line, please take a look.
 
Í

Íßêïò Ãêñ33ê

Thank you for verifying this,

Also now http://superhost.gr seems to stuck in the following line which i try to open an acii file to slect a random line, please take a look.
 
C

Chris Angelico

Thank you for verifying this,

Also now http://superhost.gr seems to stuck in the following line which itry to open an acii file to slect a random line, please take a look.

Your quotes file isn't ASCII. Read the error message, Python is being
very helpful.

ChrisA
 
Í

Íßêïò Ãêñ33ê

Ôç ÐÝìðôç, 28 Ìáñôßïõ 2013 4:46:48 ð.ì. UTC+2, ï ÷ñÞóôçò Chris Angelico Ýãñáøå:
Your quotes file isn't ASCII. Read the error message, Python is being

very helpful.

Then how come the same .txt file opens normally in Python 2.6

i also tried to save ti as .ascii istead of utf-8 file and still same erroralso if i quote it out same things happen in those liens too.

f = open( "/home/nikos/www/" + page )
htmldata = f.read()

f.read produced the same kind of error. why?
 
Í

Íßêïò Ãêñ33ê

Ôç ÐÝìðôç, 28 Ìáñôßïõ 2013 4:46:48 ð.ì. UTC+2, ï ÷ñÞóôçò Chris Angelico Ýãñáøå:
Your quotes file isn't ASCII. Read the error message, Python is being

very helpful.

Then how come the same .txt file opens normally in Python 2.6

i also tried to save ti as .ascii istead of utf-8 file and still same erroralso if i quote it out same things happen in those liens too.

f = open( "/home/nikos/www/" + page )
htmldata = f.read()

f.read produced the same kind of error. why?
 
Í

Íßêïò Ãêñ33ê

this worked

quote = random.choice( list( open( "/home/nikos/www/data/private/quotes.txt", 'rb') ) )

and also this

f = open( "/home/nikos/www/" + page, 'rb' )

i dont know why python 3 needs 'rb' though.

Now ima having problem with this:

htmldata = htmldata % (quote, music)

it says soemthign about wrong operand....
 
Í

Íßêïò Ãêñ33ê

this worked

quote = random.choice( list( open( "/home/nikos/www/data/private/quotes.txt", 'rb') ) )

and also this

f = open( "/home/nikos/www/" + page, 'rb' )

i dont know why python 3 needs 'rb' though.

Now ima having problem with this:

htmldata = htmldata % (quote, music)

it says soemthign about wrong operand....
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top