[python-sybase] how to get return value of update/delete

Nidositko, James James.Nidositko at gs.com
Thu Oct 27 00:16:43 EST 2005


Mike, 
There is no inherent concept of a "return value" from an executed SQL
statement.  You can produce such a result by encapsulating your SQL
statements within stored procedures by detecting the rowcount and setting
the return value in response, but there isn't really any need for you to do
that.

1) It sounds like the error case that you're trying to describe below should
be detected by getting a rowcount of zero from the update.

2)  Rowcount does work.  Here is some sample code that will show rowcount
working in various situations.  

  c=dbc.cursor()
  print "Cursor rowcount is initialized to: %d" % c.rowcount
  c.execute("create table __test_rowcount (col1 varchar(10) NULL)")
  print "Cursor rowcount after create table is: %d" % c.rowcount

  c.execute("insert __test_rowcount (col1) values ('asdf')")
  print "Cursor rowcount after insert 1 is: %d" % c.rowcount

  c.execute("insert __test_rowcount (col1) values ('asdf')")
  print "Cursor rowcount after insert 2 is: %d" % c.rowcount

  c.execute("update __test_rowcount set col1 = 'qwer' where col1 = 'asdf'")
  print "Cursor rowcount after update is: %d" % c.rowcount

  c.execute("update __test_rowcount set col1 = 'qwer' where col1 = 'not
there'")
  print "Cursor rowcount after update (no rows) is: %d" % c.rowcount

  c.execute("select count(*) from  __test_rowcount")
  print "Cursor rowcount after execute for select is: %d" % c.rowcount
  c.fetchall()
  print "Cursor rowcount after fetch for select is: %d" % c.rowcount

  c.execute("delete __test_rowcount where col1 = 'qwer'")
  print "Cursor rowcount after delete is: %d" % c.rowcount

The only unusual case is select.  Then, the rowcount is not set until the
fetch is performed.

-Jim

-----Original Message-----
From: python-sybase-bounces at www.object-craft.com.au
[mailto:python-sybase-bounces at www.object-craft.com.au] On Behalf Of
python-sybase-request at www.object-craft.com.au
Sent: Tuesday, October 25, 2005 10:00 PM
To: python-sybase at www.object-craft.com.au
Subject: Python-sybase Digest, Vol 5, Issue 3


Today's Topics:

   1. how to get return value of update/delete statement (michael lee)


----------------------------------------------------------------------

Message: 1
Date: Tue, 25 Oct 2005 18:30:07 +0800
From: michael lee <mik3l3374 at gmail.com>
Subject: [python-sybase] how to get return value of update/delete
	statement
To: Python Sybase <python-sybase at www.object-craft.com.au>
Message-ID:
	<e3202a160510250330t7306ecd6p79b4517d42e5bc2c at mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

hi
how can i successfully get the return of an update or delete statement using
the Sybase module?
 i am doing a CGI script whereby if a user keys in the wrong name, i would
want to catch that error  eg if key in wrong username, my CGI script will
call Sybase to execute < update table set this = a-value where name =
'wronguser' > and then return a value indicating "not found"
but i am not able to figure out how to catch this return value. Any advise?
 ....
cur.execute(update_statement)
....
 my table is being updated though when i tried a valid user. I tried
rowcount but also not working.
thanks
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://www.object-craft.com.au/pipermail/python-sybase/attachments/20051025/
0c35109c/attachment-0001.html

------------------------------

_______________________________________________
Python-sybase mailing list
Python-sybase at www.object-craft.com.au
https://www.object-craft.com.au/cgi-bin/mailman/listinfo/python-sybase


End of Python-sybase Digest, Vol 5, Issue 3
*******************************************


More information about the Python-sybase mailing list