------ art_29327_11472508.1137553896921 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Sorry, saw "long", thought "lob". The problem is that there's a default buffer size for working with longs/lobs that you have to reset to a value that's appropriate for your data. In perl DBI there's a LongReadLength attribute, and it looks like there's something similar for oci8 via the "low level" interface (maybe OCI_ATTR_MAXDATA_SIZE). But there doesn't appear to be a way to set OCI attributes from the "high level" interface, unless I'm missing something. Which is likely... On 1/17/06, Gennady Bystritsky <Gennady.Bystritsky / quest.com> wrote: > > Thank you very much, Neil. I saw blob support in OCI8, however I need to > work with datatype 'long'. I need to for dealing with a legacy database > that cannot be altered in any way. Will OCI8 work on 'long' columns? I > will definitelly try, however I doubt it. > > Thanks a lot anyways, > Gennady. > > -----Original Message----- > From: Neil Kohl [mailto:nakohl / gmail.com] > Sent: Tuesday, January 17, 2006 12:14 > To: ruby-talk ML > Subject: Re: Populating 'long' data column with Ruby OCI8 (trying again, > need a solution badly) > > On 1/17/06, Gennady Bystritsky <Gennady.Bystritsky / quest.com> wrote: > > > Is there any way to insert a big chunk of data (say, 100K) into a > > column of type long with Ruby OCI8 or by any other Ruby means? > > You need to do it in chunks. See documentation for OCI8::BLOB#write(). > Here's an example that works for me loading data from a file. You'll > need to adapt to load from a variable. > > require 'oci8' > > conn = OCI8.new(user, passwd, sid) > > # test.txt is a file that's > 100K > name = "test.txt" > > # create the row with an empty blob > cursor = conn.parse("INSERT INTO nkrb_test (name, data) VALUES(:name, > EMPTY_BLOB())") > cursor.exec(name) > > # now load blob column with file contents conn.exec("SELECT name, data > FROM nkrb_test") do |name, data| > chunk_size = data.chunk_size > File.open(name, 'r') do |f| > until f.eof? > data.write(f.read(chunk_size)) > end > data.size = f.pos > end > end > conn.commit > > Schema for nkrb_test is: > > create table nkrb_test ( > id INT, > name VARCHAR(255), > data BLOB, > CONSTRAINT nkrb_test_pk PRIMARY KEY (id) ); > > > UPDATE: It is not possible to read (with OCI8) columns of type long if > > > they contain large data chunks (100K). Reported error is: > > `fetch': ORA-01406: fetched column value was truncated > > Try setting OCI8::BLOB#truncate() to longer than the longest data you > expect to see in a row, or use OCI8::BLOB#read() to read row data in > chunks -- again see docs for example. > > If you haven't figured it out yet already, LOBs are a real pain to deal > with. > > -- > Neil Kohl > nakohl / gmail.com > > > -- Neil Kohl nakohl / gmail.com ------ art_29327_11472508.1137553896921--