ruby-oci8 2.1.5.1-x64-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +7 -0
  2. data/.yardopts +17 -0
  3. data/COPYING +30 -0
  4. data/COPYING_old +64 -0
  5. data/ChangeLog +2779 -0
  6. data/Makefile +92 -0
  7. data/NEWS +660 -0
  8. data/README.md +43 -0
  9. data/VERSION +1 -0
  10. data/dist-files +91 -0
  11. data/docs/install-binary-package.md +40 -0
  12. data/docs/install-full-client.md +116 -0
  13. data/docs/install-instant-client.md +167 -0
  14. data/docs/platform-specific-issues.md +197 -0
  15. data/docs/report-installation-issue.md +50 -0
  16. data/lib/.document +1 -0
  17. data/lib/dbd/OCI8.rb +591 -0
  18. data/lib/oci8.rb +147 -0
  19. data/lib/oci8.rb.in +147 -0
  20. data/lib/oci8/.document +8 -0
  21. data/lib/oci8/bindtype.rb +350 -0
  22. data/lib/oci8/compat.rb +113 -0
  23. data/lib/oci8/connection_pool.rb +108 -0
  24. data/lib/oci8/cursor.rb +564 -0
  25. data/lib/oci8/datetime.rb +605 -0
  26. data/lib/oci8/encoding-init.rb +79 -0
  27. data/lib/oci8/encoding.yml +537 -0
  28. data/lib/oci8/metadata.rb +2092 -0
  29. data/lib/oci8/object.rb +605 -0
  30. data/lib/oci8/oci8.rb +560 -0
  31. data/lib/oci8/ocihandle.rb +607 -0
  32. data/lib/oci8/oracle_version.rb +143 -0
  33. data/lib/oci8/properties.rb +134 -0
  34. data/lib/oci8lib_200.so +0 -0
  35. data/metaconfig +142 -0
  36. data/pre-distclean.rb +7 -0
  37. data/ruby-oci8.gemspec +80 -0
  38. data/setup.rb +1333 -0
  39. data/test/README +42 -0
  40. data/test/config.rb +184 -0
  41. data/test/setup_test_object.sql +171 -0
  42. data/test/test_all.rb +54 -0
  43. data/test/test_appinfo.rb +63 -0
  44. data/test/test_array_dml.rb +333 -0
  45. data/test/test_bind_raw.rb +46 -0
  46. data/test/test_bind_string.rb +106 -0
  47. data/test/test_bind_time.rb +178 -0
  48. data/test/test_break.rb +124 -0
  49. data/test/test_clob.rb +98 -0
  50. data/test/test_connection_pool.rb +125 -0
  51. data/test/test_connstr.rb +81 -0
  52. data/test/test_datetime.rb +581 -0
  53. data/test/test_dbi.rb +366 -0
  54. data/test/test_dbi_clob.rb +53 -0
  55. data/test/test_encoding.rb +104 -0
  56. data/test/test_error.rb +88 -0
  57. data/test/test_metadata.rb +1485 -0
  58. data/test/test_object.rb +462 -0
  59. data/test/test_oci8.rb +489 -0
  60. data/test/test_oracle_version.rb +70 -0
  61. data/test/test_oradate.rb +256 -0
  62. data/test/test_oranumber.rb +787 -0
  63. data/test/test_rowid.rb +33 -0
  64. metadata +109 -0
