[DB-SIG] About LOB

Kwon, Chan Young chan.young.kwon at sap.com
Tue May 3 09:09:29 CEST 2011


*       LOB
o       read(size[,position])
o       write(data[,position])
o       find(data[,position])



Best wishes,
Chanyoung Kwon

SAP R&D Center Korea



_____________________________________________
From: Kwon, Chan Young
Sent: Tuesday, May 03, 2011 3:45 PM
To: 'M.-A. Lemburg'
Cc: Chris Clark; db-sig at python.org
Subject: RE: [DB-SIG] About LOB


Hi Lemburg,

There is no documentation on the web open to external access.
Our new DB project is little bit confidential.

I can just send you a copy of wiki page inside my company's intranet.
My LOB is also file-like object.
So it has just two interfaces.
One is read()
The other is write()
Different from JDBC, this python LOB object does not need different functions for UNICODE,STRING and BINARY.
Inside read/write function, there must be some routine for various input data type.

In my humble opinion, LOB object’s extension should be like this.

*       LOB
o       read(data[,position])
o       write(data[,position])
o       find(data[,position])

Here is my DB API’s documentation inside intranet of my company.

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


Best wishes,
Chanyoung Kwon

SAP R&D Center Korea



-----Original Message-----
From: M.-A. Lemburg [mailto:mal at egenix.com]
Sent: Monday, May 02, 2011 8:39 PM
To: Kwon, Chan Young
Cc: Chris Clark; db-sig at python.org
Subject: Re: [DB-SIG] About LOB

Kwon, Chan Young wrote:
> 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.

There are various ways large binary/text objects are handled by
databases at the API level.

Some databases provide APIs which allow reading/writing such
data in chunks, others provide file descriptors which can be use
used for this, yet others maintain the files outside the database
and provide "locator" objects for these.

Since all of these approaches use a file-like interface in one
way or another, perhaps we could agree on a common DB-API extension
that defines the minimum interface of such objects and a constructor
that turns an existing file into an object which can then be passed
to the database (much like the Binary() constructor we have for
binary data).

Do you have documentation for the LOB object you are using available
on the web ?

Regards,
--
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, May 02 2011)
>>> Python/Zope Consulting and Support ...        http://www.egenix.com/
>>> mxODBC.Zope.Database.Adapter ...             http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ...        http://python.egenix.com/
________________________________________________________________________
2011-06-20: EuroPython 2011, Florence, Italy               49 days to go

::: Try our new mxODBC.Connect Python Database Interface for free ! ::::


   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
    D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
           Registered at Amtsgericht Duesseldorf: HRB 46611
               http://www.egenix.com/company/contact/


> 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
>
> _______________________________________________
> DB-SIG maillist  -  DB-SIG at python.org
> http://mail.python.org/mailman/listinfo/db-sig




More information about the DB-SIG mailing list