By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,742 Members | 1,224 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,742 IT Pros & Developers. It's quick & easy.

how to return correct value of update stmt

P: n/a
hi
i use odbc to update a table in a database but i always get return
value of -1
even though i tried to return an integer. the table is updated though
....
sql = """
update table
set column = 0
where col = "%s"
select @@rowcount

""" % (var1)
.....
try:
s = odbc.odbc(connectstring)
cur = s.cursor()
res = cur.execute(sql)
s.commit()
s.close()
cur.close()
s = None
cur = None
print res
return res
except:
print 'error while processing ', sys.exc_type,sys.exc_value
how to properly get a positive return ?
thanks

Oct 19 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
ei***********@yahoo.com wrote:
hi
i use odbc to update a table in a database but i always get return
value of -1
even though i tried to return an integer. the table is updated though
...
sql = """
update table
set column = 0
where col = "%s"
select @@rowcount

""" % (var1)
....
try:
s = odbc.odbc(connectstring)
cur = s.cursor()
res = cur.execute(sql)
s.commit()
s.close()
cur.close()
s = None
cur = None
print res
return res
except:
print 'error while processing ', sys.exc_type,sys.exc_value
how to properly get a positive return ?
thanks

Is the table actually being updated?

The definition of the cursor.execute() method in

http://www.python.org/peps/pep-0249.html

specifically says "Return values are not defined". So if you are seeing
the database do the right thing I'd stop worrying about the return
value. If exceptions aren't being raised and the database is doing what
you want, what's the problem?

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006 www.python.org/pycon/

Oct 19 '05 #2

P: n/a
hi
yes , the table is updated. Just feels "uncomfortable" with the return
of -1.
was also concerned that what if the actual table doesn't exist, will it
return -1?
anyway, i will go check it out ..
thanks

Oct 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.