ruby-oci8 2.1.0 → 2.1.1

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.
data/ext/oci8/oradate.c CHANGED
@@ -2,7 +2,7 @@
2
2
  /*
3
3
  * oradate.c
4
4
  *
5
- * Copyright (C) 2002-2008 KUBO Takehiro <kubo@jiubao.org>
5
+ * Copyright (C) 2002-2012 KUBO Takehiro <kubo@jiubao.org>
6
6
  *
7
7
  * date and time between 4712 B.C. and 9999 A.D.
8
8
  */
@@ -14,9 +14,8 @@ static VALUE cOraDate;
14
14
  /*
15
15
  * Document-class: OraDate
16
16
  *
17
- * ruby class compatible with Oracle <tt>DATE</tt> data type.
18
- * Date and time between 4712 B.C. and 9999 A.D.
19
- *
17
+ * OraDate is the ruby class compatible with Oracle <tt>DATE</tt> data type.
18
+ * The range is between 4712 B.C. and 9999 A.D.
20
19
  */
21
20
  struct ora_date {
22
21
  unsigned char century;
@@ -79,10 +78,15 @@ static VALUE ora_date_s_allocate(VALUE klass)
79
78
  }
80
79
 
81
80
  /*
82
- * call-seq:
83
- * OraDate.new(year = 1, month = 1, day = 1, hour = 0, min = 0, sec = 0) -> oradate
81
+ * call-seq:
82
+ * initialize(year = 1, month = 1, day = 1, hour = 0, min = 0, sec = 0)
83
+ *
84
+ * Returns an <code>OraDate</code> object initialized to the specified date and time.
84
85
  *
85
- * Returns an <code>OraDate</code> object initialized to the specified date and time.
86
+ * @example
87
+ * OraDate.new # => 0001-01-01 00:00:00
88
+ * OraDate.new(2012) # => 2012-01-01 00:00:00
89
+ * OraDate.new(2012, 3, 4) # => 2012-03-04 00:00:00
86
90
  */
87
91
  static VALUE ora_date_initialize(int argc, VALUE *argv, VALUE self)
88
92
  {
@@ -138,7 +142,9 @@ static VALUE ora_date_initialize(int argc, VALUE *argv, VALUE self)
138
142
  return Qnil;
139
143
  }
140
144
 
141
- /* :nodoc: */
145
+ /*
146
+ * @private
147
+ */
142
148
  static VALUE ora_date_initialize_copy(VALUE lhs, VALUE rhs)
143
149
  {
144
150
  ora_date_t *l, *r;
@@ -151,11 +157,10 @@ static VALUE ora_date_initialize_copy(VALUE lhs, VALUE rhs)
151
157
  }
152
158
 
153
159
  /*
154
- * call-seq:
155
- * OraDate.now() -> oradate
160
+ * Returns an <code>OraDate</code> object initialized to the
161
+ * current local time.
156
162
  *
157
- * Returns an <code>OraDate</code> object initialized to the
158
- * current local time.
163
+ * @return [OraDate]
159
164
  */
160
165
  static VALUE ora_date_s_now(int argc, VALUE *argv, VALUE klass)
161
166
  {
@@ -183,11 +188,10 @@ static VALUE ora_date_s_now(int argc, VALUE *argv, VALUE klass)
183
188
  }
184
189
 
185
190
  /*
186
- * call-seq:
187
- * oradate.to_s -> string
191
+ * Returns a string representing <i>self</i>.
192
+ * The string format is 'yyyy/mm/dd hh:mi:ss'.
188
193
  *
189
- * Returns a string representing <i>oradate</i>.
190
- * The string format is 'yyyy/mm/dd hh:mi:ss'.
194
+ * @return [OraDate]
191
195
  */
192
196
  static VALUE ora_date_to_s(VALUE self)
193
197
  {
@@ -201,11 +205,9 @@ static VALUE ora_date_to_s(VALUE self)
201
205
  }
202
206
 
203
207
  /*
204
- * call-seq:
205
- * oradate.to_a -> array
208
+ * Returns a 6-element <i>array</i> of year, month, day, hour, minute and second.
206
209
  *
207
- * Returns a 6-element <i>array</i> of values for <i>oradate</i>:
208
- * {<code>[year, month, day, hour, minute, second]</code>}.
210
+ * @return [Array]
209
211
  */
