ruby-oci8-master 2.0.7

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 (84) hide show
  1. data/ChangeLog +2321 -0
  2. data/Makefile +88 -0
  3. data/NEWS +303 -0
  4. data/README +76 -0
  5. data/VERSION +1 -0
  6. data/dist-files +83 -0
  7. data/doc/api.en.html +527 -0
  8. data/doc/api.en.rd +554 -0
  9. data/doc/api.ja.html +525 -0
  10. data/doc/api.ja.rd +557 -0
  11. data/doc/manual.css +35 -0
  12. data/ext/oci8/.document +18 -0
  13. data/ext/oci8/MANIFEST +18 -0
  14. data/ext/oci8/apiwrap.c.tmpl +182 -0
  15. data/ext/oci8/apiwrap.h.tmpl +61 -0
  16. data/ext/oci8/apiwrap.rb +91 -0
  17. data/ext/oci8/apiwrap.yml +1455 -0
  18. data/ext/oci8/attr.c +105 -0
  19. data/ext/oci8/bind.c +366 -0
  20. data/ext/oci8/connection_pool.c +199 -0
  21. data/ext/oci8/encoding.c +289 -0
  22. data/ext/oci8/env.c +178 -0
  23. data/ext/oci8/error.c +378 -0
  24. data/ext/oci8/extconf.rb +179 -0
  25. data/ext/oci8/lob.c +805 -0
  26. data/ext/oci8/metadata.c +232 -0
  27. data/ext/oci8/object.c +727 -0
  28. data/ext/oci8/oci8.c +1156 -0
  29. data/ext/oci8/oci8.h +574 -0
  30. data/ext/oci8/oci8lib.c +527 -0
  31. data/ext/oci8/ocidatetime.c +484 -0
  32. data/ext/oci8/ocihandle.c +751 -0
  33. data/ext/oci8/ocinumber.c +1612 -0
  34. data/ext/oci8/oraconf.rb +1119 -0
  35. data/ext/oci8/oradate.c +611 -0
  36. data/ext/oci8/oranumber_util.c +352 -0
  37. data/ext/oci8/oranumber_util.h +24 -0
  38. data/ext/oci8/post-config.rb +5 -0
  39. data/ext/oci8/stmt.c +673 -0
  40. data/ext/oci8/thread_util.c +85 -0
  41. data/ext/oci8/thread_util.h +30 -0
  42. data/ext/oci8/win32.c +137 -0
  43. data/lib/.document +1 -0
  44. data/lib/dbd/OCI8.rb +591 -0
  45. data/lib/oci8.rb.in +94 -0
  46. data/lib/oci8/.document +8 -0
  47. data/lib/oci8/bindtype.rb +349 -0
  48. data/lib/oci8/compat.rb +113 -0
  49. data/lib/oci8/connection_pool.rb +99 -0
  50. data/lib/oci8/datetime.rb +611 -0
  51. data/lib/oci8/encoding-init.rb +74 -0
  52. data/lib/oci8/encoding.yml +537 -0
  53. data/lib/oci8/metadata.rb +2132 -0
  54. data/lib/oci8/object.rb +581 -0
  55. data/lib/oci8/oci8.rb +721 -0
  56. data/lib/oci8/ocihandle.rb +425 -0
  57. data/lib/oci8/oracle_version.rb +144 -0
  58. data/lib/oci8/properties.rb +73 -0
  59. data/metaconfig +142 -0
  60. data/pre-distclean.rb +7 -0
  61. data/ruby-oci8.gemspec +63 -0
  62. data/setup.rb +1331 -0
  63. data/test/README +4 -0
  64. data/test/config.rb +122 -0
  65. data/test/test_all.rb +51 -0
  66. data/test/test_appinfo.rb +63 -0
  67. data/test/test_array_dml.rb +333 -0
  68. data/test/test_bind_raw.rb +46 -0
  69. data/test/test_bind_time.rb +178 -0
  70. data/test/test_break.rb +96 -0
  71. data/test/test_clob.rb +82 -0
  72. data/test/test_connstr.rb +81 -0
  73. data/test/test_datetime.rb +582 -0
  74. data/test/test_dbi.rb +366 -0
  75. data/test/test_dbi_clob.rb +53 -0
  76. data/test/test_encoding.rb +100 -0
  77. data/test/test_error.rb +88 -0
  78. data/test/test_metadata.rb +1399 -0
  79. data/test/test_oci8.rb +434 -0
  80. data/test/test_oracle_version.rb +70 -0
  81. data/test/test_oradate.rb +256 -0
  82. data/test/test_oranumber.rb +746 -0
  83. data/test/test_rowid.rb +33 -0
  84. metadata +137 -0
