From: Dave C. <dj...@ob...> - 2002-10-21 07:45:41
|
De> dear all: the Fearless (and Clueless) Python Newbie here trying to De> understand the sybase module :-) Dave Cole very kindly helped me De> to identify the source of the segv. looks like libct is a bit De> more temperamental than the libsybdb that I'm used to: it gets De> upset if the locale in LANG envar isn't in locales.dat, in the De> block for your OS. segv seems like a rather extreme response to De> this condition, but that's Sybase's problem :-) We all just have to suffer :-) De> am starting to get my bearings, have figured out where col De> names/types are stashed (c.description) after execution of a De> query. De> De> but now am puzzled because I got a rowcount of -1 when I expected De> to get a rowcount of <number of rows returned>. here's the De> braindead code. As far as I know the row count is only available from the Sybase CT library once all of the results have been consumed. The relevant line of code from Sybase.py is: status, self.rowcount = self._cmd.ct_res_info(CS_ROW_COUNT) You could play around with this by moving the call to ct_res_info() to different places in the code. I seem to remember trying this without success. It would be nice to be able to have the row count immediately though. De> c.execute('select * from numbers order by tablename') De> print c.description De> a = [] De> for item in c.description: De> a.append(item[0]) De> print "COL NAMES:",a De> print c.rowcount," ROWS" De> for row in c.fetchall(): De> print row De> De> python test.py De> [('tablename', 0, 0, 30, 0, 0, 0), ('nserial', 8, 0, 4, 0, 0, 0), ('uid', 7, 0, 2, 0, 0, 32), ('stamp', 13, 0, 4, 0, 0, 32)] De> COL NAMES: ['tablename', 'nserial', 'uid', 'stamp'] De> -1 ROWS De> ('Agents', 200, 1, '25/07/96') De> ('Alarms', 1, 1, '28/04/97') De> ... De> currentThread(): no current thread for 1024 De> De> why do I get -1 rows? the dbapi doco says this value is -1 when De> no command has been executed; but as you see, a SQL command has De> been executed and rows are being returned. am I missing De> something? If someone could work out how to get the row count before fetching the results could they please tell me? It also worried me when I wrote the code. De> also as you see I keep getting this "no current thread" message. De> it seems harmless (like a bogus condition on image rundown) but I De> wish I knew what it meant. Copied and slightly edited from another message...: Looks like my lock management code in the Cursor destructor is not working. This is something which drove me crazy - I could not understand how else to solve the problem. The TDS protocol does not allow multiple queries to be in flight over the same connection. To "hide" this limitation I lock the connection whenever a cursor performs a query. This allows you to share connections between threads if you want to. The __del__() method of the cursor makes sure that it releases any lock it has on the Connection object. When a program terminates the Python interpreter deletes all objects (calling the __del__() method if it is defined) which still exist. I discovered that the thread object in which a Connection lock was created would sometimes be deleted before the cursor object which still held a lock in that thread. The code in the __del__() method attempts to move the lock to the current thread so it can be unlocked. It seems to be not working for you. The error message should not be there. It is either a bug in my code, or a bug in the threading module which comes with the Python you are running. If I was to place a bet, I would say that the bug is in my code. - Dave -- http://www.object-craft.com.au |