Frage

I got a table:

+-----------+-------------+------+-----+---------+-------+
| Field     | Type        | Null | Key | Default | Extra |
+-----------+-------------+------+-----+---------+-------+
| Benutzer  | varchar(50) | YES  |     | NULL    |       |
| Confirmed | tinyint(1)  | YES  |     | NULL    |       |
+-----------+-------------+------+-----+---------+-------+

with one entry!

If I execute on the mysql console in a shell:

select Benutzer from UserConfirm where Benutzer = '\{\'gid\'\:\ \'tamer\'\,\ \'uid\'\:\ \'tamer\'\}'

it works!

At mysql-python there comes the errormessage:

TypeError: 'long' object is not callable

What did I make wrong?! Here is my python code:

cursor = self.__db.cursor().execute('select * from UserConfirm where Benutzer = \'' + ds + '\'') 
return cursor().fetchrow()

For any advice, I would kindly thank you.

War es hilfreich?

Lösung

The problem is that you are not storing the cursor object, just the return value of execute, which is not the cursor, it should be:

cursor = self.__db.cursor()
cursor.execute('select * from UserConfirm where Benutzer = \'' + ds + '\'') 
return cursor.fetchone()

Andere Tipps

Note that I assume your line cursor().fetchrow() is a typo and you meant cursor.fetchrow().

Not knowing mysql-python myself, from the error I can assume cursor.execute is returning the number of rows or an error code, not the cursor itself.

Try the following instead:

cursor = self.__db.cursor()
cursor.execute('select * from UserConfirm where Benutzer = \'' + ds + '\'')
return cursor.fetchrow()
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top