[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

mysqldb SELECT COUNT reurns 1

SMALLp

12/27/2007 8:04:00 PM

Hy! I nave another problem I can't solve!
<code>

import MySQLdb as mysql

connectionString = {"host":"localhost", "user":"root",
"passwd":"pofuck", "db":"fileshare"}
dataTable = "files"
conn = mysql.connect(host=connectionString["host"],
user=connectionString["user"], passwd=connectionString["passwd"],
db=connectionString["db"])

cursor = conn.cursor()
sql = "SELECT COUNT(*) FROM " + dataTable
res = cursor.execute(sql)
print res

<code>
It prints 1, and there are 88 rows in table. SELECT works fine, but
SELECT COUNT(*) makes problems.

Help! Thanks in advance!
33 Answers

Rob Williscroft

12/27/2007 8:24:00 PM

0

SMALLp wrote in news:fl10ev$hfb$1@ss408.t-com.hr in comp.lang.python:

> Hy! I nave another problem I can't solve!
> <code>
>
> import MySQLdb as mysql

> cursor = conn.cursor()
> sql = "SELECT COUNT(*) FROM " + dataTable
> res = cursor.execute(sql)

I think you need to do:
res = cursor.fetchone()[0]


> print res
>
> <code>
> It prints 1, and there are 88 rows in table. SELECT works fine, but
> SELECT COUNT(*) makes problems.

Rob.
--
http://www.victim-prime.dsl....

SMALLp

12/27/2007 8:32:00 PM

0

Rob Williscroft wrote:
> SMALLp wrote in news:fl10ev$hfb$1@ss408.t-com.hr in comp.lang.python:
>
>> Hy! I nave another problem I can't solve!
>> <code>
>>
>> import MySQLdb as mysql
>
>> cursor = conn.cursor()
>> sql = "SELECT COUNT(*) FROM " + dataTable
>> res = cursor.execute(sql)
>
> I think you need to do:
> res = cursor.fetchone()[0]
>
>
>> print res
>>
>> <code>
>> It prints 1, and there are 88 rows in table. SELECT works fine, but
>> SELECT COUNT(*) makes problems.
>
> Rob.
Of course! Thanks!

John Machin

12/27/2007 8:49:00 PM

0

On Dec 28, 7:03 am, SMALLp <po...@mzm.hr> wrote:
> Hy! I nave another problem I can't solve!
> <code>
>
> import MySQLdb as mysql
>
> connectionString = {"host":"localhost", "user":"root",
> "passwd":"pofuck", "db":"fileshare"}
> dataTable = "files"
> conn = mysql.connect(host=connectionString["host"],
> user=connectionString["user"], passwd=connectionString["passwd"],
> db=connectionString["db"])
>
> cursor = conn.cursor()
> sql = "SELECT COUNT(*) FROM " + dataTable
> res = cursor.execute(sql)
> print res
>
> <code>
> It prints 1, and there are 88 rows in table.

What makes you think that it should return 88?

> SELECT works fine, but

In what sense does a bare "SELECT" work fine??

> SELECT COUNT(*) makes problems.
>
> Help! Thanks in advance!

Consider helping yourself, e.g.:
(1) search the web for "mysqldb tutorial"
(2) read the MySQLdb documentation
(3) read http://www.python.org/dev/peps...

You need to use one of the cursor.fetchXXXX methods to get your
results. The result from a call to cursor.execute is NOT defined in
the Python DBAPI. If you are interested in portability of your code
across database software, you should not rely on it. The value 1
probably just means that the execute call succeeded.

Do read carefully the descriptions of what is returned by each of the
cursor.fetchXXXX methods.

Ian Clark

12/27/2007 11:25:00 PM

0

On 2007-12-27, SMALLp <pofuk@mzm.hr> wrote:
> connectionString = {"host":"localhost", "user":"root",
> "passwd":"pofuck", "db":"fileshare"}
> dataTable = "files"
> conn = mysql.connect(host=connectionString["host"],
> user=connectionString["user"], passwd=connectionString["passwd"],
> db=connectionString["db"])

Just to let you know, that last line can be rewritten as:

conn = mysql.connect(**connectionString)


Ian

mike

1/9/2008 10:41:00 PM

0

On Dec 27 2007, 5:25 pm, Ian Clark <icl...@mail.ewu.edu> wrote:
> On 2007-12-27, SMALLp <po...@mzm.hr> wrote:
>
> > connectionString = {"host":"localhost", "user":"root",
> > "passwd":"pofuck", "db":"fileshare"}
> > dataTable = "files"
> > conn = mysql.connect(host=connectionString["host"],
> > user=connectionString["user"], passwd=connectionString["passwd"],
> > db=connectionString["db"])
>
> Just to let you know, that last line can be rewritten as:
>
> conn = mysql.connect(**connectionString)
>
> Ian

Try using cursor.fetchall() instead of cursor.fetchone()

Photography by James

3/19/2013 6:03:00 PM

0

Come to ultra-liberal Eugene Oregon and see for yourself. Almost all of
the smaller markets, and I've traveled and worked in 19 states, are
filled with quiet and not-so-quiet bigots.

The university of Oregon here is a prime example of an institution with
a history of anti-Semitic teachers, students, and groups like the
Pacifica Foundation and Al-Nakba Awareness. Even the local
reconstructionist synagogue keeps a relatively low profile lest they
encourage the local (so-called) white supremacists.

Disagree if you will (it promotes dialogue at least)...it's out there
and it is dangerous philosophically, physically, and literally. I see it
all the time. But then again, I am not wealthy or even middle class and
thus shielded from what goes on in the streets, amongst the poor, and in
stressed economically depressed areas.

You kill what you fear and
You fear what you do not understand

On 3/19/13 8:30 AM, Shelly wrote:
> On 3/19/2013 11:03 AM, Photography by James wrote:
>> It would be nice to have a Lubavitcher surge out here in Oregon! Once
>> you leave NYC or LA, I have found the anti-Semitism is not only rampant,
>> but in some places institutionalized.
>
> Having lived most of my life in the Boston area, and for a decade in
> Florida (most in Central Florida), and having traveled extensively to
> most of the states, I couldn't disagree with you more.
>

--- news://freenews.netfront.net/ - complaints: news@netfront.net ---

mm

3/19/2013 6:44:00 PM

0

On Tue, 19 Mar 2013 15:03:57 +0000 (UTC), Photography by James
<kg7fu@yahoo.com> wrote:

>It would be nice to have a Lubavitcher surge out here in Oregon! Once
>you leave NYC or LA, I have found the anti-Semitism is not only rampant,
>but in some places institutionalized.

I don't want to make this guy too popular, but let's just say on my
way from Dallas to Baltimore, I lost my wallet. Didn't have enough
money to get home or even to get a room for the night. Borrowed
money from a Lubavitcher rabbi in the small city where I was. There
were 2 or 3 other congregations too, but at 4PM on a summer afternoon,
they didn't answer the phone. (If he hadn't answered I would have
gone to the O or C congregation when it was time for Mincha.)

