ruby-staci 2.2.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (115) hide show
  1. checksums.yaml +7 -0
  2. data/.yardopts +14 -0
  3. data/COPYING +30 -0
  4. data/COPYING_old +64 -0
  5. data/ChangeLog +3826 -0
  6. data/Makefile +92 -0
  7. data/NEWS +1194 -0
  8. data/README.md +66 -0
  9. data/dist-files +113 -0
  10. data/docs/bind-array-to-in_cond.md +38 -0
  11. data/docs/conflicts-local-connections-and-processes.md +98 -0
  12. data/docs/hanging-after-inactivity.md +63 -0
  13. data/docs/install-binary-package.md +44 -0
  14. data/docs/install-full-client.md +111 -0
  15. data/docs/install-instant-client.md +194 -0
  16. data/docs/install-on-osx.md +133 -0
  17. data/docs/ldap-auth-and-function-interposition.md +123 -0
  18. data/docs/number-type-mapping.md +79 -0
  19. data/docs/osx-install-dev-tools.png +0 -0
  20. data/docs/platform-specific-issues.md +164 -0
  21. data/docs/report-installation-issue.md +50 -0
  22. data/docs/timeout-parameters.md +94 -0
  23. data/ext/oci8/.document +18 -0
  24. data/ext/oci8/MANIFEST +18 -0
  25. data/ext/oci8/apiwrap.c.tmpl +178 -0
  26. data/ext/oci8/apiwrap.h.tmpl +61 -0
  27. data/ext/oci8/apiwrap.rb +96 -0
  28. data/ext/oci8/apiwrap.yml +1322 -0
  29. data/ext/oci8/attr.c +57 -0
  30. data/ext/oci8/bind.c +838 -0
  31. data/ext/oci8/connection_pool.c +216 -0
  32. data/ext/oci8/encoding.c +196 -0
  33. data/ext/oci8/env.c +139 -0
  34. data/ext/oci8/error.c +385 -0
  35. data/ext/oci8/extconf.rb +219 -0
  36. data/ext/oci8/hook_funcs.c +407 -0
  37. data/ext/oci8/lob.c +1278 -0
  38. data/ext/oci8/metadata.c +279 -0
  39. data/ext/oci8/object.c +919 -0
  40. data/ext/oci8/oci8.c +1058 -0
  41. data/ext/oci8/oci8.h +556 -0
  42. data/ext/oci8/oci8lib.c +704 -0
  43. data/ext/oci8/ocidatetime.c +506 -0
  44. data/ext/oci8/ocihandle.c +852 -0
  45. data/ext/oci8/ocinumber.c +1922 -0
  46. data/ext/oci8/oraconf.rb +1145 -0
  47. data/ext/oci8/oradate.c +670 -0
  48. data/ext/oci8/oranumber_util.c +352 -0
  49. data/ext/oci8/oranumber_util.h +24 -0
  50. data/ext/oci8/plthook.h +66 -0
  51. data/ext/oci8/plthook_elf.c +702 -0
  52. data/ext/oci8/plthook_osx.c +505 -0
  53. data/ext/oci8/plthook_win32.c +391 -0
  54. data/ext/oci8/post-config.rb +5 -0
  55. data/ext/oci8/stmt.c +448 -0
  56. data/ext/oci8/thread_util.c +81 -0
  57. data/ext/oci8/thread_util.h +18 -0
  58. data/ext/oci8/util.c +71 -0
  59. data/ext/oci8/win32.c +117 -0
  60. data/lib/.document +1 -0
  61. data/lib/dbd/STACI.rb +591 -0
  62. data/lib/oci8/.document +8 -0
  63. data/lib/oci8/bindtype.rb +333 -0
  64. data/lib/oci8/check_load_error.rb +146 -0
  65. data/lib/oci8/compat.rb +117 -0
  66. data/lib/oci8/connection_pool.rb +179 -0
  67. data/lib/oci8/cursor.rb +605 -0
  68. data/lib/oci8/datetime.rb +605 -0
  69. data/lib/oci8/encoding-init.rb +45 -0
  70. data/lib/oci8/encoding.yml +537 -0
  71. data/lib/oci8/metadata.rb +2148 -0
  72. data/lib/oci8/object.rb +641 -0
  73. data/lib/oci8/oci8.rb +756 -0
  74. data/lib/oci8/ocihandle.rb +591 -0
  75. data/lib/oci8/oracle_version.rb +153 -0
  76. data/lib/oci8/properties.rb +196 -0
  77. data/lib/oci8/version.rb +3 -0
  78. data/lib/ruby-staci.rb +1 -0
  79. data/lib/staci.rb +190 -0
  80. data/metaconfig +142 -0
  81. data/pre-distclean.rb +7 -0
  82. data/ruby-aci.gemspec +83 -0
  83. data/setup.rb +1342 -0
  84. data/test/README.md +37 -0
  85. data/test/config.rb +201 -0
  86. data/test/setup_test_object.sql +199 -0
  87. data/test/setup_test_package.sql +59 -0
  88. data/test/test_all.rb +56 -0
  89. data/test/test_appinfo.rb +62 -0
  90. data/test/test_array_dml.rb +333 -0
  91. data/test/test_bind_array.rb +70 -0
  92. data/test/test_bind_boolean.rb +99 -0
  93. data/test/test_bind_integer.rb +47 -0
  94. data/test/test_bind_raw.rb +45 -0
  95. data/test/test_bind_string.rb +105 -0
  96. data/test/test_bind_time.rb +177 -0
  97. data/test/test_break.rb +124 -0
  98. data/test/test_clob.rb +86 -0
  99. data/test/test_connection_pool.rb +124 -0
  100. data/test/test_connstr.rb +220 -0
  101. data/test/test_datetime.rb +585 -0
  102. data/test/test_dbi.rb +365 -0
  103. data/test/test_dbi_clob.rb +53 -0
  104. data/test/test_encoding.rb +103 -0
  105. data/test/test_error.rb +87 -0
  106. data/test/test_metadata.rb +2674 -0
  107. data/test/test_object.rb +546 -0
  108. data/test/test_oci8.rb +624 -0
  109. data/test/test_oracle_version.rb +68 -0
  110. data/test/test_oradate.rb +255 -0
  111. data/test/test_oranumber.rb +786 -0
  112. data/test/test_package_type.rb +981 -0
  113. data/test/test_properties.rb +17 -0
  114. data/test/test_rowid.rb +32 -0
  115. metadata +158 -0