210
212
  static VALUE ora_date_to_a(VALUE self)
211
213
  {
@@ -223,10 +225,9 @@ static VALUE ora_date_to_a(VALUE self)
223
225
  }
224
226
 
225
227
  /*
226
- * call-seq:
227
- * oradate.year -> fixnum
228
+ * Returns the year field of <i>self</i>.
228
229
  *
229
- * Returns the year (-4712..9999) for <i>oradate</i>.
230
+ * @return [Fixnum]
230
231
  */
231
232
  static VALUE ora_date_year(VALUE self)
232
233
  {
@@ -237,10 +238,12 @@ static VALUE ora_date_year(VALUE self)
237
238
  }
238
239
 
239
240
  /*
240
- * call-seq:
241
- * oradate.year = fixnum
241
+ * call-seq:
242
+ * year = num
242
243
  *
243
- * Sets the year (-4712..9999) for <i>oradate</i>.
244
+ * Assigns <i>num</i> to the year field of <i>self</i>.
245
+ *
246
+ * @param [Fixnum] number between -4712 and 9999
244
247
  */
245
248
  static VALUE ora_date_set_year(VALUE self, VALUE val)
246
249
  {
@@ -255,10 +258,10 @@ static VALUE ora_date_set_year(VALUE self, VALUE val)
255
258
  }
256
259
 
257
260
  /*
258
- * call-seq:
259
- * oradate.month -> fixnum
261
+ * Returns the month field of <i>self</i>.
262
+ * The month starts with one.
260
263
  *
261
- * Returns the month of the year (1..12) for <i>oradate</i>.
264
+ * @return [Fixnum]
262
265
  */
263
266
  static VALUE ora_date_month(VALUE self)
264
267
  {
@@ -269,10 +272,13 @@ static VALUE ora_date_month(VALUE self)
269
272
  }
270
273
 
271
274
  /*
272
- * call-seq:
273
- * oradate.month = fixnum
275
+ * call-seq:
276
+ * month = num
277
+ *
278
+ * Assigns <i>num</i> to the month field of <i>self</i>.
279
+ * The month starts with one.
274
280
  *
275
- * Sets the month of the year (1..12) for <i>oradate</i>.
281
+ * @param [Fixnum] number between 1 and 12
276
282
  */
277
283
  static VALUE ora_date_set_month(VALUE self, VALUE val)
278
284
  {
@@ -287,10 +293,9 @@ static VALUE ora_date_set_month(VALUE self, VALUE val)
287
293
  }
288
294
 
289
295
  /*
290
- * call-seq:
291
- * oradate.day -> fixnum
296
+ * Returns the day of month field of <i>self</i>.
292
297
  *
293
- * Returns the day of the month (1..31) for <i>oradate</i>.
298
+ * @return [Fixnum]
294
299
  */
295
300
  static VALUE ora_date_day(VALUE self)
296
301
  {
@@ -301,10 +306,12 @@ static VALUE ora_date_day(VALUE self)
301
306
  }
302
307
 
303
308
  /*
304
- * call-seq:
305
- * oradate.day = fixnum
309
+ * call-seq:
310
+ * day = num
311
+ *
312
+ * Assigns <i>num</i> to the day of month field of <i>self</i>.
306
313
  *
307
- * Sets the day of the month (1..31) for <i>oradate</i>.
314
+ * @param [Fixnum] number between 1 and 31
308
315
  */
309
316
  static VALUE ora_date_set_day(VALUE self, VALUE val)
310
317
  {
@@ -319,10 +326,9 @@ static VALUE ora_date_set_day(VALUE self, VALUE val)
319
326
  }
320
327
 
321
328
  /*
322
- * call-seq:
323
- * oradate.hour -> fixnum
329
+ * Returns the hour field of <i>self</i>.
324
330
  *
325
- * Returns the hour of the day (0..23) for <i>oradate</i>.
331
+ * @return [Fixnum]
326
332
  */
327
333
  static VALUE ora_date_hour(VALUE self)
328
334
  {
@@ -333,10 +339,12 @@ static VALUE ora_date_hour(VALUE self)
333
339
  }
334
340
 
