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
@@ -1,445 +0,0 @@
1
- /*
2
- oranumber.c - part of ruby-oci8
3
-
4
- Copyright (C) 2002 KUBO Takehiro <kubo@jiubao.org>
5
-
6
- =begin
7
- == OraNumber
8
- This is not a numeric class, so algebra operations and setter methods
9
- are not permitted, but a place to hold fetched date from Oracle server.
10
-
11
- In fact as matter, this is a test class to check the algorithm to
12
- convert Oracle internal number format to Ruby's number, which is internally used by,
13
- for example, ((<OCIStmt#attrGet|OCIHandle#attrGet>))(((<OCI_ATTR_MIN>))).
14
- =end
15
- */
16
- #include "oci8.h"
17
- #include "math.h"
18
-
19
- #define Get_Sign(on) ((on)->exponent & 0x80)
20
- #define Get_Exp_Part(on) ((on)->exponent & 0x7F)
21
- #define Get_Exponent(on) (Get_Sign(on) ? (Get_Exp_Part(on) - 65) : (~(Get_Exp_Part(on)) + 63))
22
- #define Get_Mantissa_At(on, i) (Get_Sign(on) ? (on)->mantissa[i] - 1 : 101 - (on)->mantissa[i])
23
-
24
- static int ora_number_from_str(ora_vnumber_t *ovn, unsigned char *buf, size_t len);
25
-
26
- static ora_vnumber_t *get_ora_number(VALUE self)
27
- {
28
- ora_vnumber_t *ovn;
29
- Data_Get_Struct(self, ora_vnumber_t, ovn);
30
- return ovn;
31
- }
32
-
33
- static VALUE ora_number_s_allocate(VALUE klass)
34
- {
35
- ora_vnumber_t *ovn;
36
- return Data_Make_Struct(klass, ora_vnumber_t, NULL, xfree, ovn);
37
- }
38
-
39
- #ifndef HAVE_RB_DEFINE_ALLOC_FUNC
40
- /* ruby 1.6 */
41
- static VALUE ora_number_s_new(int argc, VALUE *argv, VALUE klass)
42
- {
43
- VALUE obj = ora_number_s_allocate(klass);
44
- rb_obj_call_init(obj, argc, argv);
45
- return obj;
46
- }
47
- #endif
48
-
49
- /*
50
- =begin
51
- --- OraNumber.new()
52
- =end
53
- */
54
- static VALUE ora_number_initialize(int argc, VALUE *argv, VALUE self)
55
- {
56
- ora_vnumber_t *ovn = get_ora_number(self);
57
- volatile VALUE arg;
58
-
59
- rb_scan_args(argc, argv, "01", &arg);
60
- ovn->size = 1;
61
- ovn->num.exponent = 0x80;
62
- memset(ovn->num.mantissa, 0, sizeof(ovn->num.mantissa));
63
- if (argc == 1) {
64
- if (TYPE(arg) != T_STRING) {
65
- arg = rb_obj_as_string(arg);
66
- }
67
- if (ora_number_from_str(ovn, RSTRING_ORATEXT(arg), RSTRING_LEN(arg)) != 0) {
68
- rb_raise(rb_eArgError, "could not convert '%s' to OraNumber", RSTRING_PTR(arg));
69
- }
70
- }
71
- return Qnil;
72
- }
73
-
74
- static VALUE ora_number_initialize_copy(VALUE lhs, VALUE rhs)
75
- {
76
- ora_vnumber_t *l, *r;
77
-
78
- #ifdef HAVE_RB_DEFINE_ALLOC_FUNC
79
- /* ruby 1.8 */
80
- rb_obj_init_copy(lhs, rhs);
81
- #endif
82
- Data_Get_Struct(lhs, ora_vnumber_t, l);
83
- Data_Get_Struct(rhs, ora_vnumber_t, r);
84
- memcpy(l, r, sizeof(ora_vnumber_t));
85
- return lhs;
86
- }
87
-
88
- static VALUE ora_number_clone(VALUE self)
89
- {
90
- VALUE obj = ora_number_s_allocate(CLASS_OF(self));
91
- return ora_number_initialize_copy(obj, self);
92
- }
93
-
94
- /*
95
- =begin
96
- --- OraNumber#to_i()
97
- =end
98
- */
99
- static VALUE ora_number_to_i(VALUE self)
100
- {
101
- ora_vnumber_t *ovn = get_ora_number(self);
102
- unsigned char buf[ORA_NUMBER_BUF_SIZE];
103
-
104
- ora_number_to_str(buf, NULL, &(ovn->num), ovn->size);
105
- return rb_cstr2inum(TO_CHARPTR(buf), 10);
106
- }
107
-
108
- /*
109
- =begin
110
- --- OraNumber#to_f()
111
- =end
112
- */
113
- static VALUE ora_number_to_f(VALUE self)
114
- {
115
- ora_vnumber_t *ovn = get_ora_number(self);
116
- unsigned char buf[ORA_NUMBER_BUF_SIZE];
117
-
118
- ora_number_to_str(buf, NULL, &(ovn->num), ovn->size);
119
- return rb_float_new(rb_cstr_to_dbl(TO_CHARPTR(buf), Qfalse));
120
- }
121
-
122
- /*
123
- =begin
124
- --- OraNumber#to_s()
125
- =end
126
- */
127
- static VALUE ora_number_to_s(VALUE self)
128
- {
129
- ora_vnumber_t *ovn = get_ora_number(self);
130
- unsigned char buf[ORA_NUMBER_BUF_SIZE];
131
- size_t len;
132
-
133
- ora_number_to_str(buf, &len, &(ovn->num), ovn->size);
134
- return rb_str_new(TO_CHARPTR(buf), len);
135
- }
136
-
137
- static VALUE ora_number_uminus(VALUE self)
138
- {
139
- ora_vnumber_t *ovn = get_ora_number(self);
140
- VALUE obj;
141
- int i;
142
-
143
- if (ovn->num.exponent == 0x80)
144
- return self;
145
- obj = ora_number_clone(self);
146
- ovn = get_ora_number(obj);
147
- ovn->num.exponent = ~(ovn->num.exponent);
148
- for (i = 0;i < ovn->size - 1;i++)
149
- ovn->num.mantissa[i] = 102 - ovn->num.mantissa[i];
150
- if (Get_Sign(&(ovn->num))) {
151
- if (ovn->size != 21 || ovn->num.mantissa[19] == 0x00) {
152
- ovn->size--;
153
- }
154
- } else {
155
- if (ovn->size != 21) {
156
- ovn->num.mantissa[ovn->size - 1] = 102;
157
- ovn->size++;
158
- }
159
- }
160
- return obj;
161
- }
162
-
163
- static VALUE ora_number_dump(int argc, VALUE *argv, VALUE self)
164
- {
165
- ora_vnumber_t *ovn = get_ora_number(self);
166
- unsigned char i;
167
- for (i = ovn->size - 1; i < 20; i++) {
168
- ovn->num.mantissa[i] = 0;
169
- }
170
- return rb_str_new((const char*)ovn, sizeof(ora_vnumber_t));
171
- }
172
-
173
- static VALUE ora_number_s_load(VALUE klass, VALUE str)
174
- {
175
- ora_vnumber_t *ovn;
176
- VALUE obj;
177
-
178
- Check_Type(str, T_STRING);
179
- if (RSTRING_LEN(str) != sizeof(ora_vnumber_t)) {
180
- rb_raise(rb_eTypeError, "marshaled OraNumber format differ");
181
- }
182
- obj = ora_number_s_allocate(klass);
183
- ovn = get_ora_number(obj);
184
- memcpy(ovn, RSTRING_PTR(str), sizeof(ora_vnumber_t));
185
- return obj;
186
- }
187
-
188
- void Init_ora_number(void)
189
- {
190
- #ifdef HAVE_RB_DEFINE_ALLOC_FUNC
191
- /* ruby 1.8 */
192
- rb_define_alloc_func(cOraNumber, RUBY_METHOD_FUNC(ora_number_s_allocate));
193
- rb_define_method(cOraNumber, "initialize", ora_number_initialize, -1);
194
- rb_define_method(cOraNumber, "initialize_copy", ora_number_initialize_copy, 1);
195
- #else
196
- /* ruby 1.6 */
197
- rb_define_singleton_method(cOraNumber, "new", ora_number_s_new, -1);
198
- rb_define_method(cOraNumber, "initialize", ora_number_initialize, -1);
199
- rb_define_method(cOraNumber, "clone", ora_number_clone, 0);
200
- rb_define_method(cOraNumber, "dup", ora_number_clone, 0);
201
- #endif
202
-
203
- rb_define_method(cOraNumber, "to_i", ora_number_to_i, 0);
204
- rb_define_method(cOraNumber, "to_f", ora_number_to_f, 0);
205
- rb_define_method(cOraNumber, "to_s", ora_number_to_s, 0);
206
- rb_define_method(cOraNumber, "-@", ora_number_uminus, 0);
207
-
208
- rb_define_method(cOraNumber, "_dump", ora_number_dump, -1);
209
- rb_define_singleton_method(cOraNumber, "_load", ora_number_s_load, 1);
210
- }
211
-
212
- void ora_number_to_str(unsigned char *buf, size_t *lenp, ora_number_t *on, unsigned char size)
213
- {
214
- int exponent;
215
- int len = 0;
216
- int mentissa_size;
217
- int i, j;
218
-
219
- if (on->exponent == 0x80) {
220
- buf[0] = '0';
221
- buf[1] = '\0';
222
- if (lenp != NULL)
223
- *lenp = 1;
224
- return;
225
- }
226
-
227
- if (Get_Sign(on)) {
228
- mentissa_size = size - 1;
229
- } else {
230
- if (size == 21 && on->mantissa[19] != 102)
231
- mentissa_size = 20;
232
- else
233
- mentissa_size = size - 2;
234
- buf[len++] = '-';
235
- }
236
- exponent = Get_Exponent(on);
237
- if (exponent < 0) {
238
- buf[len++] = '0';
239
- buf[len++] = '.';
240
- for (i = exponent * 2;i < -2;i++)
241
- buf[len++] = '0';
242
- for (i = 0;i < mentissa_size;i++) {
243
- j = Get_Mantissa_At(on, i);
244
- buf[len++] = j / 10 + '0';
245
- if (i != mentissa_size - 1 || j % 10 != 0)
246
- buf[len++] = j % 10 + '0';
247
- }
248
- } else {
249
- for (i = 0;i < mentissa_size;i++) {
250
- j = Get_Mantissa_At(on, i);
251
- if (i == exponent + 1) {
252
- buf[len++] = '.';
253
- }
254
- if (i != 0 || j / 10 != 0)
255
- buf[len++] = j / 10 + '0';
256
- if ((i < exponent + 1) /* integer part */
257
- || (i != mentissa_size - 1 || j % 10 != 0) /* decimal fraction */)
258
- buf[len++] = j % 10 + '0';
259
- }
260
- for (;i <= exponent;i++) {
261
- buf[len++] = '0';
262
- buf[len++] = '0';
263
- }
264
- }
265
- buf[len] = '\0';
266
- if (lenp != NULL)
267
- *lenp = len;
268
- }
269
-
270
- static int ora_number_from_str(ora_vnumber_t *ovn, unsigned char *buf, size_t len)
271
- {
272
- unsigned char work[80];
273
- int sign = 1;
274
- int state = 0;
275
- int i, j;
276
- int iidx; /* index of integer part */
277
- int fidx; /* index of fraction part */
278
- unsigned char *p;
279
- int mantissa_size;
280
- int exponent;
281
-
282
- if (len > ORA_NUMBER_BUF_SIZE) {
283
- return 1;
284
- }
285
- /* [ \t]*(+|-)[0-9]*(.[0-9]*) */
286
- for (i = iidx = fidx = 0; i < len; i++) {
287
- unsigned char uc = buf[i];
288
- switch (state) {
289
- case 0:
290
- /* [ \t]*(+|-)[0-9]*(.[0-9]*) */
291
- /* ^ */
292
- switch (uc) {
293
- case ' ':
294
- case '\t':
295
- /* [ \t]*(+|-)[0-9]*(.[0-9]*) */
296
- /* ^ */
297
- break;
298
- case '-':
299
- sign = -1;
300
- state = 1;
301
- /* [ \t]*(+|-)[0-9]*(.[0-9]*) */
302
- /* ^ */
303
- break;
304
- case '+':
305
- case '0':
306
- state = 1;
307
- /* [ \t]*(+|-)[0-9]*(.[0-9]*) */
308
- /* ^ */
309
- break;
310
- case '1':
311
- case '2':
312
- case '3':
313
- case '4':
314
- case '5':
315
- case '6':
316
- case '7':
317
- case '8':
318
- case '9':
319
- work[iidx++] = uc - '0';
320
- state = 1;
321
- /* [ \t]*(+|-)[0-9]*(.[0-9]*) */
322
- /* ^ */
323
- break;
324
- case '.':
325
- state = 2;
326
- /* [ \t]*(+|-)[0-9]*(.[0-9]*) */
327
- /* ^ */
328
- break;
329
- default:
330
- return 1;
331
- }
332
- break;
333
- case 1:
334
- /* [ \t]*(+|-)[0-9]*(.[0-9]*) */
335
- /* ^ */
336
- switch (uc) {
337
- case '0':
338
- case '1':
339
- case '2':
340
- case '3':
341
- case '4':
342
- case '5':
343
- case '6':
344
- case '7':
345
- case '8':
346
- case '9':
347
- if (iidx > sizeof(work))
348
- return 1;
349
- work[iidx++] = uc - '0';
350
- /* [ \t]*(+|-)[0-9]*(.[0-9]*) */
351
- /* ^ */
352
- break;
353
- case '.':
354
- state = 2;
355
- /* [ \t]*(+|-)[0-9]*(.[0-9]*) */
356
- /* ^ */
357
- break;
358
- default:
359
- return 1;
360
- }
361
- break;
362
- case 2:
363
- /* [ \t]*(+|-)[0-9]*(.[0-9]*) */
364
- /* ^ */
365
- switch (uc) {
366
- case '0':
367
- case '1':
368
- case '2':
369
- case '3':
370
- case '4':
371
- case '5':
372
- case '6':
373
- case '7':
374
- case '8':
375
- case '9':
376
- if (iidx + fidx > sizeof(work))
377
- return 1;
378
- work[iidx + fidx++] = uc - '0';
379
- /* [ \t]*(+|-)[0-9]*(.[0-9]*) */
380
- /* ^ */
381
- break;
382
- default:
383
- return 1;
384
- }
385
- break;
386
- }
387
- }
388
- /* convert to 100-base number */
389
- if (iidx & 1) {
390
- i = j = 1;
391
- } else {
392
- i = j = 0;
393
- }
394
- if (fidx & 1) {
395
- if (iidx + fidx > sizeof(work))
396
- return 1;
397
- work[iidx + fidx++] = 0;
398
- }
399
- while (i < iidx + fidx) {
400
- work[j++] = work[i] * 10 + work[i + 1];
401
- i += 2;
402
- }
403
- iidx = (iidx + 1) >> 1;
404
- fidx >>= 1;
405
- /* ... */
406
- p = work;
407
- mantissa_size = iidx + fidx;
408
- exponent = (int)iidx - 1;
409
- /* delete leading zeros */
410
- while (mantissa_size > 0 && p[0] == 0) {
411
- mantissa_size--;
412
- exponent--;
413
- p++;
414
- }
415
- /* delete trailing zeros */
416
- while (mantissa_size > 0 && p[mantissa_size - 1] == 0) {
417
- mantissa_size--;
418
- }
419
- /* check size */
420
- if (mantissa_size > sizeof(ovn->num.mantissa))
421
- return 1;
422
- if (mantissa_size == 0) {
423
- ovn->size = 1;
424
- ovn->num.exponent = 0x80;
425
- return 0;
426
- }
427
- if (sign > 0) {
428
- ovn->size = mantissa_size + 1;
429
- ovn->num.exponent = 0x80 + exponent + 65;
430
- for (i = 0; i < mantissa_size; i++) {
431
- ovn->num.mantissa[i] = p[i] + 1;
432
- }
433
- } else {
434
- ovn->size = mantissa_size + 1;
435
- ovn->num.exponent = 62 - exponent;
436
- for (i = 0; i < mantissa_size; i++) {
437
- ovn->num.mantissa[i] = 101 - p[i];
438
- }
439
- if (mantissa_size < 20) {
440
- ovn->size++;
441
- ovn->num.mantissa[i] = 102;
442
- }
443
- }
444
- return 0;
445
- }
@@ -1,37 +0,0 @@
1
- /*
2
- param.c - part of ruby-oci8
3
-
4
- Copyright (C) 2002 KUBO Takehiro <kubo@jiubao.org>
5
-
6
- =begin
7
- == OCIParam
8
- super class: ((<OCIDescriptor>))
9
- =end
10
- */
11
- #include "oci8.h"
12
-
13
- void Init_oci8_param(void)
14
- {
15
- rb_define_method(cOCIParam, "paramGet", oci8_param_get, 1);
16
- }
17
-
18
- VALUE oci8_param_get(VALUE self, VALUE pos)
19
- {
20
- oci8_handle_t *h;
21
- OCIParam *parmhp = NULL;
22
- oci8_handle_t *parmh;
23
- VALUE obj;
24
- sword rv;
25
-
26
- Get_Handle(self, h);
27
- Check_Type(pos, T_FIXNUM);
28
- rv = OCIParamGet(h->hp, h->type, h->errhp, (dvoid *)&parmhp, FIX2INT(pos));
29
- if (rv != OCI_SUCCESS) {
30
- oci8_raise(h->errhp, rv, NULL);
31
- }
32
- parmh = oci8_make_handle(OCI_DTYPE_PARAM, parmhp, h->errhp, h, 0);
33
- parmh->u.param.is_implicit = (h->type == OCI_HTYPE_STMT) ? 1 : 0;
34
-
35
- obj = parmh->self;
36
- return obj;
37
- }