@@ -0,0 +1,46 @@
1
+ # Low-level API
2
+ require 'oci8'
3
+ require 'test/unit'
4
+ require File.dirname(__FILE__) + '/config'
5
+
6
+ class TestBindRaw < Test::Unit::TestCase
7
+ CHECK_TARGET = [
8
+ ["0123456789:;<=>?", "303132333435363738393A3B3C3D3E3F"],
9
+ ["@ABCDEFGHIJKLMNO", "404142434445464748494A4B4C4D4E4F"],
10
+ ["PQRSTUVWXYZ[\\]^_", "505152535455565758595A5B5C5D5E5F"],
11
+ ["`abcdefghijklmno", "606162636465666768696A6B6C6D6E6F"],
12
+ ["pqrstuvwxyz{|}~", "707172737475767778797A7B7C7D7E"],
13
+ ]
14
+
15
+ def setup
16
+ @conn = get_oci8_connection()
17
+ end
18
+
19
+ def test_set_raw
20
+ cursor = @conn.parse("BEGIN :hex := RAWTOHEX(:raw); END;")
21
+ cursor.bind_param(:raw, nil, OCI8::RAW, 16)
22
+ cursor.bind_param(:hex, nil, String, 32)
23
+
24
+ CHECK_TARGET.each do |raw, hex|
25
+ cursor[:raw] = raw
26
+ cursor.exec
27
+ assert_equal(hex, cursor[:hex])
28
+ end
29
+ end
30
+
31
+ def test_get_raw
32
+ cursor = @conn.parse("BEGIN :raw := HEXTORAW(:hex); END;")
33
+ cursor.bind_param(:hex, nil, String, 32)
34
+ cursor.bind_param(:raw, nil, OCI8::RAW, 16)
35
+
36
+ CHECK_TARGET.each do |raw, hex|
37
+ cursor[:hex] = hex
38
+ cursor.exec
39
+ assert_equal(raw, cursor[:raw])
40
+ end
41
+ end
42
+
43
+ def teardown
44
+ @conn.logoff
45
+ end
46
+ end
@@ -0,0 +1,178 @@
1
+ require 'oci8'
2
+ require 'test/unit'
3
+ require File.dirname(__FILE__) + '/config'
4
+
5
+ class TestBindTime < Test::Unit::TestCase
6
+
7
+ YEAR_CHECK_TARGET = [1971, 1989, 2002, 2037]
8
+ MON_CHECK_TARGET = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
9
+ DAY_CHECK_TARGET = [1, 10, 20, 31] # days of January.
10
+ HOUR_CHECK_TARGET = [0, 6, 12, 18, 23]
11
+ MIN_CHECK_TARGET = [0, 15, 30, 45, 59]
12
+ SEC_CHECK_TARGET = [0, 15, 30, 45, 59]
13
+
14
+ def setup
15
+ @conn = get_oci8_connection
16
+ end
17
+
18
+ def test_set_year
19
+ cursor = @conn.parse("BEGIN :year := TO_NUMBER(TO_CHAR(:time, 'SYYYY'), '9999'); END;")
20
+ cursor.bind_param(:time, Time)
21
+ cursor.bind_param(:year, Fixnum)
22
+
23
+ YEAR_CHECK_TARGET.each do |i|
24
+ # set year
25
+ cursor[:time] = Time.local(i, 1)
26
+ # check result
27
+ cursor.exec
28
+ assert_equal(i, cursor[:year])
29
+ end
30
+ end
31
+
32
+ def test_get_year
33
+ cursor = @conn.parse("BEGIN :time := TO_DATE(TO_CHAR(:year, '0999'), 'SYYYY'); END;")
34
+ cursor.bind_param(:year, Fixnum)
35
+ cursor.bind_param(:time, Time)
36
+ YEAR_CHECK_TARGET.each do |i|
37
+ # set time via oracle.
38
+ cursor[:year] = i
39
+ cursor.exec
40
+ # check Time#year
41
+ assert_equal(i, cursor[:time].year)
42
+ end
43
+ end
44
+
45
+ def test_set_mon
46
+ cursor = @conn.parse("BEGIN :mon := TO_NUMBER(TO_CHAR(:time, 'MM'), '99'); END;")
47
+ cursor.bind_param(:time, Time)
48
+ cursor.bind_param(:mon, Fixnum)
49
+ MON_CHECK_TARGET.each do |i|
50
+ # set mon
51
+ cursor[:time] = Time.local(2001, i)
52
+ # check result via oracle.
53
+ cursor.exec
54
+ assert_equal(i, cursor[:mon])
55
+ end
56
+ end
57
+
58
+ def test_get_mon
59
+ cursor = @conn.parse("BEGIN :time := TO_DATE(TO_CHAR(:mon, '99'), 'MM'); END;")
60
+ cursor.bind_param(:mon, Fixnum)
61
+ cursor.bind_param(:time, Time)
62
+ MON_CHECK_TARGET.each do |i|
63
+ # set time via oracle.
64
+ cursor[:mon] = i;
65
+ cursor.exec
66
+ # check Time#mon
67
+ assert_equal(i, cursor[:time].mon)
68
+ end
69
+ end
70
+
71
+ def test_set_day
72
+ cursor = @conn.parse("BEGIN :day := TO_NUMBER(TO_CHAR(:time, 'DD'), '99'); END;")
73
+ cursor.bind_param(:time, Time)
74
+ cursor.bind_param(:day, Fixnum)
75
+ DAY_CHECK_TARGET.each do |i|
76
+ # set day
77
+ cursor[:time] = Time.local(2001, 1, i)
78
+ # check result via oracle.
79
+ cursor.exec
80
+ assert_equal(i, cursor[:day])
81
+ end
82
+ end
83
+
84
+ def test_get_day
85
+ cursor = @conn.parse("BEGIN :time := TO_DATE('200101' || TO_CHAR(:day, 'FM00'), 'YYYYMMDD'); END;")
86
+ day_in = cursor.bind_param(:day, Fixnum)
87
+ time_out = cursor.bind_param(:time, Time)
88
+ DAY_CHECK_TARGET.each do |i|
89
+ # set time via oracle.
90
+ cursor[:day] = i;
91
+ cursor.exec
92
+ # check Time#day
93
+ assert_equal(i, cursor[:time].day)
94
+ end
95
+ end
96
+
97
+ def test_set_hour
98
+ cursor = @conn.parse("BEGIN :hour := TO_NUMBER(TO_CHAR(:time, 'HH24'), '99'); END;")
99
+ cursor.bind_param(:time, Time)
100
+ cursor.bind_param(:hour, Fixnum)
101
+ HOUR_CHECK_TARGET.each do |i|
102
+ # set hour
103
+ cursor[:time] = Time.local(2001, 1, 1, i)
104
+ # check result via oracle.
105
+ cursor.exec
106
+ assert_equal(i, cursor[:hour])
107
+ end
108
+ end
109
+
110
+ def test_get_hour
111
+ cursor = @conn.parse("BEGIN :time := TO_DATE(TO_CHAR(:hour, '99'), 'HH24'); END;")
112
+ cursor.bind_param(:hour, Fixnum)
113
+ cursor.bind_param(:time, Time)
114
+ HOUR_CHECK_TARGET.each do |i|
115
+ # set time via oracle.
116
+ cursor[:hour] = i
117
+ cursor.exec
118
+ # check Time#hour
119
+ assert_equal(i, cursor[:time].hour)
120
+ end
121
+ end
122
+
123
+ def test_set_min
124
+ cursor = @conn.parse("BEGIN :min := TO_NUMBER(TO_CHAR(:time, 'MI'), '99'); END;")
125
+ cursor.bind_param(:time, Time)
126
+ cursor.bind_param(:min, Fixnum)
127
+ MIN_CHECK_TARGET.each do |i|
128
+ # set min
129
+ cursor[:time] = Time.local(2001, 1, 1, 0, i)
130
+ # check result via oracle.
131
+ cursor.exec
132
+ assert_equal(i, cursor[:min])
133
+ end
134
+ end
135
+
136
+ def test_get_min
137
+ cursor = @conn.parse("BEGIN :time := TO_DATE(TO_CHAR(:min, '99'), 'MI'); END;")
138
+ cursor.bind_param(:min, Fixnum)
139
+ cursor.bind_param(:time, Time)
140
+ MIN_CHECK_TARGET.each do |i|
141
+ # set time via oracle.
142
+ cursor[:min] = i;
143
+ cursor.exec
144
+ # check Time#min
145
+ assert_equal(i, cursor[:time].min)
146
+ end
147
+ end
148
+
149
+ def test_set_sec
150
+ cursor = @conn.parse("BEGIN :sec := TO_NUMBER(TO_CHAR(:time, 'SS'), '99'); END;")
151
+ cursor.bind_param(:time, Time)
152
+ cursor.bind_param(:sec, Fixnum)
153
+ SEC_CHECK_TARGET.each do |i|
154
+ # set sec
155
+ cursor[:time] = Time.local(2001, 1, 1, 0, 0, i)
156
+ # check result via oracle.
157
+ cursor.exec
158
+ assert_equal(i, cursor[:sec])
159
+ end
160
+ end
161
+
162
+ def test_get_sec
163
+ cursor = @conn.parse("BEGIN :time := TO_DATE(TO_CHAR(:sec, '99'), 'SS'); END;")
164
+ cursor.bind_param(:sec, Fixnum)
165
+ cursor.bind_param(:time, Time)
166
+ SEC_CHECK_TARGET.each do |i|
167
+ # set time via oracle.
168
+ cursor[:sec] = i
169
+ cursor.exec
170
+ # check Time#sec
171
+ assert_equal(i, cursor[:time].sec)
172
+ end
173
+ end
174
+
175
+ def teardown
176
+ @conn.logoff
177
+ end
178
+ end
@@ -0,0 +1,96 @@
1
+ # High-level API
2
+ require 'oci8'
3
+ require 'test/unit'
4
+ require 'timeout'
5
+ require File.dirname(__FILE__) + '/config'
6
+
7
+ class TestBreak < Test::Unit::TestCase
8
+
9
+ def setup
10
+ @conn = get_oci8_connection
11
+ end
12
+
13
+ def teardown
14
+ @conn.logoff
15
+ end
16
+
17
+ def report(str)
18
+ printf "%d: %s\n", (Time.now - $start_time), str
19
+ end
20
+
21
+ PLSQL_DONE = 1
22
+ OCIBREAK = 2
23
+ SEND_BREAK = 3
24
+
25
+ TIME_IN_PLSQL = 5
26
+ TIME_TO_BREAK = 2
27
+
28
+ def do_test_ocibreak(conn, expect)
29
+ $start_time = Time.now
30
+
31
+ th = Thread.start do
32
+ begin
33
+ conn.exec("BEGIN DBMS_LOCK.SLEEP(#{TIME_IN_PLSQL}); END;")
34
+ assert_equal(expect[PLSQL_DONE], (Time.now - $start_time).round, 'PLSQL_DONE')
35
+ rescue OCIBreak
36
+ assert_equal(expect[OCIBREAK], (Time.now - $start_time).round, 'OCIBREAK')
37
+ assert_equal('Canceled by user request.', $!.to_s)
38
+ end
39
+ end
40
+
41
+ sleep(0.3) # Wait until DBMS_LOCK.SLEEP is running.
42
+ sleep(TIME_TO_BREAK - 0.3)
43
+ assert_equal(expect[SEND_BREAK], (Time.now - $start_time).round, 'SEND_BREAK')
44
+ conn.break()
45
+ th.join
46
+ end
47
+
48
+ def test_blocking_mode
49
+ @conn.non_blocking = false
50
+ assert_equal(false, @conn.non_blocking?)
51
+ expect = []
52
+ expect[PLSQL_DONE] = TIME_IN_PLSQL
53
+ expect[OCIBREAK] = "Invalid status"
54
+ expect[SEND_BREAK] = TIME_IN_PLSQL + TIME_TO_BREAK
55
+ do_test_ocibreak(@conn, expect)
56
+ end
57
+
58
+ def test_non_blocking_mode
59
+ is_windows_server = false
60
+ @conn.exec('select banner from v$version') do |row|
61
+ is_windows_server = true if row[0].include? 'Windows'
62
+ end
63
+
64
+ @conn.non_blocking = true
65
+ assert_equal(true, @conn.non_blocking?)
66
+ expect = []
67
+ if is_windows_server
68
+ if $oracle_server_version >= OCI8::ORAVER_9_0
69
+ # raise after sleeping #{TIME_IN_PLSQL} seconds.
70
+ expect[PLSQL_DONE] = "Invalid status"
71
+ expect[OCIBREAK] = TIME_IN_PLSQL
72
+ else
73
+ expect[PLSQL_DONE] = TIME_IN_PLSQL
74
+ expect[OCIBREAK] = "Invalid status"
75
+ end
76
+ else
77
+ # raise immediately by OCI8#break.
78
+ expect[PLSQL_DONE] = "Invalid status"
79
+ expect[OCIBREAK] = TIME_TO_BREAK
80
+ end
81
+ expect[SEND_BREAK] = TIME_TO_BREAK
82
+ do_test_ocibreak(@conn, expect)
83
+ end
84
+
85
+ def test_timeout
86
+ @conn.non_blocking = true
87
+ start_time = Time.now
88
+ assert_raise(Timeout::Error) do
89
+ Timeout.timeout(1) do
90
+ @conn.exec("BEGIN DBMS_LOCK.SLEEP(10); END;")
91
+ end
92
+ end
93
+ @conn.exec("BEGIN NULL; END;")
94
+ assert_operator(Time.now, :<, start_time + 2)
95
+ end
96
+ end
@@ -0,0 +1,82 @@
1
+ # Low-level API
2
+ require 'oci8'
3
+ require 'test/unit'
4
+ require File.dirname(__FILE__) + '/config'
5
+
6
+ class TestCLob < Test::Unit::TestCase
7
+
8
+ def setup
9
+ @conn = get_oci8_connection
10
+ drop_table('test_table')
11
+ @conn.exec('CREATE TABLE test_table (filename VARCHAR2(40), content CLOB)')
12
+ end
13
+
14
+ def test_insert
15
+ filename = File.basename($lobfile)
16
+ @conn.exec("DELETE FROM test_table WHERE filename = :1", filename)
17
+ @conn.exec("INSERT INTO test_table(filename, content) VALUES (:1, EMPTY_CLOB())", filename)
18
+ cursor = @conn.exec("SELECT content FROM test_table WHERE filename = :1 FOR UPDATE", filename)
19
+ lob = cursor.fetch[0]
20
+ open($lobfile) do |f|
21
+ while f.gets()
22
+ lob.write($_)
23
+ end
24
+ end
25
+ lob.close
26
+ end
27
+
28
+ def test_insert_with_flush
29
+ filename = File.basename($lobfile)
30
+ @conn.exec("DELETE FROM test_table WHERE filename = :1", filename)
31
+ @conn.exec("INSERT INTO test_table(filename, content) VALUES (:1, EMPTY_CLOB())", filename)
32
+ cursor = @conn.exec("SELECT content FROM test_table WHERE filename = :1 FOR UPDATE", filename)
33
+ lob = cursor.fetch[0]
34
+ lob.sync = false
35
+ open($lobfile) do |f|
36
+ while f.gets()
37
+ lob.write($_)
38
+ end
39
+ end
40
+ lob.flush
41
+ lob.close
42
+ end
43
+
44
+ def test_insert_symbol
45
+ filename = 'test_symbol'
46
+ value = :foo_bar
47
+ @conn.exec("DELETE FROM test_table WHERE filename = :1", filename)
48
+ @conn.exec("INSERT INTO test_table(filename, content) VALUES (:1, EMPTY_CLOB())", filename)
49
+ cursor = @conn.exec("SELECT content FROM test_table WHERE filename = :1 FOR UPDATE", filename)
50
+ lob = cursor.fetch[0]
51
+ lob.write(value)
52
+ lob.rewind
53
+ assert_equal(value.to_s, lob.read);
54
+ lob.close
55
+ end
56
+
57
+ def test_read
58
+ test_insert() # first insert data.
59
+ filename = File.basename($lobfile)
60
+ cursor = @conn.exec("SELECT content FROM test_table WHERE filename = :1 FOR UPDATE", filename)
61
+ lob = cursor.fetch[0]
62
+
63
+ open($lobfile) do |f|
64
+ while buf = lob.read($lobreadnum)
65
+ fbuf = f.read(buf.size)
66
+ assert_equal(fbuf, buf)
67
+ # offset += buf.size will not work fine,
68
+ # Though buf.size counts in byte,
69
+ # offset and $lobreadnum count in character.
70
+ end
71
+ assert_equal(nil, buf)
72
+ assert(f.eof?)
73
+ assert(lob.eof?)
74
+ end
75
+ lob.close
76
+ end
77
+
78
+ def teardown
79
+ drop_table('test_table')
80
+ @conn.logoff
81
+ end
82
+ end
@@ -0,0 +1,81 @@
1
+ require 'oci8'
2
+ require 'test/unit'
3
+ require File.dirname(__FILE__) + '/config'
4
+
5
+ class TestConnStr < Test::Unit::TestCase
6
+ TEST_CASES =
7
+ [
8
+ # success cases:
9
+ # [ 'connect_string', expected result as an array]
10
+ # error cases:
11
+ # [ 'connect_string', ExceptionClass]
12
+ ["hr/hr@host/service_name", ["hr", "hr", "host/service_name", nil]],
13
+ ["sys/syspw@host/service_name AS SYSdba ", ["sys", "syspw", "host/service_name", :SYSDBA]],
14
+ ["sys/syspw@host:1521/service_name as sysdba", ["sys", "syspw", "host:1521/service_name", :SYSDBA]],
15
+ # error cases
16
+ ["service_name", ArgumentError],
17
+ ["", ArgumentError],
18
+ ["foo bar/baz", ArgumentError],
19
+ ["foo@bar/baz", ArgumentError],
20
+ # raise error in connecting but no error in parse_connect_string.
21
+ ["foo/bar as sysdbaaa", ["foo", "bar", nil, "sysdbaaa"]],
22
+
23
+ ##
24
+ ## following test cases are contributed by Shiwei Zhang.
25
+ ##
26
+ #"username/password"
27
+ ["username/password", ["username", "password", nil, nil]],
28
+ #"username/password@[//]host[:port][/service_name]"
29
+ ["username/password@host", ["username", "password", "host", nil]],
30
+ ["username/password@host/service_name", ["username", "password", "host/service_name", nil]],
31
+ ["username/password@host:1521", ["username", "password", "host:1521", nil]],
32
+ ["username/password@host:1521/service_name", ["username", "password", "host:1521/service_name", nil]],
33
+ ["username/password@//host", ["username", "password", "//host", nil]],
34
+ ["username/password@//host/service_name", ["username", "password", "//host/service_name", nil]],
35
+ ["username/password@//host:1521", ["username", "password", "//host:1521", nil]],
36
+ ["username/password@//host:1521/service_name", ["username", "password", "//host:1521/service_name", nil]],
37
+ #"username/password as{sysoper|sysdba}"
38
+ ["username/password as sysoper", ["username", "password", nil, :SYSOPER]],
39
+ ["username/password as sysdba", ["username", "password", nil, :SYSDBA]],
40
+ #"username/password@[//]host[:port][/service_name] as {sysoper|sysdba}"
41
+ ["username/password@host as sysoper", ["username", "password", "host", :SYSOPER]],
42
+ ["username/password@host as sysdba", ["username", "password", "host", :SYSDBA]],
43
+ ["username/password@host/service_name as sysoper", ["username", "password", "host/service_name", :SYSOPER]],
44
+ ["username/password@host/service_name as sysdba", ["username", "password", "host/service_name", :SYSDBA]],
45
+ ["username/password@host:1521 as sysoper", ["username", "password", "host:1521", :SYSOPER]],
46
+ ["username/password@host:1521 as sysdba", ["username", "password", "host:1521", :SYSDBA]],
47
+ ["username/password@host:1521/service_name as sysoper", ["username", "password", "host:1521/service_name", :SYSOPER]],
48
+ ["username/password@host:1521/service_name as sysdba", ["username", "password", "host:1521/service_name", :SYSDBA]],
49
+ ["username/password@//host as sysoper", ["username", "password", "//host", :SYSOPER]],
50
+ ["username/password@//host as sysdba", ["username", "password", "//host", :SYSDBA]],
51
+ ["username/password@//host/service_name as sysoper", ["username", "password", "//host/service_name", :SYSOPER]],
52
+ ["username/password@//host/service_name as sysdba", ["username", "password", "//host/service_name", :SYSDBA]],
53
+ ["username/password@//host:1521 as sysoper", ["username", "password", "//host:1521", :SYSOPER]],
54
+ ["username/password@//host:1521 as sysdba", ["username", "password", "//host:1521", :SYSDBA]],
55
+ ["username/password@//host:1521/service_name as sysoper", ["username", "password", "//host:1521/service_name", :SYSOPER]],
56
+ ["username/password@//host:1521/service_name as sysdba", ["username", "password", "//host:1521/service_name", :SYSDBA]],
57
+ ["/passwd@192.168.19.19:1521/orcl as sysdba", ["", "passwd", "192.168.19.19:1521/orcl", :SYSDBA]],
58
+ ["/", [nil, nil, nil, nil]],
59
+ ["/ as sysdba", [nil, nil, nil, :SYSDBA]],
60
+ ]
61
+
62
+ def test_connstr
63
+ obj = OCI8.allocate # create an uninitialized object.
64
+ TEST_CASES.each do |test_case|
65
+ case test_case[1]
66
+ when Array
67
+ # use instance_eval to call a private method parse_connect_string.
68
+ result = obj.instance_eval { parse_connect_string(test_case[0]) }
69
+ assert_equal(test_case[1], result, test_case[0])
70
+ when Class
71
+ assert_raises(test_case[1]) do
72
+ result = obj.instance_eval { parse_connect_string(test_case[0]) }
73
+ end
74
+ else
75
+ raise "unsupported testcase"
76
+ end
77
+ end
78
+ end
79
+ end
80
+
81
+ Test::Unit::AutoRunner.run() if $0 == __FILE__