335
341
  /*
336
- * call-seq:
337
- * oradate.hour = fixnum
342
+ * call-seq:
343
+ * hour = num
338
344
  *
339
- * Sets the hour of the day (0..23) for <i>oradate</i>.
345
+ * Assigns <i>num</i> to the hour field of <i>self</i>.
346
+ *
347
+ * @param [Fixnum] number between 0 and 23
340
348
  */
341
349
  static VALUE ora_date_set_hour(VALUE self, VALUE val)
342
350
  {
@@ -351,10 +359,9 @@ static VALUE ora_date_set_hour(VALUE self, VALUE val)
351
359
  }
352
360
 
353
361
  /*
354
- * call-seq:
355
- * oradate.minute -> fixnum
362
+ * Returns the minute field of <i>self</i>.
356
363
  *
357
- * Returns the minute of the hour (0..59) for <i>oradate</i>.
364
+ * @return [Fixnum]
358
365
  */
359
366
  static VALUE ora_date_minute(VALUE self)
360
367
  {
@@ -365,10 +372,12 @@ static VALUE ora_date_minute(VALUE self)
365
372
  }
366
373
 
367
374
  /*
368
- * call-seq:
369
- * oradate.minute = fixnum
375
+ * call-seq:
376
+ * minute = num
377
+ *
378
+ * Assigns <i>num</i> to the minute field of <i>self</i>.
370
379
  *
371
- * Sets the minute of the hour (0..59) for <i>oradate</i>.
380
+ * @param [Fixnum] number between 0 and 59
372
381
  */
373
382
  static VALUE ora_date_set_minute(VALUE self, VALUE val)
374
383
  {
@@ -383,10 +392,9 @@ static VALUE ora_date_set_minute(VALUE self, VALUE val)
383
392
  }
384
393
 
385
394
  /*
386
- * call-seq:
387
- * oradate.second -> fixnum
395
+ * Returns the second field of <i>self</i>.
388
396
  *
389
- * Returns the second of the minute (0..59) for <i>oradate</i>.
397
+ * @return [Fixnum]
390
398
  */
391
399
  static VALUE ora_date_second(VALUE self)
392
400
  {
@@ -397,10 +405,12 @@ static VALUE ora_date_second(VALUE self)
397
405
  }
398
406
 
399
407
  /*
400
- * call-seq:
401
- * oradate.second = fixnum
408
+ * call-seq:
409
+ * second = num
410
+ *
411
+ * Assigns <i>num</i> to the second field of <i>self</i>.
402
412
  *
403
- * Sets the second of the minute (0..59) for <i>oradate</i>.
413
+ * @param [Fixnum] number between 0 and 59
404
414
  */
405
415
  static VALUE ora_date_set_second(VALUE self, VALUE val)
406
416
  {
@@ -415,13 +425,13 @@ static VALUE ora_date_set_second(VALUE self, VALUE val)
415
425
  }
416
426
 
417
427
  /*
418
- * call-seq:
419
- * oradate.trunc
428
+ * Truncates hour, minute and second fields to zero.
420
429
  *
421
- * Truncates hour, minute and second to zero for <i>oradate</i>.
430
+ * @example
431
+ * oradate = OraDate.now # => 2008/07/17 11:07:30
432
+ * oradate.trunc # => 2008/07/17 00:00:00
422
433
  *
423
- * oradate = OraDate.now # 2008/07/17 11:07:30
424
- * oradate.trunc # 2008/07/17 00:00:00
434
+ * @return [OraDate]
425
435
  */
426
436
  static VALUE ora_date_trunc(VALUE self)
427
437
  {
@@ -435,12 +445,11 @@ static VALUE ora_date_trunc(VALUE self)
435
445
  }
436
446
 
437
447
  /*
438
- * call-seq:
439
- * oradate1 <=> oradate2 -> -1, 0, +1
448
+ * call-seq:
449
+ * self <=> other
440
450
  *
441
- * Comparison---Compares <i>oradate1</i> with <i>oradate2</i>.
442
- * Other comparison operators are available because
443
- * <code>Comparable</code> module is included.
451
+ * Returns -1, 0, or +1 depending on whether <i>self</i> is less than,
452
+ * equal to, or greater than <i>other</i>.
444
453
  */
445
454
  static VALUE ora_date_cmp(VALUE self, VALUE val)
446
455
  {
@@ -465,7 +474,9 @@ static VALUE ora_date_cmp(VALUE self, VALUE val)
465
474
  return INT2FIX(0);
466
475
  }