Earlier I asked the cop where I could find "Traveler's Aid" and he had
never heard of it.
http://en.wikipedia.org/wiki/Travelers_Aid_Society_o...
http://en.wikipedia.org/wiki/Travelers_Aid_Int...


>
>On 3/17/13 6:35 PM, Fattush wrote:
>> The "orthodox surge."
>>
>> http://www.nytimes.com/2013/03/08/opinion/brooks-the-orthodox-surge.html?comment...
>>
>>
>> The article is interesting. Many of the comments are scary. It seems
>> bigotry against Jews is alive and well in the US. :-(
>
>--- news://freenews.netfront.net/ - complaints: news@netfront.net ---

--

Meir

sheldonlg

3/19/2013 8:21:00 PM

0

On 3/19/2013 2:02 PM, Photography by James wrote:
> Come to ultra-liberal Eugene Oregon and see for yourself. Almost all of
> the smaller markets, and I've traveled and worked in 19 states, are
> filled with quiet and not-so-quiet bigots.
>
> The university of Oregon here is a prime example of an institution with
> a history of anti-Semitic teachers, students, and groups like the
> Pacifica Foundation and Al-Nakba Awareness. Even the local
> reconstructionist synagogue keeps a relatively low profile lest they
> encourage the local (so-called) white supremacists.
>
> Disagree if you will (it promotes dialogue at least)...it's out there
> and it is dangerous philosophically, physically, and literally. I see it
> all the time. But then again, I am not wealthy or even middle class and
> thus shielded from what goes on in the streets, amongst the poor, and in
> stressed economically depressed areas.
>
> You kill what you fear and
> You fear what you do not understand

No doubt there is anti-Semitism in the US. There is such everywhere.
There is also anti-black, anti-gay, anti-Irish, anti-whatever everywhere.

You, however, said (and I quote) "Once you leave NYC or LA, I have found
the anti-Semitism is not only rampant, but in some places
institutionalized.".

I objected to that statement as being incorrect. I have lived 37 years
in the Boston area, 5 years in Philadelphia area, 30 years of summers in
Maine, 10 years in Florida, and I have not encountered either "rampant"
not even miniscule, anti-Semitism -- and certainly not
institutionalized. I have also been to many other states (but not
Oregon), and the same story holds.

>
> On 3/19/13 8:30 AM, Shelly wrote:
>> On 3/19/2013 11:03 AM, Photography by James wrote:
>>> It would be nice to have a Lubavitcher surge out here in Oregon! Once
>>> you leave NYC or LA, I have found the anti-Semitism is not only rampant,
>>> but in some places institutionalized.
>>
>> Having lived most of my life in the Boston area, and for a decade in
>> Florida (most in Central Florida), and having traveled extensively to
>> most of the states, I couldn't disagree with you more.
>>
>
> --- news://freenews.netfront.net/ - complaints: news@netfront.net ---
>


--
Shelly

Dennis

3/20/2013 1:14:00 PM

0

Shelly wrote:

> On 3/19/2013 2:02 PM, Photography by James wrote:

>> Come to ultra-liberal Eugene Oregon and see for yourself. Almost all
>> of the smaller markets, and I've traveled and worked in 19 states,
>> are filled with quiet and not-so-quiet bigots.
>>
>> The university of Oregon here is a prime example of an institution
>> with a history of anti-Semitic teachers, students, and groups like
>> the Pacifica Foundation and Al-Nakba Awareness. Even the local
>> reconstructionist synagogue keeps a relatively low profile lest they
>> encourage the local (so-called) white supremacists.
>>
>> Disagree if you will (it promotes dialogue at least)...it's out there
>> and it is dangerous philosophically, physically, and literally. I see
>> it all the time. But then again, I am not wealthy or even middle
>> class and thus shielded from what goes on in the streets, amongst the
>> poor, and in stressed economically depressed areas.
>>
>> You kill what you fear and
>> You fear what you do not understand
>
> No doubt there is anti-Semitism in the US. There is such everywhere.
> There is also anti-black, anti-gay, anti-Irish, anti-whatever
> everywhere.
>
> You, however, said (and I quote) "Once you leave NYC or LA, I have
> found the anti-Semitism is not only rampant, but in some places
> institutionalized.".
>
> I objected to that statement as being incorrect. I have lived 37
> years in the Boston area, 5 years in Philadelphia area, 30 years of
> summers in Maine, 10 years in Florida, and I have not encountered
> either "rampant" not even miniscule, anti-Semitism -- and certainly
> not institutionalized. I have also been to many other states (but not
> Oregon), and the same story holds.

I think that James is describing our rabidly pro-Palestinian ultra-
liberals.

I certainly never saw it growing up in Topeka, Kansas. There a lot of
the Jews were part of the psychiatric staff at the Menninger's Clinic; I
knew a lot of their children when I was growing up. I don't recall any
prejudice.

I myself saw a Canadian-born Jewish psychiatrist in psychotherapy when I
was young, and he was a very bad therapist. Being young and naive in
additon to needing help, and being overawed by the enormous prestige of
the Menninger's Clinic in Kansas and indeed the USA and elsewhere, I did
not understand.

As an adult, I came to realize that I was getting very poor therapy. I
have investigated this fellow and found out plenty about his serious
problems at that time.

However, I had an AlAnon sponsor suggest that part of the problem was the
Jewish emphasis on guilt.

As an adult, I had a respected friend, who shared my interest in Judaism
and the Jews, who nevertheless said, "They invented guilt!"

At some time, I'll try to start a thread on that. It doesn't seem
consistent with the positive attitude and emphasis on 'choose life',
'L'chaim!' of Judaism,

However, I have a childhood buddy who lived near Miami for a long time.
He said, "I can see why you wouldn't like them! They're loud,
obnoxious,and argue over prices at checkouts."

Late in life, I found my own father, who I have always thought very
highly of, was pretty anti-Semitic. He had some bad experiences while he
was a 1st lieutenant in the Army during WWII; I never got the details.
He said some things that I find quite appalling, which I wouldn't repeat
here!

My sister and I both observed that our parents raised us with hardly any
prejudices. Thus, toward the end of her life, she had a pretty serious
boyfriend who was black - and my parents were both quite upset!!! I was
surprised - as I was by my dad's anti-Semitism.

All that aside, I haven't encountered all that much anti-Jewish sentiment
myself. I myself am a sympathizer, of course, otherwise I wouldn't be
here.

Dennis


Yisroel Markov

3/20/2013 3:09:00 PM

0

On Wed, 20 Mar 2013 13:13:53 +0000 (UTC), Dennis
<tsalagi18NOSPAM@hotmail.com> said:

[snip]

>Late in life, I found my own father, who I have always thought very
>highly of, was pretty anti-Semitic. He had some bad experiences while he
>was a 1st lieutenant in the Army during WWII; I never got the details.
>He said some things that I find quite appalling, which I wouldn't repeat
>here!

[nod] Personal experiences can color one's perceptions a lot. The
relevant Russian meme sounds like this (in translation): "I got
nothing against Jews, but I hate kikes!"

>My sister and I both observed that our parents raised us with hardly any
>prejudices. Thus, toward the end of her life, she had a pretty serious
>boyfriend who was black - and my parents were both quite upset!!! I was
>surprised - as I was by my dad's anti-Semitism.

Your parents sound like good people if this was a surprise to you.

>All that aside, I haven't encountered all that much anti-Jewish sentiment
>myself. I myself am a sympathizer, of course, otherwise I wouldn't be
>here.
--
Yisroel "Godwrestler Warriorson" Markov - Boston, MA Member
www.reason.com -- for a sober analysis of the world DNRC
--------------------------------------------------------------------
"Judge, and be prepared to be judged" -- Ayn Rand