MySQLdb: ValueError Something Stupid

M

mcl

I have just started with python and MySQL.

I have a simple test for each of my tables.

The first two work as expected, but the third 'qlooks', gives a
ValueError.

If I copy and paste the SQL in the traceback to phpMyAdmin, it works
as expected.

Can anyone give a clue as to what I am doing wrong

Python 2.4
MySQL 4.1.22-standard

The tablename qlooks is LOWERCASE

Code =======================================================
cursor = gv.conn.cursor()
queries = ["%septi%"]
fields = ("qlTitle", "qlSubTitle", "qlPostCode", "qlMap",
"qlDetails")
tblFields = "select * from qlooks "
whereTests = 'Where qlTitle like "%septi%"'
sql = tblFields + whereTests
#cursor.execute(sql)
cursor.execute('select * from PERMS')
row = cursor.fetchone()
print "Row=", row, gv.nl
cursor.execute('select * from LISTS')
row = cursor.fetchone()
print "Row=", row, gv.nl
cursor.execute('select * from qlooks')
row = cursor.fetchone()
print "Row=", row, gv.nl

cursor.close()

ERROR TRACEBACK ++++++++++++++++++++++++++++++++++++++++

79 print "Row=", row, gv.nl
80 cursor.execute('select * from qlooks')
81 row = cursor.fetchone()
82 print "Row=", row, gv.nl
cursor = <MySQLdb.cursors.Cursor instance>, cursor.execute = <bound
method Cursor.execute of <MySQLdb.cursors.Cursor instance>>
/usr/lib/python2.4/site-packages/MySQLdb/cursors.py in
execute(self=<MySQLdb.cursors.Cursor instance>, query='select * from
qlooks', args=None)
93 """
94 del self.messages[:]
95 return self._execute(query, args)
96
97 def _execute(self, query, args):
self = <MySQLdb.cursors.Cursor instance>, self._execute = <bound
method Cursor._execute of <MySQLdb.cursors.Cursor instance>>, query =
'select * from qlooks', args = None
/usr/lib/python2.4/site-packages/MySQLdb/cursors.py in
_execute(self=<MySQLdb.cursors.Cursor instance>, query='select * from
qlooks', args=None)
112 exc, value, tb = exc_info()
113 del tb
114 self.errorhandler(self, exc, value)
115 self._executed = query
116 return r
self = <MySQLdb.cursors.Cursor instance>, self.errorhandler = <bound
method Connection.defaulterrorhandler of ...l.connection open to
'db.sabren.com' at 936cac4>>, exc = <class exceptions.ValueError>,
value = <exceptions.ValueError instance>
/usr/lib/python2.4/site-packages/MySQLdb/connections.py in
defaulterrorhandler(connection=<_mysql.connection open to
'db.sabren.com' at 936cac4>, cursor=<MySQLdb.cursors.Cursor instance>,
errorclass=<class exceptions.ValueError>,
errorvalue=<exceptions.ValueError instance>)
31 else:
32 connection.messages.append(error)
33 raise errorclass, errorvalue
34
35
errorclass = <class exceptions.ValueError>, errorvalue =
<exceptions.ValueError instance>

ValueError: invalid literal for int(): 0-
args = ('invalid literal for int(): 0-',)


=========================================
Thanks Richard
 
M

mcl

I have just started with python and MySQL.

I have a simple test for each of my tables.

The first two work as expected, but the third 'qlooks', gives a
ValueError.

If I copy and paste the SQL in the traceback to phpMyAdmin, it works
as expected.

Can anyone give a clue as to what I am doing wrong

Python 2.4
MySQL 4.1.22-standard

The tablename qlooks is LOWERCASE

Code =======================================================
cursor = gv.conn.cursor()
queries = ["%septi%"]
fields = ("qlTitle", "qlSubTitle", "qlPostCode", "qlMap",
"qlDetails")
tblFields = "select * from qlooks "
whereTests = 'Where qlTitle like "%septi%"'
sql = tblFields + whereTests
#cursor.execute(sql)
cursor.execute('select * from PERMS')
row = cursor.fetchone()
print "Row=", row, gv.nl
cursor.execute('select * from LISTS')
row = cursor.fetchone()
print "Row=", row, gv.nl
cursor.execute('select * from qlooks')
row = cursor.fetchone()
print "Row=", row, gv.nl

cursor.close()

ERROR TRACEBACK ++++++++++++++++++++++++++++++++++++++++

79 print "Row=", row, gv.nl
80 cursor.execute('select * from qlooks')
81 row = cursor.fetchone()
82 print "Row=", row, gv.nl
cursor = <MySQLdb.cursors.Cursor instance>, cursor.execute = <bound
method Cursor.execute of <MySQLdb.cursors.Cursor instance>>
/usr/lib/python2.4/site-packages/MySQLdb/cursors.py in
execute(self=<MySQLdb.cursors.Cursor instance>, query='select * from
qlooks', args=None)
93 """
94 del self.messages[:]
95 return self._execute(query, args)
96
97 def _execute(self, query, args):
self = <MySQLdb.cursors.Cursor instance>, self._execute = <bound
method Cursor._execute of <MySQLdb.cursors.Cursor instance>>, query =
'select * from qlooks', args = None
/usr/lib/python2.4/site-packages/MySQLdb/cursors.py in
_execute(self=<MySQLdb.cursors.Cursor instance>, query='select * from
qlooks', args=None)
112 exc, value, tb = exc_info()
113 del tb
114 self.errorhandler(self, exc, value)
115 self._executed = query
116 return r
self = <MySQLdb.cursors.Cursor instance>, self.errorhandler = <bound
method Connection.defaulterrorhandler of ...l.connection open to
'db.sabren.com' at 936cac4>>, exc = <class exceptions.ValueError>,
value = <exceptions.ValueError instance>
/usr/lib/python2.4/site-packages/MySQLdb/connections.py in
defaulterrorhandler(connection=<_mysql.connection open to
'db.sabren.com' at 936cac4>, cursor=<MySQLdb.cursors.Cursor instance>,
errorclass=<class exceptions.ValueError>,
errorvalue=<exceptions.ValueError instance>)
31 else:
32 connection.messages.append(error)
33 raise errorclass, errorvalue
34
35
errorclass = <class exceptions.ValueError>, errorvalue =
<exceptions.ValueError instance>

ValueError: invalid literal for int(): 0-
args = ('invalid literal for int(): 0-',)

=========================================
Thanks Richard

Sort of solved it.

On that particular table it did not like * for all fields.

Any reason why that would be the case ?

Richard
 
C

Carsten Haese

Sort of solved it.

On that particular table it did not like * for all fields.

Any reason why that would be the case ?

None that we can divine without more information. What's the schema for
the table in question, which column(s) are you excluding to make the
query work, and what kind of data is in the column(s) you're excluding?
 
M

mcl

None that we can divine without more information. What's the schema for
the table in question, which column(s) are you excluding to make the
query work, and what kind of data is in the column(s) you're excluding?

Thanks for replying.

I did not exclude any columns and the Schema is:

CREATE TABLE lstData (
qlCat varchar(20) NOT NULL default '',
qlTitle varchar(255) NOT NULL default '',
qlSubTitle varchar(255) default NULL,
qlDetails text,
qlPic varchar(20) default NULL,
qlPostCode varchar(16) default NULL,
qlUpd timestamp NOT NULL default '0000-00-00 00:00:00' on update
CURRENT_TIMESTAMP,
KEY `idx-qlCat` (qlCat)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

Thanks again

Richard
 
L

Lawrence D'Oliveiro

mcl said:
ValueError: invalid literal for int(): 0-

Could it be you have a MySQL column that is declared as some integer type,
but contains this funny "0-" value? So when MySQLdb tries to return it as a
Python integer, it fails to convert.
 
J

Justin Ezequiel

Thanks for replying.

I did not exclude any columns and the Schema is:

CREATE TABLE lstData (
qlCat varchar(20) NOT NULL default '',
qlTitle varchar(255) NOT NULL default '',
qlSubTitle varchar(255) default NULL,
qlDetails text,
qlPic varchar(20) default NULL,
qlPostCode varchar(16) default NULL,
qlUpd timestamp NOT NULL default '0000-00-00 00:00:00' on update
CURRENT_TIMESTAMP,
KEY `idx-qlCat` (qlCat)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

Thanks again

Richard

saw this before on earlier MySQLdb and timestamp column
try upgrading your MySQLdb

see https://bugzilla.redhat.com/show_bug.cgi?id=155341 or
http://www.ravenbrook.com/project/p4dti/master/code/replicator/mysqldb_support.py
 

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

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top