ruby-oci8 2.0.3 → 2.0.4

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.
@@ -0,0 +1,24 @@
1
+ /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
2
+ /*
3
+ * oranumber_util.h - part of ruby-oci8
4
+ *
5
+ * Copyright (C) 2010 KUBO Takehiro <kubo@jiubao.org>
6
+ */
7
+ #ifndef ORANUMBER_UTIL_H
8
+ #define ORANUMBER_UTIL_H 1
9
+ #include <orl.h>
10
+
11
+ #define ORANUMBER_INVALID_INTERNAL_FORMAT -1
12
+ #define ORANUMBER_TOO_SHORT_BUFFER -2
13
+
14
+ #define ORANUMBER_SUCCESS 0
15
+ #define ORANUMBER_INVALID_NUMBER 1722
16
+ #define ORANUMBER_NUMERIC_OVERFLOW 1426
17
+
18
+ int oranumber_to_str(const OCINumber *on, char *buf, int buflen);
19
+ int oranumber_from_str(OCINumber *on, const char *buf, int buflen);
20
+
21
+ #define ORANUMBER_DUMP_BUF_SIZ 99
22
+ int oranumber_dump(const OCINumber *on, char *buf);
23
+
24
+ #endif
@@ -342,16 +342,18 @@ static VALUE oci8_stmt_do_fetch(oci8_stmt_t *stmt, oci8_svcctx_t *svcctx)
342
342
  oci8_bind_t *obind;
343
343
  const oci8_bind_class_t *bind_class;
344
344
 
