[PYTHON DB-SIG] API conformant sybase module
Thu, 9 Jan 1997 09:02:22 +0100
I just don't see the point of having a method that renders an object
completely useless, but keeps it around.
I see your point. However, one may wish to make the connection unusable BUT
cannot control the invokation of __del__ just by killing the object reference
since there may be others lingering. I have encountered exactly this problem
where Python kept a reference after an exception and the __del__ method did
not execute when I hoped for it. There are other similar situations.
Sorry, but I still don't get it. Looking at the spec again, I may be missing
something significant. I was assuming that the 'operation' arguement to
execute is a string of arbitrary SQL. If this is the case, then I don't see
any role for the 'params'. I also don't see any benefit to storing the string.
I must be missing something, somebody please help ! A python code example
would be very useful here.
Of course, you can always construct a complete sql string but that less efficient
in case you wish to do the same operation many times with new data. In this case
the implementation can keep a record of the latest PREPAREd string and reuse the
previous PREPARE result until a new string is supplied, saves time. Also, I like
to be able to use data without being forced to convert into string format.
In Tcl this is all the same but not in Python.
Further, if I need to insert a BLOB (Binary Large OBject), I *require* the
As an example of how I typically use the execute method:
Python 1.4 (Nov 4 1996) [GCC 184.108.40.206]
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> import os, sys, informixdb
>>> db = informixdb.informixdb("mydatabase@myserver")
>>> c = db.cursor()
>>> some_image_id = 72
>>> c.execute("select * from image where image_id = ?", (some_image_id,))
[('image_id', 'NUMBER', 4, 4, 0, 0, 1),
('locked_by', 'STRING', 16, 16, 0, 0, 1),
('locked_at', 'DATE', 3080, 3080, 0, 0, 1),
('img_state', 'STRING', 1, 1, 0, 0, 1),
('copy_of', 'NUMBER', 4, 4, 0, 0, 1)]
>>> aRow = c.fetchone()
(72L, '', <DbiDate object at 9b3c8>, 'P', 0)
Hope this illuminates somewhat.
> 4) I assume that its ok to add methods, but what would
people think about > having settable attributes (eg. for
the database or the connection info) ? What do you have
in mind ?
Currently I can do things like:
>>> syb1 = Sybase(user = 'ted', server = 'local', database = 'emp',
... password = 'haha', interface = '/usr/sybase/interfaces')
Yes, this is nice. Can you provide a list keywords you have found useful
and describe the semantics ?
>>> syb1.sql('select * from employee')
[<Result instance at 165b74, 1629 rows, 10 columns>]
>>> syb1.database = 'acct'
Ehrr, should one not simply create a new database object here ?
>>> syb1.sql('select * from accounts')
[<Result instance at 16ab8c, 157 rows, 3 columns>]
>>> syb1.user = 'guest'
>>> syb1.database = 'cat'
>>> syb1.sql('select * from catalog')
[<Result instance at 15732c, 210 rows, 17 columns>]
Hmm, and here ?
It seems like a matter of style but I feel that this is not really the I
like to use objects.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Bertil Reinhammar IV DocEye AB (Combitech)
phn. +46 13 200606 Teknikringen 9
fax. +46 13 214897 S-58330 Linköping
DB-SIG - SIG on Tabular Databases in Python
send messages to: firstname.lastname@example.org
administrivia to: email@example.com