data/test/README ADDED
@@ -0,0 +1,42 @@
1
+ Before runing unit test:
2
+
3
+ 1. connect to Oracle as system:
4
+
5
+ $ sqlplus system/<password_of_system>
6
+
7
+ 2. create user ruby:
8
+
9
+ SQL> CREATE USER ruby IDENTIFIED BY oci8;
10
+
11
+ or
12
+
13
+ SQL> CREATE USER ruby IDENTIFIED BY oci8
14
+ 2 DEFAULT TABLESPACE users TEMPORARY TABLESPACE temp;
15
+
16
+ 3. grant the privilege to connect and execute.
17
+
18
+ SQL> GRANT connect, resource, create view TO ruby;
19
+
20
+ 4. connect to Oracle as sys
21
+
22
+ $ sqlplus 'sys/<password_of_sys> as sysdba'
23
+
24
+ 5. grant privileges
25
+
26
+ SQL> GRANT EXECUTE ON dbms_lock TO ruby;
27
+ SQL> GRANT CREATE VIEW TO ruby;
28
+
29
+ 6. connect as ruby user.
30
+
31
+ $ sqlplus ruby/oci8
32
+
33
+ 7. Create object types
34
+
35
+ SQL> @test/setup_test_object.sql
36
+
37
+ 8. change $dbname if the database
38
+
39
+ Then you can run:
40
+ $ make check
41
+ or
42
+ $ nmake check (If your compiler is MS Visual C++.)
data/test/config.rb ADDED
@@ -0,0 +1,184 @@
1
+ # $dbuser must have permission to run DBMS_LOCK.SLEEP
2
+ # connect as sys
3
+ # GRANT EXECUTE ON dbms_lock TO ruby;
4
+ $dbuser = "ruby"
5
+ $dbpass = "oci8"
6
+ $dbname = nil
7
+
8
+ # for test_bind_string_as_nchar in test_encoding.rb
9
+ ENV['ORA_NCHAR_LITERAL_REPLACE'] = 'TRUE' if OCI8.client_charset_name.include? 'UTF8'
10
+
11
+ # test_clob.rb
12
+
13
+ nls_lang = ENV['NLS_LANG']
14
+ nls_lang = nls_lang.split('.')[1] unless nls_lang.nil?
15
+ nls_lang = nls_lang.upcase unless nls_lang.nil?
16
+ $lobfile = File.dirname(__FILE__) + '/../setup.rb'
17
+ $lobreadnum = 256 # counts in charactors
18
+
19
+ # don't modify below.
20
+
21
+ # $oracle_server_version: database compatible level of the Oracle server.
22
+ # $oracle_client_version: Oracle client library version for which oci8 is compiled.
23
+ # $oracle_version: lower value of $oracle_server_version and $oracle_client_version.
24
+ conn = OCI8.new($dbuser, $dbpass, $dbname)
25
+ begin
26
+ conn.exec('select value from database_compatible_level') do |row|
27
+ $oracle_server_version = OCI8::OracleVersion.new(row[0])
28
+ end
29
+ rescue OCIError
30
+ raise if $!.code != 942 # ORA-00942: table or view does not exist
31
+ $oracle_server_version = OCI8::ORAVER_8_0
32
+ end
33
+ conn.logoff
34
+
35
+ if $oracle_server_version < OCI8.oracle_client_version
36
+ $oracle_version = $oracle_server_version
37
+ else
38
+ $oracle_version = OCI8.oracle_client_version
39
+ end
40
+
41
+ if $oracle_version < OCI8::ORAVER_8_1
42
+ $test_clob = false
43
+ else
44
+ $test_clob = true
45
+ end
46
+
47
+ begin
48
+ Time.new(2001, 1, 1, 0, 0, 0, '+00:00')
49
+ # ruby 1.9.2 or later
50
+ def convert_to_time(year, month, day, hour, minute, sec, subsec, timezone)
51
+ subsec ||= 0
52
+ if timezone
53
+ # with time zone
54
+ Time.new(year, month, day, hour, minute, sec + subsec, timezone)
55
+ else
56
+ # without time zone
57
+ Time.local(year, month, day, hour, minute, sec, subsec * 1000000)
58
+ end
59
+ end
60
+ rescue
61
+ # ruby 1.9.1 or former
62
+ def convert_to_time(year, month, day, hour, minute, sec, subsec, timezone)
63
+ subsec ||= 0
64
+ if timezone
65
+ # with time zone
66
+ /([+-])(\d+):(\d+)/ =~ timezone
67
+ offset = ($1 + '1').to_i * ($2.to_i * 60 + $3.to_i)
68
+ if offset == 0
69
+ Time.utc(year, month, day, hour, minute, sec, subsec * 1000000)
70
+ else
71
+ tm = Time.local(year, month, day, hour, minute, sec, subsec * 1000000)
72
+ raise "Failed to convert #{str} to Time" if tm.utc_offset != offset * 60
73
+ tm
74
+ end
75
+ else
76
+ # without time zone
77
+ Time.local(year, month, day, hour, minute, sec, subsec * 1000000)
78
+ end
79
+ end
80
+ end
81
+
82
+ def convert_to_datetime(year, month, day, hour, minute, sec, subsec, timezone)
83
+ subsec ||= 0
84
+ utc_offset = if timezone
85
+ # with time zone
86
+ /([+-])(\d+):(\d+)/ =~ timezone
87
+ ($1 + '1').to_i * ($2.to_i * 60 + $3.to_i) * 60
88
+ else
89
+ Time.local(year, month, day, hour, minute, sec).utc_offset
90
+ end
91
+ begin
92
+ DateTime.civil(year, month, day, hour, minute, sec + subsec, utc_offset.to_r / 86400)
93
+ rescue ArgumentError
94
+ raise $! if $!.to_s != 'invalid date'
95
+ # for ruby 1.8.6.
96
+ # convert to a DateTime via a String as a workaround.
97
+ if utc_offset >= 0
98
+ sign = ?+
99
+ else
100
+ sign = ?-
101
+ utc_offset = - utc_offset;
102
+ end
103
+ tz_min = utc_offset / 60
104
+ tz_hour, tz_min = tz_min.divmod 60
105
+ time_str = format("%04d-%02d-%02dT%02d:%02d:%02d.%09d%c%02d:%02d",
106
+ year, month, day, hour, minute, sec, (subsec * 1000_000_000).to_i, sign, tz_hour, tz_min)
107
+ ::DateTime.parse(time_str)
108
+ end
109
+ end
110
+
111
+ module Test
112
+ module Unit
113
+ class TestCase
114
+
115
+ def get_oci8_connection()
116
+ OCI8.new($dbuser, $dbpass, $dbname)
117
+ rescue OCIError
118
+ raise if $!.code != 12516 && $!.code != 12520
119
+ # sleep a few second and try again if
120
+ # the error code is ORA-12516 or ORA-12520.
121
+ #
122
+ # ORA-12516 - TNS:listener could not find available handler with
123
+ # matching protocol stack
124
+ # ORA-12520 - TNS:listener could not find available handler for
125
+ # requested type of server
126
+ #
127
+ # Thanks to Christopher Jones.
128
+ #
129
+ # Ref: The Underground PHP and Oracle Manual (page 175 in vesion 1.4)
130
+ # http://www.oracle.com/technology/tech/php/pdf/underground-php-oracle-manual.pdf
131
+ #
132
+ sleep(5)
133
+ OCI8.new($dbuser, $dbpass, $dbname)
134
+ end
135
+
136
+ def get_dbi_connection()
137
+ DBI.connect("dbi:OCI8:#{$dbname}", $dbuser, $dbpass, 'AutoCommit' => false)
138
+ rescue DBI::DatabaseError
139
+ raise if $!.err != 12516 && $!.err != 12520
140
+ # same as get_oci8_connection()
141
+ sleep(5)
142
+ DBI.connect("dbi:OCI8:#{$dbname}", $dbuser, $dbpass, 'AutoCommit' => false)
143
+ end
144
+
145
+ def drop_table(table_name)
146
+ if $oracle_server_version < OCI8::ORAVER_10_1
147
+ # Oracle 8 - 9i
148
+ sql = "DROP TABLE #{table_name}"
149
+ else
150
+ # Oracle 10g -
151
+ sql = "DROP TABLE #{table_name} PURGE"
152
+ end
153
+
154
+ if defined? @conn
155
+ begin
156
+ @conn.exec(sql)
157
+ rescue OCIError
158
+ raise if $!.code != 942 # table or view does not exist
159
+ end
160
+ elsif instance_variable_get(:@dbh)
161
+ begin
162
+ @dbh.do(sql)
163
+ rescue DBI::DatabaseError
164
+ raise if $!.err != 942 # table or view does not exist
165
+ end
166
+ end
167
+ end # drop_table
168
+
169
+ def drop_type(type_name)
170
+ begin
171
+ @conn.exec("DROP TYPE BODY #{type_name}")
172
+ rescue OCIError
173
+ raise if $!.code != 4043
174
+ end
175
+ begin
176
+ @conn.exec("DROP TYPE #{type_name}")
177
+ rescue OCIError
178
+ raise if $!.code != 4043
179
+ end
180
+ end # drop_type
181
+ end
182
+ end
183
+ end
184
+
@@ -0,0 +1,171 @@
1
+ drop table rb_test_obj_tab1 purge
2
+ /
3
+ drop table rb_test_obj_tab2 purge
4
+ /
5
+ drop type rb_test_obj
6
+ /
7
+ drop type rb_test_obj_elem_ary_of_ary
8
+ /
9
+ drop type rb_test_obj_elem_array
10
+ /
11
+ drop type rb_test_obj_elem
12
+ /
13
+ create type rb_test_obj_elem as object (
14
+ x integer,
15
+ y integer
16
+ )
17
+ /
18
+ create or replace type rb_test_int_array as array(50) of integer
19
+ /
20
+ create or replace type rb_test_flt_array as array(50) of float
21
+ /
22
+ create or replace type rb_test_num_array as array(50) of number(10,1)
23
+ /
24
+ create or replace type rb_test_bdbl_array as array(50) of binary_double
25
+ /
26
+ create or replace type rb_test_bflt_array as array(50) of binary_float
27
+ /
28
+ create or replace type rb_test_str_array as array(50) of varchar2(50)
29
+ /
30
+ create or replace type rb_test_raw_array as array(50) of raw(50)
31
+ /
32
+ create or replace type rb_test_obj_elem_array as array(50) of rb_test_obj_elem
33
+ /
34
+ create or replace type rb_test_obj_elem_ary_of_ary as array(50) of rb_test_obj_elem_array
35
+ /
36
+ --create or replace type rb_test_date_array as array(50) of date
37
+ --/
38
+ create type rb_test_obj as object (
39
+ int_val integer,
40
+ flt_val float,
41
+ num_val number(10,1),
42
+ bdbl_val binary_double,
43
+ bflt_val binary_float,
44
+ str_val varchar2(50),
45
+ raw_val raw(50),
46
+ clob_val clob,
47
+ nclob_val nclob,
48
+ blob_val blob,
49
+ obj_val rb_test_obj_elem,
50
+ int_array_val rb_test_int_array,
51
+ flt_array_val rb_test_flt_array,
52
+ num_array_val rb_test_num_array,
53
+ bdbl_array_val rb_test_bdbl_array,
54
+ bflt_array_val rb_test_bflt_array,
55
+ str_array_val rb_test_str_array,
56
+ raw_array_val rb_test_raw_array,
57
+ obj_array_val rb_test_obj_elem_array,
58
+ obj_ary_of_ary_val rb_test_obj_elem_ary_of_ary,
59
+ date_val date,
60
+ -- date_array_val rb_test_date_array,
61
+
62
+ constructor function rb_test_obj(n number) return self as result,
63
+ static function test_object_version return integer,
64
+ static function class_func(n number) return rb_test_obj,
65
+ static procedure class_proc1(obj out rb_test_obj, n number),
66
+ static procedure class_proc2(obj in out rb_test_obj),
67
+ member function member_func return integer,
68
+ member procedure member_proc(n in integer)
69
+ )
70
+ /
71
+ create or replace type body rb_test_obj is
72
+
73
+ constructor function rb_test_obj(n number) return self as result is
74
+ function to_test_date(n number) return date is
75
+ begin
76
+ return to_date(to_char(1990 + n, 'FM0000') ||
77
+ to_char(mod(round(n) * 5, 12) + 1, 'FM00') ||
78
+ to_char(mod(round(n) * 7, 27) + 1, 'FM00') ||
79
+ to_char(mod(round(n) * 9, 24), 'FM00') ||
80
+ to_char(mod(round(n) * 11, 60), 'FM00') ||
81
+ to_char(mod(round(n) * 13, 60), 'FM00'), 'yyyymmddhh24miss');
82
+ end;
83
+ begin
84
+ self.int_val := n;
85
+ self.flt_val := n;
86
+ self.num_val := n;
87
+ self.bdbl_val := n;
88
+ self.bflt_val := n;
89
+ self.str_val := to_char(n);
90
+ self.raw_val := utl_raw.cast_to_raw(to_char(n));
91
+ self.clob_val := to_clob(n);
92
+ self.nclob_val := to_clob(n);
93
+ self.blob_val := to_blob(utl_raw.cast_to_raw(to_char(n)));
94
+ self.obj_val := rb_test_obj_elem(n, n + 1);
95
+ self.date_val := to_test_date(n);
96
+ if self.int_val != 1 then
97
+ self.int_array_val := rb_test_int_array(n, n + 1, n + 2);
98
+ self.flt_array_val := rb_test_flt_array(n, n + 1, n + 2);
99
+ self.num_array_val := rb_test_num_array(n, n + 1, n + 2);
100
+ self.bdbl_array_val := rb_test_bdbl_array(n, n + 1, n + 2);
101
+ self.bflt_array_val := rb_test_bflt_array(n, n + 1, n + 2);
102
+ self.str_array_val := rb_test_str_array(to_char(n), to_char(n + 1), to_char(n + 2));
103
+ self.raw_array_val := rb_test_raw_array(utl_raw.cast_to_raw(to_char(n)),
104
+ utl_raw.cast_to_raw(to_char(n + 1)),
105
+ utl_raw.cast_to_raw(to_char(n + 2)));
106
+ self.obj_array_val := rb_test_obj_elem_array(rb_test_obj_elem(n + 0, n + 1),
107
+ rb_test_obj_elem(n + 1, n + 2),
108
+ rb_test_obj_elem(n + 2, n + 3));
109
+ self.obj_ary_of_ary_val := rb_test_obj_elem_ary_of_ary(self.obj_array_val);
110
+ -- self.date_array_val := rb_test_date_array(to_test_date(n),
111
+ -- to_test_date(n + 1),
112
+ -- to_test_date(n + 2));
113
+ end if;
114
+ return;
115
+ end;
116
+
117
+ static function test_object_version return integer is
118
+ begin
119
+ return 2;
120
+ end;
121
+
122
+ static function class_func(n number) return rb_test_obj is
123
+ begin
124
+ return rb_test_obj(n);
125
+ end;
126
+
127
+ static procedure class_proc1(obj out rb_test_obj, n number) is
128
+ begin
129
+ obj := rb_test_obj(n);
130
+ end;
131
+
132
+ static procedure class_proc2(obj in out rb_test_obj) is
133
+ begin
134
+ obj.int_val := obj.int_val + 1;
135
+ end;
136
+
137
+ member function member_func return integer is
138
+ begin
139
+ return int_val;
140
+ end;
141
+
142
+ member procedure member_proc(n in integer) is
143
+ begin
144
+ self.int_val := n;
145
+ end;
146
+ end;
147
+ /
148
+ create table rb_test_obj_tab1 (
149
+ n number primary key,
150
+ obj rb_test_obj
151
+ )
152
+ /
153
+ create table rb_test_obj_tab2 of rb_test_obj (
154
+ int_val primary key
155
+ )
156
+ /
157
+ declare
158
+ n number := 0;
159
+ obj rb_test_obj;
160
+ begin
161
+ loop
162
+ n := n + 1.2;
163
+ exit when n > 20;
164
+ obj := rb_test_obj(n);
165
+ insert into rb_test_obj_tab1 values (n, obj);
166
+ insert into rb_test_obj_tab2 values (obj);
167
+ end loop;
168
+ end;
169
+ /
170
+ commit
171
+ /
data/test/test_all.rb ADDED
@@ -0,0 +1,54 @@
1
+ srcdir = File.dirname(__FILE__)
2
+
3
+ require 'oci8'
4
+ require 'test/unit'
5
+ require "#{srcdir}/config"
6
+
7
+ require "#{srcdir}/test_oradate"
8
+ require "#{srcdir}/test_oranumber"
9
+ require "#{srcdir}/test_bind_string"
10
+ require "#{srcdir}/test_bind_time"
11
+ require "#{srcdir}/test_bind_raw"
12
+ if $test_clob
13
+ require "#{srcdir}/test_clob"
14
+ end
15
+
16
+ require "#{srcdir}/test_break"
17
+ require "#{srcdir}/test_oci8"
18
+ require "#{srcdir}/test_datetime"
19
+ require "#{srcdir}/test_connstr"
20
+ require "#{srcdir}/test_metadata"
21
+ require "#{srcdir}/test_array_dml"
22
+ require "#{srcdir}/test_rowid"
23
+ require "#{srcdir}/test_appinfo"
24
+ require "#{srcdir}/test_oracle_version"
25
+ require "#{srcdir}/test_error"
26
+ require "#{srcdir}/test_connection_pool"
27
+ require "#{srcdir}/test_object"
28
+
29
+ if OCI8.respond_to? :encoding
30
+ require "#{srcdir}/test_encoding"
31
+ end
32
+
33
+ # Ruby/DBI
34
+ begin
35
+ require 'dbi'
36
+ rescue LoadError
37
+ begin
38
+ require 'rubygems'
39
+ require 'dbi'
40
+ rescue LoadError
41
+ dbi_not_found = true
42
+ end
43
+ end
44
+ unless dbi_not_found
45
+ require "#{srcdir}/test_dbi"
46
+ if $test_clob
47
+ require "#{srcdir}/test_dbi_clob"
48
+ end
49
+ end
50
+
51
+ #Test::Unit::AutoRunner.run(true, true)
52
+ if defined? Test::Unit::AutoRunner
53
+ Test::Unit::AutoRunner.run()
54
+ end