345
- obind = (oci8_bind_t *)stmt->base.children;
346
- do {
347
- if (obind->base.type == OCI_HTYPE_DEFINE) {
348
- bind_class = (const oci8_bind_class_t *)obind->base.klass;
349
- if (bind_class->pre_fetch_hook != NULL) {
350
- bind_class->pre_fetch_hook(obind, stmt->svc);
345
+ if (stmt->base.children != NULL) {
346
+ obind = (oci8_bind_t *)stmt->base.children;
347
+ do {
348
+ if (obind->base.type == OCI_HTYPE_DEFINE) {
349
+ bind_class = (const oci8_bind_class_t *)obind->base.klass;
350
+ if (bind_class->pre_fetch_hook != NULL) {
351
+ bind_class->pre_fetch_hook(obind, stmt->svc);
352
+ }
351
353
  }
352
- }
353
- obind = (oci8_bind_t *)obind->base.next;
354
- } while (obind != (oci8_bind_t*)stmt->base.children);
354
+ obind = (oci8_bind_t *)obind->base.next;
355
+ } while (obind != (oci8_bind_t*)stmt->base.children);
356
+ }
355
357
  rv = OCIStmtFetch_nb(svcctx, stmt->base.hp.stmt, oci8_errhp, 1, OCI_FETCH_NEXT, OCI_DEFAULT);
356
358
  #ifdef USE_DYNAMIC_FETCH
357
359
  while (rv == OCI_NEED_DATA) {
@@ -92,9 +92,13 @@ class OCI8
92
92
  end
93
93
  return [year, month, day, hour, minute, sec] unless full
94
94
 
95
- # sec_fraction
95
+ # fractional second
96
96
  if val.respond_to? :sec_fraction
97
97
  fsec = (val.sec_fraction * @@datetime_fsec_base).to_i
98
+ elsif val.respond_to? :nsec
99
+ fsec = val.nsec
100
+ elsif val.respond_to? :usec
101
+ fsec = val.usec * 1000
98
102
  else
99
103
  fsec = 0
100
104
  end
@@ -473,6 +473,45 @@ class TestOraNumber < Test::Unit::TestCase
473
473
  actual_val = OraNumber.new(x).to_s
474
474
  assert_equal(expected_val, actual_val, x)
475
475
  end
476
+
477
+ conn = get_oci8_connection()
478
+ begin
479
+ cursor = conn.parse('select to_number(:1) from dual')
480
+ cursor.define(1, OraNumber)
481
+ cursor.bind_param(1, nil, String, 200)
482
+ [
483
+ "100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", # 1E125
484
+ "10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", # 1E124
485
+ "234567890234567890234567890234567890000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
486
+ "23456789023456789023456789023456789000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
487
+ "2345678902345678902345678902345678900",
488
+ "234567890234567890234567890234567890",
489
+ "23456789023456789023456789023456789",
490
+ "2345678902345678902345678902345678.9",
491
+ "234567890234567890234567890234567.89",
492
+ "23.456789023456789023456789023456789",
493
+ "2.3456789023456789023456789023456789",
494
+ "0.23456789023456789023456789023456789", # 2.34..snip..E-1
495
+ "0.023456789023456789023456789023456789", # 2.34..snip..E-2
496
+ "0.0023456789023456789023456789023456789", # 2.34..snip..E-3
497
+ "0.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000023456789023456789023456789023456789", # 2.34..snip..E-130
498
+ "0.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001", # 1E-129
499
+ "0.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001", # 1E-130
500
+ ].each do |str|
501
+ cursor[1] = str
502
+ cursor.exec
503
+ onum = cursor.fetch[0]
504
+ assert_equal(str, onum.to_s, "test data: " + str)
505
+
506
+ str = '-' + str
507
+ cursor[1] = str
508
+ cursor.exec
509
+ onum = cursor.fetch[0]
510
+ assert_equal(str, onum.to_s, "test data: " + str)
511
+ end
512
+ ensure
513
+ conn.logoff
514
+ end
476
515
  end
477
516
 
478
517
  # onum.truncate -> integer
@@ -488,6 +527,109 @@ class TestOraNumber < Test::Unit::TestCase
488
527
  end
489
528
  end
490
529
 
530
+ def test_new_from_string
531
+ conn = get_oci8_connection()
532
+ begin
533
+ cursor = conn.parse('select to_number(:1) from dual')
534
+ cursor.define(1, OraNumber)
535
+ cursor.bind_param(1, nil, String, 200)
536
+ [
537
+ "100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", # 1E125
538
+ "10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", # 1E124
539
+ "234567890234567890234567890234567890000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
540
+ "23456789023456789023456789023456789000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
541
+ "2345678902345678902345678902345678900",
542
+ "234567890234567890234567890234567890",
543
+ "23456789023456789023456789023456789",
544
+ "2345678902345678902345678902345678.9",
545
+ "234567890234567890234567890234567.89",
546
+ "23.456789023456789023456789023456789",
547
+ "2.3456789023456789023456789023456789",
548
+ "0.23456789023456789023456789023456789", # 2.34..snip..E-1
549
+ "0.023456789023456789023456789023456789", # 2.34..snip..E-2
550
+ "0.0023456789023456789023456789023456789", # 2.34..snip..E-3
551
+ "0.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000023456789023456789023456789023456789", # 2.34..snip..E-130
552
+ "0.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001", # 1E-129
553
+ "0.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001", # 1E-130
554
+
555
+ # leading spaces
556
+ " 123",
557
+ # trailing spaces
558
+ "123 ",
559
+ "123.456 ",
560
+ "123E10 ",
561
+ "123.456E10 ",
562
+ # scientific notation
563
+ "1234567890000e-9",
564
+ "123456789000e-8",
565
+ "123456789e-5",
566
+ "12345.6789e-1",
567
+ "12.3456789e+1",
568
+ "0.0000123456789E7",
569
+ # round to zero
570
+ "1E-131",
571
+ # overflow
572
+ "1E126",
573
+ "10E125",
574
+ "100000000000E115",
575
+ "1E+126",
576
+ # invalid number
577
+ "",
578
+ " ",
579
+ "abc",
580
+ "1E10a",
581
+ "11E10a",
582
+ "1.1.1",
583
+ # round down
584
+ "444444444444444444444444444444444444444444444444440000",
585
+ "44444444444444444444444444444444444444444444444444000",
586
+ "44444444444444444444444444.444444444444444444444444",
587
+ "4444444444444444444444444.4444444444444444444444444",
588
+ "0.000000044444444444444444444444444444444444444444444444444",
589
+ "0.00000044444444444444444444444444444444444444444444444444",
590
+ # round up
591
+ "555555555555555555555555555555555555555555555555550000",
592
+ "55555555555555555555555555555555555555555555555555000",
593
+ "55555555555555555555555555.555555555555555555555555",
594
+ "5555555555555555555555555.5555555555555555555555555",
595
+ "0.000000055555555555555555555555555555555555555555555555555",
596
+ "0.00000055555555555555555555555555555555555555555555555555",
597
+ "999999999999999999999999999999999999999999999999990000",
598
+ "99999999999999999999999999999999999999999999999999000",
599
+ "99999999999999999999999999.999999999999999999999999",
600
+ "9999999999999999999999999.9999999999999999999999999",
601
+ "0.000000099999999999999999999999999999999999999999999999999",
602
+ "0.00000099999999999999999999999999999999999999999999999999",
603
+ # overflow by round up
604
+ "999999999999999999999999999999999999999999999999999999999900000000000000000000000000000000000000000000000000000000000000000000",
605
+ ].each do |str|
606
+ run_test_new_from_string(cursor, str)
607
+ run_test_new_from_string(cursor, '-' + str)
608
+ end
609
+ ensure
610
+ conn.logoff
611
+ end
612
+ end
613
+
614
+ def run_test_new_from_string(cursor, str)
615
+ cursor[1] = str
616
+ onum = nil
617
+ begin
618
+ cursor.exec
619
+ onum = cursor.fetch[0]
620
+ rescue OCIError => oraerr
621
+ begin
622
+ OraNumber.new(str)
623
+ flunk("exception expected but none was thrown. test data: " + str)
624
+ rescue
625
+ assert_equal(oraerr.to_s, $!.to_s, "test data: " + str)
626
+ end
627
+ end
628
+ if onum
629
+ assert_equal(onum.dump, OraNumber.new(str).dump, "test data: " + str)
630
+ end
631
+ end
632
+
491
633
  def test_new_from_bigdecimal
492
634
  ["+Infinity", "-Infinity", "NaN"].each do |n|
493
635
  assert_raise TypeError do
@@ -504,7 +646,8 @@ class TestOraNumber < Test::Unit::TestCase
504
646
  [
505
647
  [Rational(1, 2), "0.5"],
506
648
  [Rational(3, 5), "0.6"],
507
- [Rational(10, 3), "3.3333333333333333333333333333333333333"],
649
+ [Rational(10, 3), "3.33333333333333333333333333333333333333"],
650
+ [Rational(20, 3), "6.66666666666666666666666666666666666667"],
508
651
  ].each do |ary|
509
652
  assert_equal(ary[1], OraNumber.new(ary[0]).to_s)
510
653
  end
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-oci8
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.3
4
+ prerelease: false
5
+ segments:
6
+ - 2
7
+ - 0
8
+ - 4
9
+ version: 2.0.4
5
10
  platform: ruby
6
11
  authors:
7
12
  - KUBO Takehiro
@@ -9,11 +14,13 @@ autorequire:
9
14
  bindir: bin
10
15
  cert_chain: []
11
16
 
12
- date: 2009-10-21 00:00:00 +09:00
17
+ date: 2010-02-28 00:00:00 +09:00
13
18
  default_executable:
14
19
  dependencies: []
15
20
 
16
- description: ruby-oci8 is a ruby interface for Oracle using OCI8 API. It is available with Oracle8, Oracle8i, Oracle9i, Oracle10g and Oracle Instant Client.
21
+ description: |
22
+ ruby-oci8 is a ruby interface for Oracle using OCI8 API. It is available with Oracle8, Oracle8i, Oracle9i, Oracle10g and Oracle Instant Client.
23
+
17
24
  email: kubo@jiubao.org
18
25
  executables: []
19
26
 
@@ -55,9 +62,12 @@ files:
55
62
  - ext/oci8/oci8.h
56
63
  - ext/oci8/oci8lib.c
57
64
  - ext/oci8/ocidatetime.c
65
+ - ext/oci8/ocihandle.c
58
66
  - ext/oci8/ocinumber.c
59
67
  - ext/oci8/oraconf.rb
60
68
  - ext/oci8/oradate.c
69
+ - ext/oci8/oranumber_util.c
70
+ - ext/oci8/oranumber_util.h
61
71
  - ext/oci8/post-config.rb
62
72
  - ext/oci8/stmt.c
63
73
  - ext/oci8/object.c
@@ -98,6 +108,8 @@ files:
98
108
  - test/test_rowid.rb
99
109
  has_rdoc: true
100
110
  homepage: http://ruby-oci8.rubyforge.org
111
+ licenses: []
112
+
101
113
  post_install_message:
102
114
  rdoc_options:
103
115
  - --main
@@ -108,20 +120,24 @@ required_ruby_version: !ruby/object:Gem::Requirement
108
120
  requirements:
109
121
  - - ">="
110
122
  - !ruby/object:Gem::Version
123
+ segments:
124
+ - 1
125
+ - 8
126
+ - 0
111
127
  version: 1.8.0
112
- version:
113
128
  required_rubygems_version: !ruby/object:Gem::Requirement
114
129
  requirements:
115
130
  - - ">="
116
131
  - !ruby/object:Gem::Version
132
+ segments:
133
+ - 0
117
134
  version: "0"
118
- version:
119
135
  requirements: []
120
136
 
121
137
  rubyforge_project: ruby-oci8
122
- rubygems_version: 1.2.0
138
+ rubygems_version: 1.3.6
123
139
  signing_key:
124
- specification_version: 2
140
+ specification_version: 3
125
141
  summary: Ruby interface for Oracle using OCI8 API
126
142
  test_files:
127
143
  - test/test_all.rb