From by.marcis at gmail.com Thu Apr 7 11:46:21 2011 From: by.marcis at gmail.com (MR) Date: Thu, 07 Apr 2011 12:46:21 +0300 Subject: [DB-SIG] 'Accessing the CDF databases through Python' translation Message-ID: <4D9D87ED.4060200@gmail.com> Hi! I'm willing to translate publication located at http://hep.uchicago.edu/cdf/howto/pythondb.html to the Belorussian language (my mother tongue). What I'm asking for is your written permission, so you don't mind after I'll post the translation to my blog. The translation is intended only for web, no print copies planned. Visitors of your website, who come from Minsk (Belorussia) will be the ones, who will read this blogpost, that's the only way to spread them, no additional instruments we can use. Every translation we ever do does not costs a penny for the webpage, which is translated. All we ask is to link back in whatever way you feel confident about it. Thank you for the article. You can leave a voice message and I will call you back, if you prefer a call instead of emails. Sincerely, Bohdan Zograf +(360) 488-0303 From chan.young.kwon at sap.com Wed Apr 27 09:10:50 2011 From: chan.young.kwon at sap.com (Kwon, Chan Young) Date: Wed, 27 Apr 2011 09:10:50 +0200 Subject: [DB-SIG] About LOB Message-ID: Hi, I am implementing new DB API for new Database according to DB API 2.0. (as C-Extension) There is no specification about LOB in DB API 2.0 Especially, I need LOB object for piecewise LOB writing/reading after query execution. So I defined my own LOB object. I tried to make simple and easy interface for LOB. Let me introduce my DB API.(red lines are about LOB handling) This is used in my company. I hope this document and example could help you to define LOB class in NEXT DB API 3.0 SPEC. API Module Interface Attribute Description connect(parameters...) Constructor for creating a connection to the database.Returns a Connection Object. It takes a number of parameters which are database dependent. -Example * dbapi.connect(address='localhost', port=30415, user='system', password='manager') ? common usage LOB() Return LOB type object. Date(year,month,day) Return datetime type object holding a date value. Time(hour,minute,second,millisecond=0) Return datetime type object holding a time value. Timestamp(year,month,day,hour,minute,second,millisecond=0) Return datetime type object holding a date+time value. DateFromTicks(ticks) Return datetime type object holding a date value. TimeFromTicks(ticks) Return datetime type object holding a time value. TimestampFromTicks(ticks) Return datetime type object holding a date+time value. Binary(string) Return an buffer type object holding a binary string value. Exceptions Attribute Description Warning Exception raised for important warnings. Error Exception that is the base class of all other error exceptions. -error information is saved as tuple * errobject[0] ? contains error code * errobject[1] ? contains error message InterfaceError Exception raised for errors that are related to the database interface rather than the database itself. DatabaseError Exception raised for errors that are related to the database. DataError Exception raised for errors that are due to problems with the processed data like division by zero, numeric value out of range, etc. OperationError Exception raised for errors that are related to the database's operation and not necessarily under the control of the programmer, e.g. an unexpected disconnect occurs, the data source name is not found, a transaction could not be processed, a memory allocation error occurred during processing, etc. IntegrityError Exception raised when the relational integrity of the database is affected, e.g. a foreign key check fails. InternalError Exception raised when the database encounters an internal error, e.g. the cursor is not valid anymore, the transaction is out of sync, etc. ProgrammingError Exception raised for programming errors, e.g. table not found or already exists, syntax error in the SQL statement, wrong number of parameters specified, etc. NotSupportedError Exception raised in case a method or database API was used which is not supported by the database, e.g. requesting a .rollback() on a connection that does not support transaction or has transactions turned off. Connection Object Attribute Description close() Close the cursor now (rather than whenever _del_ is called). The cursor will be unusable from this point forward; an Error (or subclass) exception will be raised if any operation is attempted with the cursor. commit() Commit any pending transactions to the database. rollback() Rollback any pending transactions. cursor() Return a new Cursor object using the connection. setautocommit(auto=True) Set auto-commit mode. getautocommit() Get auto-commit mode. cancel() Cancel the running database request that is executed on the connection. isconnected() Return True if the connection is valid(connected to DB). setclientinfo(key, value=None) Set client info. If the value is None, the key is removed. getclientinfo(key=None) Get client info. If the key is None, All key:value sets are returned. Cursor Object Attribute Description description Sequence of column's information; The information contains 7 items : (name, type_code, display_size, internal_size, precision, scale, null_ok). rowcount Updated column count. callproc(procname[,parameters]) Call a stored database procedure with the given name. close() Close the cursor now. nextset() Skip to the next result set, closing current result set. (for multiple resultsets) execute(operation[,parameters]) Prepare and execute a database operation (query or command). -Steps included 1. prepare operation(statement) 2. bind paramters 3. execute prepared-statement executemany(operation,seq_of_parameters) Prepare a database operation (query or command) and then execute it against all parameter sequences or mappings found in the sequence seq_of_parameters. fetchone(uselob=False) Fetch the next row of a query result set, returning a single sequence, or None when no more data is available. fetchmany([size=cursor.arraysize]) Fetch the next set of rows of a query result, returning a sequence of sequences (e.g. a list of tuples). An empty sequence is returned when no more rows are available. fetchall() Fetch all (remaining) rows of a query result, returning them as a sequence of sequences (e.g. a list of tuples). Note that the cursor's arraysize attribute can affect the performance of this operation. LOB Object Attribute Description read(size[,position]) Return a portion (or all) of the data in the LOB object write(data) Write the data to the LOB object close() Close the LOB object Source code sample def test_LobInsertWithPieceWiseLOB(self): """Piece-wise LOB INSERT""" old_mode = self.conn.getautocommit() self.conn.setautocommit(False) cur = self.conn.cursor() try: cur.execute("DROP TABLE PIECEWISE_LOB_TEST") except dbapi.Error, err: pass cur.execute("CREATE ROW TABLE PIECEWISE_LOB_TEST (key int, blob BLOB, clob CLOB, nclob NCLOB)") blob = dbapi.LOB() try: blob.read() except dbapi.Error, err: print err clob = dbapi.LOB() nclob = dbapi.LOB() cur.execute("INSERT INTO PIECEWISE_LOB_TEST VALUES (?,?,?,?)", (1, blob, clob, nclob)) blob.write(data = "blob"*1024) blob.write("2blob"*512) blob.write(u"UNICODE"*32) blob.close() clob.write("clob"*1024) clob.write(buffer("binary"*32)) clob.write(u"UNICODE"*32) clob.write(None) clob.close() chanyoung = codecs.utf_8_decode("\xEC\xB0\xAC")[0] + u"YOUNG" nclob.write(u"CHANYOUNG's UNICODE") nclob.write(chanyoung*256) nclob.close() self.conn.commit() cur.execute('select key, blob, clob, nclob from PIECEWISE_LOB_TEST') r = cur.fetchone(True) # uselob == True for c in r: if isinstance(c,dbapi.LOB) : c.read(0) c.read() c.read(999999999, 1) c.read(size=10,position=1) c.read(size=4,position=1) while True: data = c.read(1000) if data is None: break else: #print data, pass else: #print c pass cur.execute('select nclob from PIECEWISE_LOB_TEST') row = cur.fetchone() self.assertEqual(u"CHANYOUNG's UNICODE" + chanyoung*256, row[0]) try: cur.execute("DROP TABLE PIECEWISE_LOB_TEST") except dbapi.Error, err: Best wishes, Chanyoung Kwon SAP R&D Center Korea From vernondcole at gmail.com Wed Apr 27 13:58:24 2011 From: vernondcole at gmail.com (Vernon Cole) Date: Wed, 27 Apr 2011 05:58:24 -0600 Subject: [DB-SIG] About LOB In-Reply-To: References: Message-ID: Chan: [I hope I picked your familiar name? If not, please correct.] I think that you have started not one, but two excellent projects. I am excited by your post, and hope that both have a happy ending. (Will explain later, hard to type on this thing) Don't let what I am about to ask make you think you have a bad idea. Our industry is plagued by rampant TLA usage. Often, a single TLA is used for several different concepts. Before using a TLA or EMLA in a paper or conversation, we should make sure we have defined our TLA in English. For example is SMB Service Message Block, or Small and Medium Business? [TLA here means "Three Letter Acronym", EMLA is Extended Multi-Letter Acronym.] Please define precisely what LOB support should mean. -- Vernon (sent from my 'droid phone) -------------- next part -------------- An HTML attachment was scrubbed... URL: From Chris.Clark at ingres.com Wed Apr 27 19:05:25 2011 From: Chris.Clark at ingres.com (Chris Clark) Date: Wed, 27 Apr 2011 10:05:25 -0700 Subject: [DB-SIG] About LOB In-Reply-To: References: Message-ID: <4DB84CD5.1090807@ingres.com> Kwon, Chan Young wrote: > I am implementing new DB API for new Database according to DB API 2.0. (as C-Extension) > There is no specification about LOB in DB API 2.0 > Especially, I need LOB object for piecewise LOB writing/reading after query execution. > So I defined my own LOB object. > I tried to make simple and easy interface for LOB. > BLarge OBject's (BLOBs) are alluded to in pep 249 BUT they really are not detailed so I think you have spotted a weakness in the spec. CLOBs (Character Large OBjects) are not covered at all. Locators are not discussed but implied by references to bufferobjects. For BLOBs as input bind parameters check out the Binary() constructor (case sensitive) at http://www.python.org/dev/peps/pep-0249/. For BLOB results look for bufferobject in http://www.python.org/dev/peps/pep-0249/ The spec (as I read it) really expects LOBs to be handled as one massive block. However implementators can choose to implement locators behind the scene so that data isn't sent across the wire unless the buffer object is read from. So, model your LOB access methods on bufferobjects and you should be all set! Marc-Andre reads/responds to the list regularly so take note of any suggestions he has :-) Hope that helps get you started. Chris From chan.young.kwon at sap.com Thu Apr 28 04:14:45 2011 From: chan.young.kwon at sap.com (Kwon, Chan Young) Date: Thu, 28 Apr 2011 04:14:45 +0200 Subject: [DB-SIG] About LOB In-Reply-To: <4DB84CD5.1090807@ingres.com> References: <4DB84CD5.1090807@ingres.com> Message-ID: Hi, Let me describe more... 1. My suggestion of LOB object is kind of Locator object. It does not contain whole massive data. It just passes small piece of data when its methods are called. 2. buffer object is not enough to handle various kinds of LOB types. For example, character LOB, binary LOB and unicode character LOB. In my company, this LOB class is already used as extension of DBAPI spec 2.0. All colleagues like LOB class because it is very simple and easy to use. So I sent this for your information. Best wishes, Chanyoung Kwon SAP R&D Center Korea -----Original Message----- From: Chris Clark [mailto:Chris.Clark at ingres.com] Sent: Thursday, April 28, 2011 2:05 AM To: Kwon, Chan Young Cc: db-sig at python.org Subject: Re: [DB-SIG] About LOB Kwon, Chan Young wrote: > I am implementing new DB API for new Database according to DB API 2.0. (as C-Extension) > There is no specification about LOB in DB API 2.0 > Especially, I need LOB object for piecewise LOB writing/reading after query execution. > So I defined my own LOB object. > I tried to make simple and easy interface for LOB. > BLarge OBject's (BLOBs) are alluded to in pep 249 BUT they really are not detailed so I think you have spotted a weakness in the spec. CLOBs (Character Large OBjects) are not covered at all. Locators are not discussed but implied by references to bufferobjects. For BLOBs as input bind parameters check out the Binary() constructor (case sensitive) at http://www.python.org/dev/peps/pep-0249/. For BLOB results look for bufferobject in http://www.python.org/dev/peps/pep-0249/ The spec (as I read it) really expects LOBs to be handled as one massive block. However implementators can choose to implement locators behind the scene so that data isn't sent across the wire unless the buffer object is read from. So, model your LOB access methods on bufferobjects and you should be all set! Marc-Andre reads/responds to the list regularly so take note of any suggestions he has :-) Hope that helps get you started. Chris