ruby-oci8 1.0.7 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (89) hide show
  1. data/ChangeLog +1254 -390
  2. data/Makefile +10 -13
  3. data/README +56 -385
  4. data/VERSION +1 -1
  5. data/dist-files +26 -27
  6. data/ext/oci8/.document +1 -0
  7. data/ext/oci8/MANIFEST +0 -4
  8. data/ext/oci8/apiwrap.c.tmpl +172 -0
  9. data/ext/oci8/apiwrap.h.tmpl +61 -0
  10. data/ext/oci8/apiwrap.rb +91 -0
  11. data/ext/oci8/apiwrap.yml +1243 -0
  12. data/ext/oci8/attr.c +124 -384
  13. data/ext/oci8/bind.c +472 -164
  14. data/ext/oci8/encoding.c +196 -0
  15. data/ext/oci8/env.c +84 -253
  16. data/ext/oci8/error.c +196 -127
  17. data/ext/oci8/extconf.rb +82 -59
  18. data/ext/oci8/lob.c +710 -370
  19. data/ext/oci8/metadata.c +359 -0
  20. data/ext/oci8/object.c +622 -0
  21. data/ext/oci8/oci8.c +577 -161
  22. data/ext/oci8/oci8.h +354 -258
  23. data/ext/oci8/oci8lib.c +493 -0
  24. data/ext/oci8/ocidatetime.c +473 -0
  25. data/ext/oci8/ocinumber.c +1123 -24
  26. data/ext/oci8/oraconf.rb +72 -106
  27. data/ext/oci8/oradate.c +511 -321
  28. data/ext/oci8/stmt.c +752 -572
  29. data/ext/oci8/win32.c +131 -0
  30. data/ext/oci8/xmldb.c +383 -0
  31. data/lib/.document +2 -0
  32. data/lib/dbd/OCI8.rb +2 -17
  33. data/lib/oci8.rb.in +41 -1622
  34. data/lib/oci8/.document +5 -0
  35. data/lib/oci8/compat.rb +108 -0
  36. data/lib/oci8/datetime.rb +489 -0
  37. data/lib/oci8/encoding-init.rb +40 -0
  38. data/lib/oci8/encoding.yml +537 -0
  39. data/lib/oci8/metadata.rb +2077 -0
  40. data/lib/oci8/object.rb +548 -0
  41. data/lib/oci8/oci8.rb +773 -0
  42. data/lib/oci8/oracle_version.rb +144 -0
  43. data/metaconfig +3 -3
  44. data/ruby-oci8.gemspec +5 -5
  45. data/setup.rb +4 -4
  46. data/test/config.rb +64 -84
  47. data/test/test_all.rb +14 -21
  48. data/test/test_array_dml.rb +317 -0
  49. data/test/test_bind_raw.rb +18 -25
  50. data/test/test_bind_time.rb +78 -91
  51. data/test/test_break.rb +37 -35
  52. data/test/test_clob.rb +33 -89
  53. data/test/test_connstr.rb +5 -4
  54. data/test/test_datetime.rb +469 -0
  55. data/test/test_dbi.rb +99 -60
  56. data/test/test_dbi_clob.rb +3 -8
  57. data/test/test_metadata.rb +65 -51
  58. data/test/test_oci8.rb +151 -55
  59. data/test/test_oracle_version.rb +70 -0
  60. data/test/test_oradate.rb +76 -83
  61. data/test/test_oranumber.rb +405 -71
  62. data/test/test_rowid.rb +6 -11
  63. metadata +31 -32
  64. data/NEWS +0 -420
  65. data/ext/oci8/const.c +0 -165
  66. data/ext/oci8/define.c +0 -53
  67. data/ext/oci8/describe.c +0 -81
  68. data/ext/oci8/descriptor.c +0 -39
  69. data/ext/oci8/handle.c +0 -273
  70. data/ext/oci8/oranumber.c +0 -445
  71. data/ext/oci8/param.c +0 -37
  72. data/ext/oci8/server.c +0 -182
  73. data/ext/oci8/session.c +0 -99
  74. data/ext/oci8/svcctx.c +0 -238
  75. data/ruby-oci8.spec +0 -62
  76. data/support/README +0 -4
  77. data/support/runit/assert.rb +0 -281
  78. data/support/runit/cui/testrunner.rb +0 -101
  79. data/support/runit/error.rb +0 -4
  80. data/support/runit/method_mappable.rb +0 -20
  81. data/support/runit/robserver.rb +0 -25
  82. data/support/runit/setuppable.rb +0 -15
  83. data/support/runit/teardownable.rb +0 -16
  84. data/support/runit/testcase.rb +0 -113
  85. data/support/runit/testfailure.rb +0 -25
  86. data/support/runit/testresult.rb +0 -121
  87. data/support/runit/testsuite.rb +0 -43
  88. data/support/runit/version.rb +0 -3
  89. data/test/test_describe.rb +0 -137
