Module _cubrid :: Class lob
[hide private]
[frames] | no frames]

Class lob

object --+
         |
        lob

Lob class. Process BLOB/CLOB type

Instance Methods [hide private]
 
__init__(...)
x.__init__(...) initializes x; see help(type(x)) for signature
a new object with type S, a subtype of T
__new__(T, S, ...)
 
close()
Close the lob
 
export(file)
export BLOB/CLOB data to the specified file.
 
imports(file, type=...)
imports file in CUBRID server.
 
read(len)
read a chunk of data from the current file position.
 
seek(offset, whence=...)
move the LOB object current position to the direction LOB object according to the mode whence giving.
 
write(string)
writes a string to the large object.If LOB object does not exist.

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(...)
(Constructor)

 

x.__init__(...) initializes x; see help(type(x)) for signature

Overrides: object.__init__

__new__(T, S, ...)

 
Returns: a new object with type S, a subtype of T
Overrides: object.__new__

export(file)

 

export BLOB/CLOB data to the specified file. To use this function, you must use fetch_lob() in cursor class first to get BLOB/CLOB info from CUBRID.

file: string, support filepath/file

Example:

 import _cubrid
 con = _cubrid.connect('CUBRID:localhost:33000:demodb:::', 'public')
 cur = con.cursor()
 cur.prepare('select * from test_lob')
 cur.execute()
 lob = con.lob()
 cur.fetch_lob(1, lob)
 lob.export('out')
 lob.close()
 cur.close()
 con.close()

imports(file, type=...)

 

imports file in CUBRID server. If not give the type, it will be processed as BLOB.

read(len)

 

read a chunk of data from the current file position. If not given the length, it will read all the remaining data.

Return a string that contains the data read.

Example 1:

 import _cubrid
 con = _cubrid.connect('CUBRID:localhost:33000:demodb:::', 'public')
 lob = con.lob()
 lob.imports('README', 'C')
 str = lob.read(32)
 print str
 lob.close()
 con.clsoe()

Example 2:

 import _cubrid
 con = _cubrid.connect('CUBRID:localhost:33000:demodb:::', 'public')
 cur = con.cursor()
 cur.prepare('select * from test_lob')
 cur.execute()
 lob = con.lob()
 cur.fetch_lob(1, lob)
 print lob.read(32)
 lob.close()
 cur.close()
 con.close()

seek(offset, whence=...)

 

move the LOB object current position to the direction LOB object according to the mode whence giving. The argument whence can be the following values:

  • SEKK_SET: means move the cursor based on the original position, offset must be positive number, the cursor will be moved forward offset units relative to the original position.
  • SEEK_CUR: means move the cursor based on the current position. If offset is positive number, means move the cursor forward offset units. If offset is negative number, means move back offset units. This is the default value.
  • SEEK_END: means move the cursor based on the end position, offset must be positive number, the cursor will be moved back offset units relative to the end position.

Return the current position of the cursor.

write(string)

 

writes a string to the large object.If LOB object does not exist. It will be create a BLOB object as default.

Example 1:

 import _cubrid
 con = _cubrid.connect('CUBRID:localhost:33000:demodb:::', 'public')
 cur = con.cursor()
 cur.prepare('insert into test_clob(content) values (?)')
 lob = con.lob()
 content = 'CUBRID is a very powerful RDBMS'
 lob.write(content, 'C')
 cur.bind_lob(1, lob)
 cur.execute()
 lob.close()
 cur.close()
 con.close()

Example 2:

 import _cubrid
 con = _cubrid.connect('CUBRID:localhost:33000:demodb:::', 'public')
 cur = con.cursor()
 cur.prepare('select * from test_blob')
 cur.execute()
 lob = con.lob()
 cur.fetch_lob(1, lob)
 lob.seek(50, SEEK_CUR)
 lob.write('CUBRID a powerfer database')
 lob.close()
 cur.close()
 con.close()