From: Nidositko, J. <Jam...@gs...> - 2005-10-27 07:17:15
|
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: pyt...@ww... [mailto:pyt...@ww...] On Behalf Of pyt...@ww... Sent: Tuesday, October 25, 2005 10:00 PM To: pyt...@ww... 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 <mik...@gm...> Subject: [python-sybase] how to get return value of update/delete statement To: Python Sybase <pyt...@ww...> Message-ID: <e32...@ma...> 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 Pyt...@ww... https://www.object-craft.com.au/cgi-bin/mailman/listinfo/python-sybase End of Python-sybase Digest, Vol 5, Issue 3 ******************************************* |
From: Nidositko, J. <Jam...@gs...> - 2005-10-27 08:46:39
|
Mistakenly sent last reply to list as HTML. Repeated here: Mike, I had some discussions earlier this year with Dave about fixing the rowcount stuff in the recent versions of the Sybase module (0.36 and 0.37). I was under the impression that these fixes had been incorporated and released, but I did not check that before responding to your question. Sorry for the confusion. The last official version that I know of where rowcount() worked was 0.36-pre2. There were extensive changes to the structure of the code between that version and the actual 0.36 release. The rowcount problems were introduced by some of those changes and carried forward into 0.37. I'm assuming that you're using 0.37. The attached copy of Sybase.py fixes the rowcount issues. It is based on the version released with 0.37. Dave, any chance of getting an official release with rowcount() working? -Jim |
From: mike <mik...@gm...> - 2005-10-27 19:07:19
|
hi ok i have retried, redownload sybase-037, recompile and retested , but it still gives me -1 as a workaround, i will just do a check on the "user" criteria as well as check for existence of the table to be updated before i actually do the update. This way i can more or less be sure that it will definitely update. thanks again On 10/26/05, Nidositko, James <Jam...@gs...> wrote: > > > Mistakenly sent last reply to list as HTML. Repeated here: > > > Mike, > I had some discussions earlier this year with Dave about fixing the > rowcount stuff in the recent versions of the Sybase module (0.36 and 0.37 > ). > I was under the impression that these fixes had been incorporated and > released, but I did not check that before responding to your question. > Sorry for the confusion. > > The last official version that I know of where rowcount() worked was > 0.36-pre2. There were extensive changes to the structure of the code > between that version and the actual 0.36 release. The rowcount problems > were introduced by some of those changes and carried forward into 0.37. > > I'm assuming that you're using 0.37. > > The attached copy of Sybase.py fixes the rowcount issues. It is > based on the version released with 0.37. > > Dave, any chance of getting an official release with rowcount() > working? > > -Jim > > _______________________________________________ > Python-sybase mailing list > Pyt...@ww... > https://www.object-craft.com.au/cgi-bin/mailman/listinfo/python-sybase > |
From: mike <mik...@gm...> - 2005-10-27 07:56:02
|
hi thanks for the reply. I went to try the codes out def exec_updtstmt(Svr,Login,Pass,Db,SQL): ''' Connects to database specified, exec the SQL and returns value''' try: db =3D Sybase.connect(Svr, Login,Pass ,Db) c =3D db.cursor() try: c.execute(SQL) print "Cursor rowcount after update (no rows) is: %d" % c.rowcount db.commit() db.close() except Sybase.DatabaseError: return 9 except: return 2 stmt =3D ''' update table set col_1 =3D 1 where login =3D "user" ''' exec_updtstmt(Svr,Login,Pass,DbInt,stmt) what i got is "Cursor rowcount after update (no rows) is: -1" and when i checked the table it is updated. Although the update works, i would wish to get that return t= o indicate to the user whether success or failure . thanks for any further help On 10/26/05, Nidositko, James <Jam...@gs...> wrote: > > > 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=3Ddbc.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 =3D 'qwer' where col1 =3D 'asd= f'") > print "Cursor rowcount after update is: %d" % c.rowcount > > c.execute("update __test_rowcount set col1 =3D 'qwer' where col1 =3D '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 =3D '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: pyt...@ww... > [mailto:pyt...@ww...] On Behalf Of > pyt...@ww... > Sent: Tuesday, October 25, 2005 10:00 PM > To: pyt...@ww... > 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 <mik...@gm...> > Subject: [python-sybase] how to get return value of update/delete > statement > To: Python Sybase <pyt...@ww...> > Message-ID: > <e32...@ma...> > Content-Type: text/plain; charset=3D"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 =3D a-value where name =3D > '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/200510= 25/ > 0c35109c/attachment-0001.html > > ------------------------------ > > _______________________________________________ > Python-sybase mailing list > Pyt...@ww... > https://www.object-craft.com.au/cgi-bin/mailman/listinfo/python-sybase > > > End of Python-sybase Digest, Vol 5, Issue 3 > ******************************************* > |