Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

TypeError: 'long' object is not callable

Help
2012-01-15
2012-09-19
  • Tamer Higazi
    Tamer Higazi
    2012-01-15

    Hi!

    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, on python there comes the errormessage:

    TypeError: 'long' object is not callable

    Whatr did I make wrong?!

    Here is my pyhon code:

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

    return cursor().fetchrow()

    for any advise I would kindly thank you.

    Tamer

     
  • Leo Hourvitz
    Leo Hourvitz
    2012-01-15

    If you check [PEP 248, the return value from .execute is undefined (although
    MySQLdb does happen to return rowcount in this case). I think the code you
    want is

    ](http://www.python.org/dev/peps/pep-0249/)

    cursor = self.__db.cursor()
    cursor.execute('select * from UserConfirm where Benutzer = \'' + "test1" + '\'') 1L
    row = cursor.fetchone()
    

    [

    By the way, to protect yourself against SQL injection attacks you should let
    the library put your parameters into the query (and it's less code!).

    ](http://www.python.org/dev/peps/pep-0249/)

    cursor.execute('select * from UserConfirm where Benutzer = %s',"test1")
    

    [

    ](http://www.python.org/dev/peps/pep-0249/)

     
  • Leo Hourvitz
    Leo Hourvitz
    2012-01-15

    (sorry for the messed-up formatting, trying again...)

    If you check PEP 248, the return value from .execute is undefined (although
    MySQLdb does happen to return rowcount in this case). I think the code you
    want is

    cursor = self.__db.cursor()
    cursor.execute('select * from UserConfirm where Benutzer = \'' + "test1" + '\'') 1L
    row = cursor.fetchone()
    

    By the way, to protect yourself against SQL injection attacks you should let
    the library put your parameters into the query (and it's less code!).

    cursor.execute('select * from UserConfirm where Benutzer = %s',"test1")