how to return correct value of update stmt

E

eight02645999

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
 
S

Steve Holden

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
 
E

eight02645999

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
 

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,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top