467
476
 
468
- /* :nodoc: */
477
+ /*
478
+ * @private
479
+ */
469
480
  static VALUE ora_date_hash(VALUE self)
470
481
  {
471
482
  ora_date_t *od;
@@ -483,10 +494,11 @@ static VALUE ora_date_hash(VALUE self)
483
494
  }
484
495
 
485
496
  /*
486
- * call-seq:
487
- * oradate._dump -> string
497
+ * Serializes <i>self</i>.
498
+ * This method is called by Marshal.dump().
488
499
  *
489
- * Dumps <i>oradate</i> for marshaling.
500
+ * @return [String] a byte stream
501
+ * @see OraDate._load
490
502
  */
491
503
  static VALUE ora_date_dump(int argc, VALUE *argv, VALUE self)
492
504
  {
@@ -496,10 +508,15 @@ static VALUE ora_date_dump(int argc, VALUE *argv, VALUE self)
496
508
  }
497
509
 
498
510
  /*
499
- * call-seq:
500
- * OraDate._load(string) -> oradate
511
+ * call-seq:
512
+ * _load(bytes)
513
+ *
514
+ * Restores a byte stream serialized by {OraDate#_dump}.
515
+ * This method is called by Marshal.load() to deserialize a byte stream
516
+ * created by Marshal.dump().
501
517
  *
502
- * Unmarshals a dumped <code>OraDate</code> object.
518
+ * @param [String] bytes a byte stream
519
+ * @return [OraDate] an deserialized object
503
520
  */
504
521
  static VALUE ora_date_s_load(VALUE klass, VALUE str)
505
522
  {
@@ -516,9 +533,9 @@ static VALUE ora_date_s_load(VALUE klass, VALUE str)
516
533
  }
517
534
 
518
535
  /*
519
- * Document-class: OCI8::BindType::OraDate
536
+ * Document-class: OCI8::BindType::OraDate
520
537
  *
521
- * This is a helper class to bind OraDate as Oracle's <tt>DATE</tt> datatype.
538
+ * This is a helper class to bind OraDate as Oracle's <tt>DATE</tt> datatype.
522
539
  *
523
540
  */
524
541
  static VALUE bind_oradate_get(oci8_bind_t *obind, void *data, void *null_struct)
data/ext/oci8/stmt.c CHANGED
@@ -35,6 +35,7 @@ typedef struct {
35
35
  VALUE svc;
36
36
  VALUE binds;
37
37
  VALUE defns;
38
+ int use_stmt_release;
38
39
  } oci8_stmt_t;
39
40
 
40
41
  static void oci8_stmt_mark(oci8_base_t *base)
@@ -51,6 +52,11 @@ static void oci8_stmt_free(oci8_base_t *base)
51
52
  stmt->svc = Qnil;
52
53
  stmt->binds = Qnil;
53
54
  stmt->defns = Qnil;
55
+ if (stmt->use_stmt_release) {
56
+ OCIStmtRelease(base->hp.stmt, oci8_errhp, NULL, 0, OCI_DEFAULT);
57
+ base->type = 0;
58
+ stmt->use_stmt_release = 0;
59
+ }
54
60
  }
55
61
 
