OCI8::BLOB

This is a lob locator to read/write binary data to/from BLOB column. This instance is automatically generated by select statement.

Class Methods

OCI8::BLOB.new(con, val)

(new in 1.0.0-rc2)

create a temporary lob. "temporary" means "which is not stored to a database." You can store your data to a temporary lob and insert it to a table.

Instance Methods

available?

check whether BLOB is available or not. To use BLOB you need to insert EMPTY_BLOB() at first.

 conn.exec("CREATE TABLE photo (name VARCHAR2(50), image BLOB)")
 conn.exec("INSERT INTO photo VALUES ('null-data', NULL)")
 conn.exec("INSERT INTO photo VALUES ('empty-data', EMPTY_BLOB())")
 conn.exec("SELECT name, image FROM photo") do |name, image|
   case name
   when 'null-data'
     puts "#{name} => #{image.available?.to_s}"
     # => false
   when 'empty-data'
     puts "#{name} => #{image.available?.to_s}"
     # => true
   end
 end

read(size = nil)

read at most size bytes from BLOB, or to the end of file if size is omitted.

 conn.exec("SELECT name, image FROM photo") do |name, image|
   File.open(name, 'w') do |f|
     f.write(image.read)
   end
 end

write(string)

write the given string to BLOB. If old data is longer than new data, resize by OCI8::BLOB#size.

 conn.exec("SELECT name, image FROM photo") do |name, image|
   File.open(name, 'r') do |f|
     image.write(f.read)
     image.size = f.pos
   end
 end

size

return the size of BLOB.

size=(len)

set the size of BLOB.

pos

return the current offset of BLOB.

pos = number

set the current offset of BLOB.

eof?

true if the current offset is at the end of the BLOB.

chunk_size

return the chunk size of BLOB.

truncate(len)

synonym for size=.

tell

synonym for pos.

seek(pos)

synonym for pos=.

rewind

set the current offset to zero.

Last modified:2007/11/23 22:20:14
Keyword(s):
References:[SideMenu] [ruby-oci8 API]