@@ -0,0 +1,131 @@
1
+ /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
2
+ /*
3
+ win32.c - part of ruby-oci8
4
+
5
+ Copyright (C) 2009 KUBO Takehiro <kubo@jiubao.org>
6
+ */
7
+ #include "oci8.h"
8
+ #include <windows.h>
9
+
10
+ NORETURN(static void raise_error(void));
11
+
12
+ static void raise_error(void)
13
+ {
14
+ char msg[1024];
15
+ int err = GetLastError();
16
+ char *p;
17
+
18
+ sprintf(msg, "%d: ", err);
19
+ FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
20
+ NULL, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
21
+ msg + strlen(msg), sizeof(msg) - strlen(msg), NULL);
22
+ for (p = msg; *p != '\0'; p++) {
23
+ if (*p == '\n' || *p == '\r') {
24
+ *p = ' ';
25
+ }
26
+ }
27
+ rb_raise(rb_eRuntimeError, "%s", msg);
28
+ }
29
+
30
+ static VALUE dll_path(VALUE module)
31
+ {
32
+ HMODULE hModule;
33
+ DWORD len;
34
+ char path[1024];
35
+
36
+ hModule = GetModuleHandle("OCI.DLL");
37
+ if (hModule == NULL) {
38
+ raise_error();
39
+ }
40
+ len = GetModuleFileName(hModule, path, sizeof(path));
41
+ if (len == 0) {
42
+ raise_error();
43
+ }
44
+ return rb_external_str_new_with_enc(path, len, rb_filesystem_encoding());
45
+ }
46
+
47
+
48
+ typedef struct {
49
+ HKEY hKey;
50
+ HKEY hSubKey;
51
+ } enum_homes_arg_t;
52
+
53
+ static VALUE enum_homes_real(enum_homes_arg_t *arg)
54
+ {
55
+ LONG rv;
56
+ DWORD type;
57
+ DWORD idx;
58
+ char name[1024];
59
+ DWORD name_len;
60
+ FILETIME ft;
61
+
62
+ rv = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\ORACLE", 0, KEY_ENUMERATE_SUB_KEYS, &arg->hKey);
63
+ if (rv != ERROR_SUCCESS) {
64
+ return Qnil;
65
+ }
66
+ for (idx = 0; ; idx++) {
67
+ volatile VALUE oracle_home;
68
+ volatile VALUE nls_lang;
69
+
70
+ /* Get subkey name */
71
+ name_len = sizeof(name);
72
+ rv = RegEnumKeyEx(arg->hKey, idx, name, &name_len, NULL, NULL, NULL, &ft);
73
+ if (rv != ERROR_SUCCESS) {
74
+ break;
75
+ }
76
+ /* Open subkey */
77
+ if (arg->hSubKey != NULL) {
78
+ RegCloseKey(arg->hSubKey);
79
+ arg->hSubKey = NULL;
80
+ }
81
+ rv = RegOpenKeyEx(arg->hKey, name, 0, KEY_QUERY_VALUE, &arg->hSubKey);
82
+ if (rv != ERROR_SUCCESS) {
83
+ continue;
84
+ }
85
+ /* Get ORACLE_HOME */
86
+ name_len = sizeof(name);
87
+ rv = RegQueryValueEx(arg->hSubKey, "ORACLE_HOME", NULL, &type, name, &name_len);
88
+ if (rv != ERROR_SUCCESS || type != REG_SZ) {
89
+ continue;
90
+ }
91
+ oracle_home = rb_locale_str_new_cstr(name);
92
+ /* Get NLS_LANG */
93
+ name_len = sizeof(name);
94
+ rv = RegQueryValueEx(arg->hSubKey, "NLS_LANG", NULL, &type, name, &name_len);
95
+ if (rv != ERROR_SUCCESS || type != REG_SZ) {
96
+ continue;
97
+ }
98
+ nls_lang = rb_locale_str_new_cstr(name);
99
+ rb_yield_values(2, oracle_home, nls_lang);
100
+ }
101
+ return Qnil;
102
+ }
103
+
104
+ static VALUE enum_homes_ensure(enum_homes_arg_t *arg)
105
+ {
106
+ if (arg->hKey != NULL) {
107
+ RegCloseKey(arg->hKey);
108
+ arg->hKey = NULL;
109
+ }
110
+ if (arg->hSubKey != NULL) {
111
+ RegCloseKey(arg->hSubKey);
112
+ arg->hSubKey = NULL;
113
+ }
114
+ return Qnil;
115
+ }
116
+
117
+ static VALUE enum_homes(VALUE module)
118
+ {
119
+ enum_homes_arg_t arg;
120
+ arg.hKey = NULL;
121
+ arg.hSubKey = NULL;
122
+ return rb_ensure(enum_homes_real, (VALUE)&arg, enum_homes_ensure, (VALUE)&arg);
123
+ }
124
+
125
+ void Init_oci8_win32(VALUE cOCI8)
126
+ {
127
+ VALUE mWin32Util = rb_define_module_under(cOCI8, "Win32Util");
128
+
129
+ rb_define_module_function(mWin32Util, "dll_path", dll_path, 0);
130
+ rb_define_module_function(mWin32Util, "enum_homes", enum_homes, 0);
131
+ }
@@ -0,0 +1,383 @@
1
+ /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
2
+ #include "oci8.h"
3
+
4
+ #if 0 /* disabled for a while. */ && (ORACLE_CLIENT_VERSION >= ORAVER_10_1 || defined RUNTIME_API_CHECK)
5
+
6
+ #ifndef HAVE_XMLOTN_H
7
+ /* declarations in xmlproc.h of Oracle XML Development Kit */
8
+ typedef xmlnode xmlelemnode;
9
+ typedef xmlnode xmlpinode;
10
+ typedef xmlnode xmldocnode;
11
+ typedef xmlnode xmldtdnode;
12
+ typedef xmlnode xmlnotenode;
13
+ typedef xmlnode xmlnamedmap;
14
+ typedef xmlnode xmlattrnode;
15
+
16
+ typedef enum {
17
+ XMLERR_OK = 0,
18
+ } xmlerr;
19
+
20
+ typedef enum {
21
+ XMLDOM_NONE = 0, /* bogus node */
22
+ XMLDOM_ELEM = 1, /* element */
23
+ XMLDOM_ATTR = 2, /* attribute */
24
+ XMLDOM_TEXT = 3, /* char data not escaped by CDATA */
25
+ XMLDOM_CDATA = 4, /* char data escaped by CDATA */
26
+ XMLDOM_ENTREF = 5, /* entity reference */
27
+ XMLDOM_ENTITY = 6, /* entity */
28
+ XMLDOM_PI = 7, /* <?processing instructions?> */
29
+ XMLDOM_COMMENT = 8, /* <!-- Comments --> */
30
+ XMLDOM_DOC = 9, /* Document */
31
+ XMLDOM_DTD = 10, /* DTD */
32
+ XMLDOM_FRAG = 11, /* Document fragment */
33
+ XMLDOM_NOTATION = 12, /* notation */
34
+ XMLDOM_ELEMDECL = 13, /* DTD element declaration */
35
+ XMLDOM_ATTRDECL = 14, /* DTD attribute declaration */
36
+ XMLDOM_CPELEM = 15, /* element */
37
+ XMLDOM_CPCHOICE = 16, /* choice (a|b) */
38
+ XMLDOM_CPSEQ = 17, /* sequence (a,b) */
39
+ XMLDOM_CPPCDATA = 18, /* #PCDATA */
40
+ XMLDOM_CPSTAR = 19, /* '*' (zero or more) */
41
+ XMLDOM_CPPLUS = 20, /* '+' (one or more) */
42
+ XMLDOM_CPOPT = 21, /* '?' (optional) */
43
+ XMLDOM_CPEND = 22 /* end marker */
44
+ } xmlnodetype;
45
+
46
+ typedef struct xmldomcb {
47
+ void *cb[1];
48
+ } xmldomcb;
49
+
50
+ typedef struct xmlctxhead {
51
+ ub4 cw_xmlctxhead; /* checkword */
52
+ oratext *name_xmlctxhead; /* name for context */
53
+ void *cb_xmlctxhead; /* top-level function callbacks */
54
+ xmldomcb *domcb_xmlctxhead; /* DOM function callbacks */
55
+ } xmlctxhead;
56
+ #define XML_DOMCB(xctx) ((xmlctxhead *) xctx)->domcb_xmlctxhead
57
+
58
+ typedef xmlerr (*XmlDomGetDecl_t)(xmlctx *xctx, xmldocnode *doc, oratext **ver, oratext **enc, sb4 *std);
59
+ #define XmlDomGetDecl(xctx, doc, ver, enc, std) \
60
+ ((XmlDomGetDecl_t)XML_DOMCB(xctx)->cb[0])((xctx), (doc), (ver), (enc), (std))
61
+
62
+ typedef xmldtdnode* (*XmlDomGetDTD_t)(xmlctx *xctx, xmldocnode *doc);
63
+ #define XmlDomGetDTD(xctx, doc) \
64
+ ((XmlDomGetDTD_t)XML_DOMCB(xctx)->cb[3])((xctx), (doc))
65
+
66
+ typedef xmlnodetype (*XmlDomGetNodeType_t)(xmlctx *xctx, xmlnode *node);
67
+ #define XmlDomGetNodeType(xctx, node) \
68
+ ((XmlDomGetNodeType_t)XML_DOMCB(xctx)->cb[34])((xctx), (node))
69
+
70
+ typedef xmlnode* (*XmlDomGetFirstChild_t)(xmlctx *xctx, xmlnode *node);
71
+ #define XmlDomGetFirstChild(xctx, node) \
72
+ ((XmlDomGetFirstChild_t)XML_DOMCB(xctx)->cb[46])((xctx), (node))
73
+
74
+ typedef xmlnode* (*XmlDomGetNextSibling_t)(xmlctx *xctx, xmlnode *node);
75
+ #define XmlDomGetNextSibling(xctx, node) \
76
+ ((XmlDomGetNextSibling_t)XML_DOMCB(xctx)->cb[53])((xctx), (node))
77
+
78
+ typedef xmlnamedmap* (*XmlDomGetAttrs_t)(xmlctx *xctx, xmlelemnode *elem);
79
+ #define XmlDomGetAttrs(xctx, node) \
80
+ ((XmlDomGetAttrs_t)XML_DOMCB(xctx)->cb[55])((xctx), (node))
81
+
82
+ typedef xmlnode* (*XmlDomGetNodeMapItem_t)(xmlctx *xctx, xmlnamedmap *map, ub4 index);
83
+ #define XmlDomGetNodeMapItem(xctx, map, index) \
84
+ ((XmlDomGetNodeMapItem_t)XML_DOMCB(xctx)->cb[82])((xctx), (map), (index))
85
+
86
+ typedef ub4 (*XmlDomGetNodeMapLength_t)(xmlctx *xctx, xmlnamedmap *map);
87
+ #define XmlDomGetNodeMapLength(xctx, map) \
88
+ ((XmlDomGetNodeMapLength_t)XML_DOMCB(xctx)->cb[83])((xctx), (map))
89
+
90
+ typedef oratext* (*XmlDomGetCharData_t)(xmlctx *xctx, xmlnode *node);
91
+ #define XmlDomGetCharData(xctx, node) \
92
+ ((XmlDomGetCharData_t)XML_DOMCB(xctx)->cb[90])((xctx), (node))
93
+
94
+ typedef oratext* (*XmlDomGetAttrName_t)(xmlctx *xctx, xmlattrnode *attr);
95
+ #define XmlDomGetAttrName(xctx, attr) \
96
+ ((XmlDomGetAttrName_t)XML_DOMCB(xctx)->cb[98])((xctx), (attr))
97
+
98
+ typedef oratext* (*XmlDomGetAttrValue_t)(xmlctx *xctx, xmlattrnode *attr);
99
+ #define XmlDomGetAttrValue(xctx, attr) \
100
+ ((XmlDomGetAttrValue_t)XML_DOMCB(xctx)->cb[106])((xctx), (attr))
101
+
102
+ typedef oratext* (*XmlDomGetTag_t)(xmlctx *xctx, xmlelemnode *elem);
103
+ #define XmlDomGetTag(xctx, elem) \
104
+ ((XmlDomGetTag_t)XML_DOMCB(xctx)->cb[112])((xctx), (elem))
105
+
106
+ typedef oratext* (*XmlDomGetDTDName_t)(xmlctx *xctx, xmldtdnode *dtd);
107
+ #define XmlDomGetDTDName(xctx, dtd) \
108
+ ((XmlDomGetDTDName_t)XML_DOMCB(xctx)->cb[131])((xctx), (dtd))
109
+
110
+ typedef xmlnamedmap* (*XmlDomGetDTDEntities_t)(xmlctx *xctx, xmldtdnode *dtd);
111
+ #define XmlDomGetDTDEntities(xctx, dtd) \
112
+ ((XmlDomGetDTDEntities_t)XML_DOMCB(xctx)->cb[132])((xctx), (dtd))
113
+
114
+ typedef xmlnamedmap* (*XmlDomGetDTDNotations_t)(xmlctx *xctx, xmldtdnode *dtd);
115
+ #define XmlDomGetDTDNotations(xctx, dtd) \
116
+ ((XmlDomGetDTDNotations_t)XML_DOMCB(xctx)->cb[133])((xctx), (dtd))
117
+
118
+ typedef oratext* (*XmlDomGetDTDPubID_t)(xmlctx *xctx, xmldtdnode *dtd);
119
+ #define XmlDomGetDTDPubID(xctx, dtd) \
120
+ ((XmlDomGetDTDPubID_t)XML_DOMCB(xctx)->cb[134])((xctx), (dtd))
121
+
122
+ typedef oratext* (*XmlDomGetDTDSysID_t)(xmlctx *xctx, xmldtdnode *dtd);
123
+ #define XmlDomGetDTDSysID(xctx, dtd) \
124
+ ((XmlDomGetDTDSysID_t)XML_DOMCB(xctx)->cb[135])((xctx), (dtd))
125
+
126
+ typedef oratext* (*XmlDomGetPITarget_t)(xmlctx *xctx, xmlpinode *pi);
127
+ #define XmlDomGetPITarget(xctx, pi) \
128
+ ((XmlDomGetPITarget_t)XML_DOMCB(xctx)->cb[143])((xctx), (pi))
129
+
130
+ typedef oratext* (*XmlDomGetPIData_t)(xmlctx *xctx, xmlpinode *pi);
131
+ #define XmlDomGetPIData(xctx, pi) \
132
+ ((XmlDomGetPIData_t)XML_DOMCB(xctx)->cb[144])((xctx), (pi))
133
+
134
+ /* end of declarations in xmlproc.h of Oracle XML Development Kit */
135
+ #endif /* HAVE_XMLOTN_H */
136
+
137
+ static ID id_add;
138
+ static ID id_add_attribute;
139
+ static VALUE REXML_Element;
140
+ static VALUE REXML_Text;
141
+ static VALUE REXML_CData;
142
+ static VALUE REXML_Instruction;
143
+ static VALUE REXML_Comment;
144
+ static VALUE REXML_Document;
145
+ static VALUE REXML_XMLDecl;
146
+ static VALUE REXML_DocType;
147
+ static VALUE REXML_NotationDecl;
148
+
149
+ static VALUE oci8_make_element(struct xmlctx *xctx, xmlelemnode *elem);
150
+ static VALUE oci8_make_cdata(struct xmlctx *xctx, xmlnode *node);
151
+ static VALUE oci8_make_text(struct xmlctx *xctx, xmlnode *node);
152
+ static VALUE oci8_make_pi(struct xmlctx *xctx, xmlpinode *pi);
153
+ static VALUE oci8_make_comment(struct xmlctx *xctx, xmlnode *node);
154
+ static VALUE oci8_make_document(struct xmlctx *xctx, xmldocnode *doc);
155
+ static VALUE oci8_make_dtd(struct xmlctx *xctx, xmldtdnode *dtd);
156
+
157
+ static VALUE add_child_nodes(VALUE obj, struct xmlctx *xctx, xmlnode *node);
158
+ static VALUE add_attributes(VALUE obj, struct xmlctx *xctx, xmlnode *node);
159
+ static VALUE add_nodemap(VALUE obj, struct xmlctx *xctx, xmlnamedmap *map);
160
+
161
+ void Init_oci_xmldb(void)
162
+ {
163
+ id_add = rb_intern("add");
164
+ id_add_attribute = rb_intern("add_attribute");
165
+ rb_require("rexml/document");
166
+ REXML_Document = rb_eval_string("REXML::Document");
167
+ REXML_Element = rb_eval_string("REXML::Element");
168
+ REXML_Text = rb_eval_string("REXML::Text");
169
+ REXML_CData = rb_eval_string("REXML::CData");
170
+ REXML_Instruction = rb_eval_string("REXML::Instruction");
171
+ REXML_Comment = rb_eval_string("REXML::Comment");
172
+ REXML_XMLDecl = rb_eval_string("REXML::XMLDecl");
173
+ REXML_DocType = rb_eval_string("REXML::DocType");
174
+ REXML_NotationDecl = rb_eval_string("REXML::NotationDecl");
175
+ }
176
+
177
+ VALUE oci8_make_rexml(struct xmlctx *xctx, xmlnode *node)
178
+ {
179
+ xmlnodetype nodetype = XmlDomGetNodeType(xctx, node);
180
+
181
+ switch (nodetype) {
182
+ case XMLDOM_NONE: /* 0 */
183
+ rb_raise(rb_eRuntimeError, "unsupported XML node type: XMLDOM_NONE");
184
+ case XMLDOM_ELEM: /* 1 */
185
+ return oci8_make_element(xctx, (xmlelemnode*)node);
186
+ case XMLDOM_ATTR: /* 2 */
187
+ rb_raise(rb_eRuntimeError, "unsupported XML node type: XMLDOM_ATTR");
188
+ case XMLDOM_TEXT: /* 3 */
189
+ return oci8_make_text(xctx, node);
190
+ case XMLDOM_CDATA: /* 4 */
191
+ return oci8_make_cdata(xctx, node);
192
+ case XMLDOM_ENTREF: /* 5 */
193
+ rb_raise(rb_eRuntimeError, "unsupported XML node type: XMLDOM_ENTREF");
194
+ case XMLDOM_ENTITY: /* 6 */
195
+ rb_raise(rb_eRuntimeError, "unsupported XML node type: XMLDOM_ENTITY");
196
+ case XMLDOM_PI: /* 7 */
197
+ return oci8_make_pi(xctx, (xmlpinode*)node);
198
+ case XMLDOM_COMMENT: /* 8 */
199
+ return oci8_make_comment(xctx, node);
200
+ case XMLDOM_DOC: /* 9 */
201
+ return oci8_make_document(xctx, (xmldocnode*)node);
202
+ case XMLDOM_DTD: /* 10 */
203
+ return oci8_make_dtd(xctx, (xmldtdnode*)node);
204
+ case XMLDOM_FRAG: /* 11 */
205
+ rb_raise(rb_eRuntimeError, "unsupported XML node type: XMLDOM_FRAG");
206
+ case XMLDOM_NOTATION: /* 12 */
207
+ rb_raise(rb_eRuntimeError, "unsupported XML node type: XMLDOM_NOTATION");
208
+ case XMLDOM_ELEMDECL: /* 13 */
209
+ rb_raise(rb_eRuntimeError, "unsupported XML node type: XMLDOM_ELEMDECL");
210
+ case XMLDOM_ATTRDECL: /* 14 */
211
+ rb_raise(rb_eRuntimeError, "unsupported XML node type: XMLDOM_ATTRDECL");
212
+ case XMLDOM_CPELEM: /* 15 */
213
+ rb_raise(rb_eRuntimeError, "unsupported XML node type: XMLDOM_CPELEM");
214
+ case XMLDOM_CPCHOICE: /* 16 */
215
+ rb_raise(rb_eRuntimeError, "unsupported XML node type: XMLDOM_CPCHOICE");
216
+ case XMLDOM_CPSEQ: /* 17 */
217
+ rb_raise(rb_eRuntimeError, "unsupported XML node type: XMLDOM_CPSEQ");
218
+ case XMLDOM_CPPCDATA: /* 18 */
219
+ rb_raise(rb_eRuntimeError, "unsupported XML node type: XMLDOM_CPPCDATA");
220
+ case XMLDOM_CPSTAR: /* 19 */
221
+ rb_raise(rb_eRuntimeError, "unsupported XML node type: XMLDOM_CPSTAR");
222
+ case XMLDOM_CPPLUS: /* 20 */
223
+ rb_raise(rb_eRuntimeError, "unsupported XML node type: XMLDOM_CPPLUS");
224
+ case XMLDOM_CPOPT: /* 21 */
225
+ rb_raise(rb_eRuntimeError, "unsupported XML node type: XMLDOM_CPOPT");
226
+ case XMLDOM_CPEND: /* 22 */
227
+ rb_raise(rb_eRuntimeError, "unsupported XML node type: XMLDOM_CPEND");
228
+ }
229
+ rb_raise(rb_eRuntimeError, "unsupported XML node type: %d", nodetype);
230
+ }
231
+
232
+ static VALUE oci8_make_element(struct xmlctx *xctx, xmlelemnode *elem)
233
+ {
234
+ oratext *name;
235
+ VALUE obj;
236
+
237
+ name = XmlDomGetTag(xctx, elem);
238
+ obj = rb_funcall(REXML_Element, oci8_id_new, 1, rb_str_new2_ora(name));
239
+ add_attributes(obj, xctx, (xmlnode*)elem);
240
+ return add_child_nodes(obj, xctx, (xmlnode*)elem);
241
+ }
242
+
243
+ static VALUE oci8_make_text(struct xmlctx *xctx, xmlnode *node)
244
+ {
245
+ oratext *data = XmlDomGetCharData(xctx, node);
246
+ return rb_funcall(REXML_Text, oci8_id_new, 1, rb_str_new2_ora(data));
247
+ }
248
+
249
+ static VALUE oci8_make_cdata(struct xmlctx *xctx, xmlnode *node)
250
+ {
251
+ oratext *data = XmlDomGetCharData(xctx, node);
252
+ return rb_funcall(REXML_CData, oci8_id_new, 1, rb_str_new2_ora(data));
253
+ }
254
+
255
+ static VALUE oci8_make_pi(struct xmlctx *xctx, xmlpinode *pi)
256
+ {
257
+ oratext *target;
258
+ oratext *data;
259
+
260
+ target= XmlDomGetPITarget(xctx, pi);
261
+ data = XmlDomGetPIData(xctx, pi);
262
+ return rb_funcall(REXML_Instruction, oci8_id_new, 2, rb_str_new2_ora(target), data ? rb_str_new2_ora(data) : Qnil);
263
+ }
264
+
265
+ static VALUE oci8_make_comment(struct xmlctx *xctx, xmlnode *node)
266
+ {
267
+ oratext *data = XmlDomGetCharData(xctx, node);
268
+ return rb_funcall(REXML_Comment, oci8_id_new, 1, rb_str_new2_ora(data));
269
+ }
270
+
271
+ static VALUE oci8_make_document(struct xmlctx *xctx, xmldocnode *doc)
272
+ {
273
+ xmlerr err;
274
+ oratext *ver;
275
+ oratext *enc;
276
+ sb4 std;
277
+ #ifdef ENABLE_DTD
278
+ xmldtdnode* dtd;
279
+ #endif
280
+ VALUE obj;
281
+ VALUE decl;
282
+
283
+ obj = rb_funcall(REXML_Document, oci8_id_new, 0);
284
+ err = XmlDomGetDecl(xctx, doc, &ver, &enc, &std);
285
+ if (err == XMLERR_OK) {
286
+ decl = rb_funcall(REXML_XMLDecl, oci8_id_new, 3,
287
+ ver ? rb_str_new2_ora(ver) : Qnil,
288
+ enc ? rb_str_new2_ora(enc) : Qnil,
289
+ (std < 0) ? Qnil : ((std > 0) ? rb_str_new2("yes") : rb_str_new2("no")));
290
+ rb_funcall(obj, id_add, 1, decl);
291
+ }
292
+ #ifdef ENABLE_DTD
293
+ dtd = XmlDomGetDTD(xctx, doc);
294
+ if (dtd != NULL) {
295
+ rb_funcall(obj, id_add, 1, oci8_make_dtd(xctx, dtd));
296
+ }
297
+ #endif
298
+ return add_child_nodes(obj, xctx, (xmlnode*)doc);
299
+ }
300
+
301
+ static VALUE oci8_make_dtd(struct xmlctx *xctx, xmldtdnode *dtd)
302
+ {
303
+ /*
304
+ * DTD support is not finished.
305
+ * I don't know how to get full dtd data from xmldtdnode.
306
+ */
307
+ oratext *name;
308
+ oratext *pubid;
309
+ oratext *sysid;
310
+ xmlnamedmap *entities;
311
+ xmlnamedmap *notations;
312
+ VALUE obj;
313
+
314
+ name = XmlDomGetDTDName(xctx, dtd);
315
+ pubid = XmlDomGetDTDPubID(xctx, dtd);
316
+ sysid = XmlDomGetDTDSysID(xctx, dtd);
317
+ entities = XmlDomGetDTDEntities(xctx, dtd);
318
+ notations = XmlDomGetDTDNotations(xctx, dtd);
319
+
320
+ obj = rb_funcall(REXML_DocType, oci8_id_new, 1, rb_str_new2_ora(name));
321
+ if (entities != NULL)
322
+ add_nodemap(obj, xctx, entities);
323
+ if (notations != NULL)
324
+ add_nodemap(obj, xctx, notations);
325
+ return obj;
326
+ }
327
+
328
+ static VALUE add_child_nodes(VALUE obj, struct xmlctx *xctx, xmlnode *node)
329
+ {
330
+ node = XmlDomGetFirstChild(xctx, node);
331
+ while (node != NULL) {
332
+ rb_funcall(obj, id_add, 1, oci8_make_rexml(xctx, node));
333
+ node = XmlDomGetNextSibling(xctx, node);
334
+ }
335
+ return obj;
336
+ }
337
+
338
+ static VALUE add_attributes(VALUE obj, struct xmlctx *xctx, xmlnode *node)
339
+ {
340
+ xmlnamedmap *attrs;
341
+ xmlnode *attr;
342
+ oratext *name;
343
+ oratext *value;
344
+ ub4 num;
345
+ ub4 idx;
346
+
347
+ attrs = XmlDomGetAttrs(xctx, node);
348
+ num = XmlDomGetNodeMapLength(xctx, attrs);
349
+ for (idx = 0; idx < num; idx++) {
350
+ attr = XmlDomGetNodeMapItem(xctx, attrs, idx);
351
+ name = XmlDomGetAttrName(xctx, attr);
352
+ value = XmlDomGetAttrValue(xctx, attr);
353
+ rb_funcall(obj, id_add_attribute, 2,
354
+ rb_str_new2_ora(name),
355
+ value ? rb_str_new2_ora(value) : Qnil);
356
+ }
357
+ return obj;
358
+ }
359
+
360
+ static VALUE add_nodemap(VALUE obj, struct xmlctx *xctx, xmlnamedmap *map)
361
+ {
362
+ xmlnode *node;
363
+ ub4 num;
364
+ ub4 idx;
365
+
366
+ num = XmlDomGetNodeMapLength(xctx, map);
367
+ for (idx = 0; idx < num; idx++) {
368
+ node = XmlDomGetNodeMapItem(xctx, map, idx);
369
+ rb_funcall(obj, id_add, 1, oci8_make_rexml(xctx, node));
370
+ }
371
+ return obj;
372
+ }
373
+
374
+ #else
375
+ void Init_oci_xmldb(void)
376
+ {
377
+ }
378
+
379
+ VALUE oci8_make_rexml(struct xmlctx *xctx, xmlnode *node)
380
+ {
381
+ rb_notimplement();
382
+ }
383
+ #endif