56
62
  static oci8_base_vtable_t oci8_stmt_vtable = {
@@ -62,20 +68,38 @@ static oci8_base_vtable_t oci8_stmt_vtable = {
62
68
  static VALUE oci8_stmt_initialize(int argc, VALUE *argv, VALUE self)
63
69
  {
64
70
  oci8_stmt_t *stmt = DATA_PTR(self);
71
+ oci8_svcctx_t *svcctx;
65
72
  VALUE svc;
66
73
  VALUE sql;
67
74
  sword rv;
68
75
 
69
76
  rb_scan_args(argc, argv, "11", &svc, &sql);
70
77
 
71
- oci8_check_pid_consistency(oci8_get_svcctx(svc));
72
- if (argc > 1)
78
+ svcctx = oci8_get_svcctx(svc);
79
+ oci8_check_pid_consistency(svcctx);
80
+ if (argc > 1 && oracle_client_version >= ORAVER_9_2) {
73
81
  OCI8SafeStringValue(sql);
74
82
 
75
- rv = OCIHandleAlloc(oci8_envhp, &stmt->base.hp.ptr, OCI_HTYPE_STMT, 0, NULL);
76
- if (rv != OCI_SUCCESS)
77
- oci8_env_raise(oci8_envhp, rv);
78
- stmt->base.type = OCI_HTYPE_STMT;
83
+ rv = OCIStmtPrepare2(svcctx->base.hp.svc, &stmt->base.hp.stmt, oci8_errhp, RSTRING_ORATEXT(sql), RSTRING_LEN(sql), NULL, 0, OCI_NTV_SYNTAX, OCI_DEFAULT);
84
+ if (IS_OCI_ERROR(rv)) {
85
+ chker2(rv, &svcctx->base);
86
+ }
87
+ stmt->base.type = OCI_HTYPE_STMT;
88
+ stmt->use_stmt_release = 1;
89
+ } else {
90
+ rv = OCIHandleAlloc(oci8_envhp, &stmt->base.hp.ptr, OCI_HTYPE_STMT, 0, NULL);
91
+ if (rv != OCI_SUCCESS) {
92
+ oci8_env_raise(oci8_envhp, rv);
93
+ }
94
+ stmt->base.type = OCI_HTYPE_STMT;
95
+ if (argc > 1) {
96
+ OCI8SafeStringValue(sql);
97
+ rv = OCIStmtPrepare(stmt->base.hp.stmt, oci8_errhp, RSTRING_ORATEXT(sql), RSTRING_LEN(sql), OCI_NTV_SYNTAX, OCI_DEFAULT);
98
+ if (IS_OCI_ERROR(rv)) {
99
+ chker3(rv, &svcctx->base, stmt->base.hp.stmt);
100
+ }
101
+ }
102
+ }
79
103
  stmt->svc = svc;
80
104
  stmt->binds = rb_hash_new();
81
105
  stmt->defns = rb_ary_new();
@@ -84,12 +108,6 @@ static VALUE oci8_stmt_initialize(int argc, VALUE *argv, VALUE self)
84
108
  rb_ivar_set(stmt->base.self, id_at_con, svc);
85
109
  rb_ivar_set(stmt->base.self, id_at_max_array_size, Qnil);
86
110
 
87
- if (argc > 1) {
88
- rv = OCIStmtPrepare(stmt->base.hp.stmt, oci8_errhp, RSTRING_ORATEXT(sql), RSTRING_LEN(sql), OCI_NTV_SYNTAX, OCI_DEFAULT);
89
- if (IS_OCI_ERROR(rv)) {
90
- chker3(rv, &stmt->base, stmt->base.hp.stmt);
91
- }
92
- }
93
111
  oci8_link_to_parent((oci8_base_t*)stmt, (oci8_base_t*)DATA_PTR(svc));
94
112
  return Qnil;
95
113
  }
data/ext/oci8/win32.c CHANGED
@@ -13,6 +13,14 @@
13
13
  #endif
14
14
  #include <windows.h>
15
15
 
16
+ /*
17
+ * Document-module: OCI8::Win32Util
18
+ *
19
+ * Windows specific utility module.
20
+ *
21
+ * @private
22
+ */
23
+
16
24
  NORETURN(static void raise_error(void));
17
25
 
18
26
  static void raise_error(void)
@@ -33,6 +41,11 @@ static void raise_error(void)
33
41
  rb_raise(rb_eRuntimeError, "%s", msg);
34
42
  }
35
43
 
44
+ /*
45
+ * Returns the full path of OCI.DLL used by the current process.
46
+ *
47
+ * @return [String]
48
+ */
36
49
  static VALUE dll_path(VALUE module)
37
50
  {
38
51
  HMODULE hModule;
@@ -120,6 +133,15 @@ static VALUE enum_homes_ensure(enum_homes_arg_t *arg)
120
133
  return Qnil;
121
134
  }
122
135
 
136
+ /*
137
+ * Enumerates full clients' Oracle homes and NLS_LANG parameters
138
+ * registerd in the Windows registry.
139
+ *
140
+ * @yield [oracle_home, nls_lang]
141
+ * @yieldparam [String] oracle_home
142
+ * @yieldparam [String] nls_lang
143
+ * @return [nil]
144
+ */
123
145
  static VALUE enum_homes(VALUE module)
124
146
  {
125
147
  enum_homes_arg_t arg;