[ruby-oci8-devel] About XML DB support in Ruby-OCI8
Liming Lian
liming.lian at oracle.com
Tue Mar 25 23:16:44 EDT 2008
Hi Kubo,
After applying your patch for defining bind type of XMLType, I can
successfully retrieve XML data from db by explicitly defining the select
data as XMLType. Here is code snippet:
## SQLs for defining XMLType table and inserting XML data to the table
CREATE TABLE xml_table (key VARCHAR2(10) PRIMARY KEY, xml_column XMLType);
CREATE DIRECTORY xmldir AS path_to_folder_containing_XML_file;
INSERT INTO xml_table VALUES (1, XMLType(bfilename('XMLDIR', 'mytest.xml'),
nls_charset_id('AL32UTF8')));
## Ruby code for retrieving XML data
conn = OCI8.new(dbuser, dbpass, dbname)
cur = conn.parse('select xml_column from xml_table where key = 1')
cur.define(1, :xmltype)
cur.exec
r = cur.fetch
xml = r[0]
After that, the variable "xml" is a REXML object, so that we can
populate it with standard REXML APIs. It is fine with this kind of
explicitly defining XMLtype while I also find some existed code in
lib/oci8/oci8.rb to deal with XMLType as following:
File: lib/oci8/oci8.rb
Method: make_bind_object
def make_bind_object(param)
case param
when Hash
..........
when OCI8::Metadata::Base
key = param.data_type
case key
when :named_type
if param.type_name == 'XMLTYPE'
key = :xmltype
else
param = @con.get_tdo_by_metadata(param.type_metadata)
end
end
else
.............
I am only familiar with passing Hash parameter to make_bind_object.
Meantime, I notice method make_bind_object also accepts param of
OCI8::Metadata::Base type. I am wondering how to construct such
OCI8::Metadata::Base object so that we can bind or define XMLType in a
manner other than the one I have tried. Any hints? Code sample is
appreciated!
Thanks in advance!
Liming
> Here is a quick fix to fetch XMLTYPE data as REXML objects.
>
> ===================================================================
> --- ext/oci8/xmldb.c (revision 253)
>
More information about the ruby-oci8-devel
mailing list