data/ext/oci8/error.c ADDED
@@ -0,0 +1,385 @@
1
+ /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
2
+ /*
3
+ error.c - part of ruby-oci8
4
+
5
+ Copyright (C) 2002-2015 Kubo Takehiro <kubo@jiubao.org>
6
+
7
+ */
8
+ #include "oci8.h"
9
+
10
+ #ifndef DLEXT
11
+ #define DLEXT ".so"
12
+ #endif
13
+
14
+ /* Exception */
15
+ VALUE eOCIException;
16
+ VALUE eOCIBreak;
17
+ static VALUE eOCINoData;
18
+ static VALUE eACIError;
19
+ static VALUE eOCIInvalidHandle;
20
+ static VALUE eOCINeedData;
21
+ static VALUE eOCIStillExecuting;
22
+ static VALUE eOCIContinue;
23
+ static VALUE eOCISuccessWithInfo;
24
+
25
+ static ID oci8_id_at_code;
26
+ static ID oci8_id_at_sql;
27
+ static ID oci8_id_at_parse_error_offset;
28
+ static ID oci8_id_caller;
29
+ static ID oci8_id_set_backtrace;
30
+
31
+ #define ERRBUF_EXPAND_LEN 256
32
+ static char *errbuf;
33
+ static ub4 errbufsiz;
34
+
35
+ static ACIMsg *msghp;
36
+
37
+ static VALUE set_backtrace(VALUE exc, const char *file, int line);
38
+
39
+ static VALUE get_error_msg(dvoid *errhp, ub4 type, const char *default_msg, sb4 *errcode_p)
40
+ {
41
+ sword rv;
42
+ size_t len;
43
+
44
+ retry:
45
+ errbuf[0] = '\0';
46
+ rv = ACIErrorGet(errhp, 1, NULL, errcode_p, TO_ORATEXT(errbuf), errbufsiz, type);
47
+ /* OCI manual says:
48
+ * If type is set to OCI_HTYPE_ERROR, then the return
49
+ * code during truncation for OCIErrorGet() is
50
+ * OCI_ERROR. The client can then specify a bigger
51
+ * buffer and call OCIErrorGet() again.
52
+ *
53
+ * But as far as I tested on Oracle XE 10.2.0.1, the return
54
+ * code is OCI_SUCCESS when the message is truncated.
55
+ */
56
+ len = strlen(errbuf);
57
+ if (errbufsiz - len <= 7) {
58
+ /* The error message may be truncated.
59
+ * The magic number 7 means the maximum length of one utf-8
60
+ * character plus the length of a nul terminator.
61
+ */
62
+ errbufsiz += ERRBUF_EXPAND_LEN;
63
+ errbuf = xrealloc(errbuf, errbufsiz);
64
+ goto retry;
65
+ }
66
+ if (rv != OCI_SUCCESS) {
67
+ /* No message is found. Use the default message. */
68
+ return rb_usascii_str_new_cstr(default_msg);
69
+ }
70
+
71
+ /* truncate trailing CR and LF */
72
+ while (len > 0 && (errbuf[len - 1] == '\n' || errbuf[len - 1] == '\r')) {
73
+ len--;
74
+ }
75
+ return rb_external_str_new_with_enc(errbuf, len, oci8_encoding);
76
+ }
77
+
78
+ /*
79
+ * Don't call rb_class_new_instance() with more than one argument in this function.
80
+ * This may be called before OCIError#initialize is defined in lib/oci8/oci8.rb.
81
+ */
82
+ static VALUE oci_exception_new(VALUE klass, VALUE msg, VALUE code, VALUE sql, VALUE parse_error_offset)
83
+ {
84
+ VALUE obj = rb_class_new_instance(NIL_P(msg) ? 0 : 1, &msg, klass);
85
+ if (rb_obj_is_kind_of(obj, eACIError)) {
86
+ rb_ivar_set(obj, oci8_id_at_code, code);
87
+ rb_ivar_set(obj, oci8_id_at_sql, sql);
88
+ rb_ivar_set(obj, oci8_id_at_parse_error_offset, parse_error_offset);
89
+ }
90
+ return obj;
91
+ }
92
+
93
+ static VALUE oci8_make_exc(dvoid *errhp, sword status, ub4 type, ACIStmt *stmthp, const char *file, int line)
94
+ {
95
+ VALUE exc;
96
+ char errmsg[128];
97
+ sb4 errcode = -1;
98
+ VALUE msg;
99
+ VALUE parse_error_offset = Qnil;
100
+ VALUE sql = Qnil;
101
+ int rv;
102
+
103
+ switch (status) {
104
+ case OCI_ERROR:
105
+ exc = eACIError;
106
+ msg = get_error_msg(errhp, type, "Error", &errcode);
107
+ break;
108
+ case OCI_SUCCESS_WITH_INFO:
109
+ exc = eOCISuccessWithInfo;
110
+ msg = get_error_msg(errhp, type, "Error", &errcode);
111
+ break;
112
+ case ACI_NO_DATA:
113
+ exc = eOCINoData;
114
+ msg = get_error_msg(errhp, type, "No Data", &errcode);
115
+ break;
116
+ case ACI_INVALID_HANDLE:
117
+ exc = eOCIInvalidHandle;
118
+ msg = rb_usascii_str_new_cstr("Invalid Handle");
119
+ break;
120
+ case ACI_NEED_DATA:
121
+ exc = eOCINeedData;
122
+ msg = rb_usascii_str_new_cstr("Need Data");
123
+ break;
124
+ case ACI_STILL_EXECUTING:
125
+ exc = eOCIStillExecuting;
126
+ msg = rb_usascii_str_new_cstr("Still Executing");
127
+ break;
128
+ case ACI_CONTINUE:
129
+ exc = eOCIContinue;
130
+ msg = rb_usascii_str_new_cstr("Continue");
131
+ break;
132
+ default:
133
+ sprintf(errmsg, "Unknown error (%d)", status);
134
+ exc = eOCIException;
135
+ msg = rb_usascii_str_new_cstr(errmsg);
136
+ }
137
+ if (stmthp != NULL) {
138
+ ub2 offset;
139
+ text *text;
140
+ ub4 size;
141
+
142
+ rv = ACIAttrGet(stmthp, ACI_HTYPE_STMT, &offset, 0, ACI_ATTR_PARSE_ERROR_OFFSET, errhp);
143
+ if (rv == ACI_SUCCESS) {
144
+ parse_error_offset = INT2FIX(offset);
145
+ }
146
+ rv = ACIAttrGet(stmthp, ACI_HTYPE_STMT, &text, &size, ACI_ATTR_STATEMENT, errhp);
147
+ if (rv == ACI_SUCCESS) {
148
+ sql = rb_external_str_new_with_enc(TO_CHARPTR(text), size, oci8_encoding);
149
+ }
150
+ }
151
+ exc = oci_exception_new(exc, msg, INT2FIX(errcode), sql, parse_error_offset);
152
+ return set_backtrace(exc, file, line);
153
+ }
154
+
155
+ static VALUE set_backtrace(VALUE exc, const char *file, int line)
156
+ {
157
+ char errmsg[64];
158
+ VALUE backtrace;
159
+ #ifdef _WIN32
160
+ char *p = strrchr(file, '\\');
161
+ if (p != NULL)
162
+ file = p + 1;
163
+ #endif
164
+ backtrace = rb_funcall(rb_cObject, oci8_id_caller, 0);
165
+ if (TYPE(backtrace) == T_ARRAY) {
166
+ snprintf(errmsg, sizeof(errmsg), "%s:%d:in " STRINGIZE(oci8lib) DLEXT, file, line);
167
+ errmsg[sizeof(errmsg) - 1] = '\0';
168
+ rb_ary_unshift(backtrace, rb_usascii_str_new_cstr(errmsg));
169
+ rb_funcall(exc, oci8_id_set_backtrace, 1, backtrace);
170
+ }
171
+ return exc;
172
+ }
173
+
174
+ sb4 oci8_get_error_code(ACIError *errhp)
175
+ {
176
+ sb4 errcode = -1;
177
+ ACIErrorGet(oci8_errhp, 1, NULL, &errcode, NULL, 0, ACI_HTYPE_ERROR);
178
+ return errcode;
179
+ }
180
+
181
+ void Init_oci8_error(void)
182
+ {
183
+ errbufsiz = ERRBUF_EXPAND_LEN;
184
+ errbuf = xmalloc(errbufsiz);
185
+
186
+ oci8_id_at_code = rb_intern("@code");
187
+ oci8_id_at_sql = rb_intern("@sql");
188
+ oci8_id_at_parse_error_offset = rb_intern("@parse_error_offset");
189
+ oci8_id_caller = rb_intern("caller");
190
+ oci8_id_set_backtrace = rb_intern("set_backtrace");
191
+
192
+ eOCIException = rb_define_class("ACIException", rb_eStandardError);
193
+ eOCIBreak = rb_define_class("ACIBreak", eOCIException);
194
+
195
+ eACIError = rb_define_class("ACIError", eOCIException);
196
+ eOCINoData = rb_define_class("ACINoData", eACIError);
197
+ eOCIInvalidHandle = rb_define_class("ACIInvalidHandle", eOCIException);
198
+ eOCINeedData = rb_define_class("ACINeedData", eOCIException);
199
+ eOCIStillExecuting = rb_define_class("ACIStillExecuting", eOCIException);
200
+ eOCIContinue = rb_define_class("ACIContinue", eOCIException);
201
+ eOCISuccessWithInfo = rb_define_class("ACISuccessWithInfo", eACIError);
202
+
203
+ /*
204
+ * @attr_reader [Integer] code error code
205
+ */
206
+ rb_define_attr(eACIError, "code", 1, 0);
207
+ rb_define_attr(eACIError, "sql", 1, 0);
208
+ rb_define_attr(eACIError, "parse_error_offset", 1, 0);
209
+ rb_define_alias(eACIError, "parseErrorOffset", "parse_error_offset");
210
+ }
211
+
212
+ void oci8_do_raise(ACIError *errhp, sword status, ACIStmt *stmthp, const char *file, int line)
213
+ {
214
+ rb_exc_raise(oci8_make_exc(errhp, status, ACI_HTYPE_ERROR, stmthp, file, line));
215
+ }
216
+
217
+ void oci8_do_env_raise(ACIEnv *envhp, sword status, int free_envhp, const char *file, int line)
218
+ {
219
+ VALUE exc = oci8_make_exc(envhp, status, ACI_HTYPE_ENV, NULL, file, line);
220
+ if (free_envhp) {
221
+ ACIHandleFree(envhp, ACI_HTYPE_ENV);
222
+ }
223
+ rb_exc_raise(exc);
224
+ }
225
+
226
+ void oci8_do_raise_init_error(const char *file, int line)
227
+ {
228
+ VALUE msg = rb_usascii_str_new_cstr("ACI Library Initialization Error");
229
+ VALUE exc;
230
+ const char *dll_path = oci8_dll_path();
231
+
232
+ if (dll_path != NULL) {
233
+ msg = rb_str_buf_cat_ascii(msg, " - ");
234
+ msg = rb_enc_str_buf_cat(msg, dll_path, strlen(dll_path), rb_filesystem_encoding());
235
+ }
236
+ exc = rb_class_new_instance(1, &msg, eACIError);
237
+ rb_exc_raise(set_backtrace(exc, file, line));
238
+ }
239
+
240
+ VALUE oci8_get_error_message(ub4 msgno, const char *default_msg)
241
+ {
242
+ char head[32];
243
+ size_t headsz;
244
+ const char *errmsg = NULL;
245
+ char msgbuf[64];
246
+
247
+ /*if (msghp == NULL) {
248
+ chkerr(ACIMessageOpen(oci8_envhp, oci8_errhp, &msghp, TO_CONST_ORATEXT("rdbms"), TO_CONST_ORATEXT("ora"), ACI_DURATION_PROCESS));
249
+ }*/
250
+ /*errmsg = TO_CHARPTR(ACIMessageGet(msghp, msgno, NULL, 0));
251
+ if (errmsg == NULL) {
252
+ if (default_msg != NULL) {
253
+ errmsg = default_msg;
254
+ } else {
255
+ /* last resort
256
+ snprintf(msgbuf, sizeof(msgbuf), "Message %u not found; product=rdbms; facility=ora", msgno);
257
+ errmsg = msgbuf;
258
+ }
259
+ } */
260
+ headsz = snprintf(head, sizeof(head), "ORA-%05u: ", msgno);
261
+ return rb_str_append(rb_usascii_str_new(head, headsz),
262
+ rb_external_str_new_with_enc(errmsg, strlen(errmsg), oci8_encoding));
263
+ }
264
+
265
+ void oci8_do_raise_by_msgno(ub4 msgno, const char *default_msg, const char *file, int line)
266
+ {
267
+ VALUE msg = oci8_get_error_message(msgno, default_msg);
268
+ VALUE exc = oci_exception_new(eACIError, msg, INT2FIX(-1), Qnil, Qnil);
269
+
270
+ rb_exc_raise(set_backtrace(exc, file, line));
271
+ }
272
+
273
+ void oci8_check_error_(sword status, oci8_base_t *base, ACIStmt *stmthp, const char *file, int line)
274
+ {
275
+ if (status != ACI_SUCCESS) {
276
+ VALUE exc = oci8_make_exc(oci8_errhp, status, ACI_HTYPE_ERROR, stmthp, file, line);
277
+ while (base != NULL) {
278
+ if (base->type == ACI_HTYPE_SVCCTX) {
279
+ rb_ivar_set(base->self, oci8_id_at_last_error, exc);
280
+ break;
281
+ }
282
+ base = base->parent;
283
+ }
284
+ if (status != ACI_SUCCESS_WITH_INFO) {
285
+ rb_exc_raise(exc);
286
+ }
287
+ }
288
+ }
289
+
290
+ /*
291
+ * Document-class: OCIException
292
+ *
293
+ * The superclass for all exceptions raised by ruby-oci8.
294
+ *
295
+ * The following exceptions are defined as subclasses of OCIException
296
+ * These exceptions are raised when Oracle Call Interface functions
297
+ * return with an error status.
298
+ *
299
+ * - {OCIBreak}
300
+ * - {OCIError}
301
+ * - {OCISuccessWithInfo}
302
+ * - {OCINoData} (It had been a subclass of OCIException, not OCIError, until ruby-oci8 2.0)
303
+ * - {OCIInvalidHandle}
304
+ */
305
+
306
+ /*
307
+ * Document-class: OCIBreak
308
+ *
309
+ * Subclass of OCIException
310
+ *
311
+ * Raised when a SQL execution is cancelled by {STACI#break}.
312
+ */
313
+
314
+ /*
315
+ * Document-class: OCINoData
316
+ *
317
+ * Subclass of OCIError from ruby-oci8 2.1.
318
+ * It had been a subclass of OCIException until ruby-oci8 2.0.
319
+ *
320
+ * Raised when PL/SQL NO_DATA_FOUND exception is got.
321
+ */
322
+
323
+ /*
324
+ * Document-class: OCIError
325
+ *
326
+ * Subclass of OCIException
327
+ *
328
+ * The following exceptions are defined as subclasses of OCIError.
329
+ *
330
+ * - OCISuccessWithInfo
331
+ * - OCINoData (It had been a subclass of OCIException, not OCIError, until ruby-oci8 2.0)
332
+ *
333
+ * Raised when underlying Oracle Call Interface failed with an Oracle error code
334
+ * such as ORA-00001.
335
+ *
336
+ * @attr_reader [Integer] code error code
337
+ * @attr_reader [String] sql SQL statement
338
+ * @attr_reader [Integer] parse_error_offset position
339
+ */
340
+
341
+ /*
342
+ * Document-class: OCIInvalidHandle
343
+ *
344
+ * Subclass of OCIException
345
+ *
346
+ * Raised when an invalid handle is passed to underlying Oracle Call Interface.
347
+ * Report to the ruby-oci8 author if it is raised.
348
+ */
349
+
350
+ /*
351
+ * Document-class: OCINeedData
352
+ *
353
+ * Subclass of OCIException
354
+ *
355
+ * Report to the ruby-oci8 author if it is raised.
356
+ *
357
+ * @private
358
+ */
359
+
360
+ /*
361
+ * Document-class: OCIStillExecuting
362
+ *
363
+ * Subclass of OCIError
364
+ *
365
+ * Report to the ruby-oci8 author if it is raised.
366
+ *
367
+ * @private
368
+ */
369
+
370
+ /*
371
+ * Document-class: OCIContinue
372
+ *
373
+ * Subclass of OCIException
374
+ *
375
+ * Report to the ruby-oci8 author if it is raised.
376
+ *
377
+ * @private
378
+ */
379
+
380
+ /*
381
+ * Document-class: OCISuccessWithInfo
382
+ *
383
+ * Subclass of OCIError
384
+ *
385
+ */
@@ -0,0 +1,219 @@
1
+ if RUBY_VERSION < "1.9"
2
+ puts "Ruby-oci8 doesn't work ruby 1.8 since ruby-oci8 2.2.0."
3
+ exit 1
4
+ end
5
+
6
+ begin
7
+ require 'mkmf'
8
+ rescue LoadError
9
+ if /linux/ =~ RUBY_PLATFORM
10
+ raise <<EOS
11
+ You need to install a ruby development package ruby-devel, ruby-dev or so.
12
+ EOS
13
+ end
14
+ raise
15
+ end
16
+
17
+ require File.dirname(__FILE__) + '/oraconf'
18
+ require File.dirname(__FILE__) + '/apiwrap'
19
+ require File.dirname(__FILE__) + '/../../lib/oci8/oracle_version.rb'
20
+ require File.dirname(__FILE__) + '/../../lib/oci8/version.rb'
21
+
22
+ oraconf = OraConf.get()
23
+
24
+ $CFLAGS += oraconf.cflags
25
+ saved_libs = $libs
26
+ $libs += oraconf.libs
27
+
28
+ saved_defs = $defs.clone
29
+ fmt = "%s"
30
+ def fmt.%(x)
31
+ x ? super : "failed"
32
+ end
33
+ oci_major_version = 11
34
+ if oci_major_version
35
+ oci_minor_version = 1
36
+ else
37
+ if have_func('OCILobGetLength2')
38
+ oci_major_version = 10
39
+ oci_minor_version = 1
40
+ elsif have_func('OCIStmtPrepare2')
41
+ raise "Ruby-oci8 #{STACI::VERSION} doesn't support Oracle 9iR2. Use ruby-oci8 2.1.x instead."
42
+ elsif have_func('OCILogon2')
43
+ raise "Ruby-oci8 #{STACI::VERSION} doesn't support Oracle 9iR1. Use ruby-oci8 2.1.x instead."
44
+ elsif have_func('OCIEnvCreate')
45
+ raise "Ruby-oci8 #{STACI::VERSION} doesn't support Oracle 8i. Use ruby-oci8 2.0.x instead."
46
+ else
47
+ raise "Ruby-oci8 #{STACI::VERSION} doesn't support Oracle 8. Use ruby-oci8 2.0.x instead."
48
+ end
49
+ end
50
+ $defs = saved_defs
51
+
52
+ if with_config('oracle-version')
53
+ oraver = STACI::OracleVersion.new(with_config('oracle-version'))
54
+ else
55
+ oraver = STACI::OracleVersion.new(oci_major_version, oci_minor_version)
56
+ end
57
+ $defs << "-DORACLE_CLIENT_VERSION=#{format('0x%08x', oraver.to_i)}"
58
+
59
+ if with_config('runtime-check')
60
+ $defs << "-DRUNTIME_API_CHECK=1"
61
+ $libs = saved_libs
62
+ end
63
+
64
+ $objs = ["oci8lib.o", "env.o", "error.o", "oci8.o", "ocihandle.o",
65
+ "connection_pool.o",
66
+ "stmt.o", "bind.o", "metadata.o", "attr.o",
67
+ "lob.o", "oradate.o",
68
+ "ocinumber.o", "ocidatetime.o", "object.o", "apiwrap.o",
69
+ "encoding.o", "oranumber_util.o", "thread_util.o", "util.o"]
70
+
71
+ if RUBY_PLATFORM =~ /mswin32|cygwin|mingw32|bccwin32/
72
+ $defs << "-DUSE_WIN32_C"
73
+ $objs << "win32.o"
74
+ end
75
+
76
+ # Checking gcc or not
77
+ if oraconf.cc_is_gcc
78
+ $CFLAGS += " -Wall"
79
+ end
80
+
81
+ have_func("localtime_r")
82
+ have_func("dladdr")
83
+ have_func("dlmodinfo")
84
+ have_func("dlgetname")
85
+
86
+ # ruby 2.0.0 headers
87
+ have_header("ruby/thread.h")
88
+
89
+ have_func("rb_class_superclass", "ruby.h")
90
+ have_func("rb_thread_call_without_gvl", "ruby/thread.h")
91
+ have_func("rb_sym2str", "ruby.h")
92
+ if (defined? RUBY_ENGINE) && RUBY_ENGINE == 'rbx'
93
+ have_func("rb_str_buf_cat_ascii", "ruby.h")
94
+ have_func("rb_enc_str_buf_cat", "ruby.h")
95
+ end
96
+
97
+ ruby_engine = (defined? RUBY_ENGINE) ? RUBY_ENGINE : 'ruby'
98
+
99
+ so_basename = 'stacilib_'
100
+ case ruby_engine
101
+ when 'ruby'
102
+ # The extension library name includes the ruby ABI (application binary interface)
103
+ # version. It is for binary gems which contain more than one extension library
104
+ # and use correct one depending on the ABI version.
105
+ #
106
+ # ruby version | ABI version
107
+ # --------------+--------------
108
+ # 1.8.6 | 1.8
109
+ # 1.8.7 | 1.8
110
+ # --------------+--------------
111
+ # 1.9.0 | 1.9.0
112
+ # 1.9.1 | 1.9.1
113
+ # 1.9.2 | 1.9.1
114
+ # 1.9.3 | 1.9.1
115
+ # --------------+--------------
116
+ # 2.0.0 | 2.0.0
117
+ # --------------+--------------
118
+ # 2.1.0 | 2.1.0
119
+ # ... | ...
120
+ #
121
+ # The ABI version of ruby 2.1.1 will be 2.1.0.
122
+ # See "ABI Compatibility" in <URL:http://www.ruby-lang.org/en/news/2013/12/21/semantic-versioning-after-2-1-0/>.
123
+ #
124
+ case RUBY_VERSION
125
+ when /^1\.9\.0/
126
+ raise 'unsupported ruby version: 1.9.0'
127
+ when /^1\.9/
128
+ so_basename += '191'
129
+ when /^1\.8/
130
+ so_basename += '18'
131
+ else
132
+ so_basename += RUBY_VERSION.gsub(/(\d+)\.(\d+).(.*)/, '\1\20')
133
+ end
134
+ when 'rbx'
135
+ so_basename += 'rbx'
136
+ when 'jruby'
137
+ raise "Ruby-oci8 doesn't support jruby because its C extension support is in development in jruby 1.6 and deprecated in jruby 1.7."
138
+ when 'truffleruby'
139
+ so_basename += 'truffleruby'
140
+ else
141
+ raise 'unsupported ruby engine: ' + RUBY_ENGINE
142
+ end
143
+
144
+ print "checking for plthook... "
145
+ STDOUT.flush
146
+ case RUBY_PLATFORM
147
+ when /mswin32|cygwin|mingw32|bccwin32/
148
+ plthook_src = "plthook_win32.c"
149
+ when /darwin/
150
+ plthook_src = "plthook_osx.c"
151
+ else
152
+ plthook_src = "plthook_elf.c"
153
+ end
154
+ FileUtils.copy(File.dirname(__FILE__) + "/" + plthook_src, CONFTEST_C)
155
+ if xsystem(cc_command(""))
156
+ FileUtils.rm_f("#{CONFTEST}.#{$OBJEXT}")
157
+ puts plthook_src
158
+ $objs << plthook_src.gsub(/\.c$/, '.o')
159
+ $objs << "hook_funcs.o"
160
+ $defs << "-DHAVE_PLTHOOK"
161
+ have_library('dbghelp', 'ImageDirectoryEntryToData', ['windows.h', 'dbghelp.h']) if RUBY_PLATFORM =~ /cygwin/
162
+ $libs += ' -lws2_32' if RUBY_PLATFORM =~ /cygwin/
163
+ else
164
+ puts "no"
165
+ end
166
+
167
+ $defs << "-DInit_oci8lib=Init_#{so_basename}"
168
+ $defs << "-Doci8lib=#{so_basename}"
169
+ $defs << "-DOCI8LIB_VERSION=\\\"#{STACI::VERSION}\\\""
170
+ $defs << "-DCHAR_IS_NOT_A_SHORTCUT_TO_ID" if ruby_engine != 'ruby'
171
+
172
+ create_header()
173
+
174
+ # make dependency file
175
+ open("depend", "w") do |f|
176
+ extconf_opt = ''
177
+ ['oracle-version', 'runtime-check'].each do |arg|
178
+ opt = with_config(arg)
179
+ case opt
180
+ when String
181
+ extconf_opt += " --with-#{arg}=#{opt}"
182
+ when true
183
+ extconf_opt += " --with-#{arg}=yes"
184
+ when false
185
+ extconf_opt += " --with-#{arg}=no"
186
+ end
187
+ end
188
+ f.puts("Makefile: $(srcdir)/extconf.rb $(srcdir)/oraconf.rb")
189
+ f.puts("\t$(RUBY) $(srcdir)/extconf.rb#{extconf_opt}")
190
+ $objs.each do |obj|
191
+ f.puts("#{obj}: $(srcdir)/#{obj.sub(/\.o$/, ".c")} $(srcdir)/oci8.h apiwrap.h Makefile")
192
+ end
193
+ f.puts("apiwrap.c apiwrap.h: $(srcdir)/apiwrap.c.tmpl $(srcdir)/apiwrap.h.tmpl $(srcdir)/apiwrap.yml $(srcdir)/apiwrap.rb")
194
+ f.puts("\t$(RUBY) $(srcdir)/apiwrap.rb")
195
+ end
196
+
197
+ create_apiwrap()
198
+
199
+ case RUBY_PLATFORM
200
+ when /mingw32/
201
+ # Drop '-s' option from LDSHARED and explicitly run 'strip' to get the map file.
202
+ if RbConfig::MAKEFILE_CONFIG["LDSHARED"].gsub!(/-s\b/, '')
203
+ alias :oci8_configuration_orig :configuration
204
+ def configuration(*args)
205
+ prefix = [nil].pack('P').size == 4 ? '_' : ''
206
+ oci8_configuration_orig(*args) << <<EOS
207
+
208
+ # Dirty hack to get the map file.
209
+ all__: all
210
+ nm $(DLLIB) | grep ' [TtBb] #{prefix}[A-Za-z]' > $(TARGET).map
211
+ strip -s $(DLLIB)
212
+ EOS
213
+ end
214
+ end
215
+ end
216
+
217
+ create_makefile(so_basename)
218
+
219
+ exit 0