fireruby 0.2.2-i586-linux → 0.3.0-i586-linux
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/doc/README +154 -55
- data/lib/fireruby.so +0 -0
- data/lib/src.rb +807 -25
- data/test/AddRemoveUserTest.rb +50 -0
- data/test/BackupRestoreTest.rb +97 -0
- data/test/ConnectionTest.rb +1 -1
- data/test/DDLTest.rb +22 -14
- data/test/GeneratorTest.rb +2 -2
- data/test/ResultSetTest.rb +42 -8
- data/test/RowCountTest.rb +63 -0
- data/test/RowTest.rb +93 -5
- data/test/SQLTest.rb +16 -8
- data/test/ServiceManagerTest.rb +21 -0
- data/test/StatementTest.rb +3 -3
- data/test/TransactionTest.rb +6 -5
- data/test/UnitTest.rb +6 -0
- metadata +16 -3
- data/lib/fireruby.bundle +0 -0
@@ -0,0 +1,50 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'TestSetup'
|
4
|
+
require 'test/unit'
|
5
|
+
require 'rubygems'
|
6
|
+
require_gem 'fireruby'
|
7
|
+
|
8
|
+
include FireRuby
|
9
|
+
|
10
|
+
class AddRemoveUserTest < Test::Unit::TestCase
|
11
|
+
CURDIR = "#{Dir.getwd}"
|
12
|
+
DB_FILE = "#{CURDIR}#{File::SEPARATOR}add_remove_user_unit_test.fdb"
|
13
|
+
|
14
|
+
def setup
|
15
|
+
# Remove existing database files.
|
16
|
+
@database = Database.new(DB_FILE)
|
17
|
+
if File.exist?(DB_FILE)
|
18
|
+
@database.drop(DB_USER_NAME, DB_PASSWORD)
|
19
|
+
end
|
20
|
+
Database.create(DB_FILE, DB_USER_NAME, DB_PASSWORD)
|
21
|
+
end
|
22
|
+
|
23
|
+
def teardown
|
24
|
+
# Remove existing database files.
|
25
|
+
if File.exist?(DB_FILE)
|
26
|
+
@database.drop(DB_USER_NAME, DB_PASSWORD)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def test01
|
31
|
+
sm = ServiceManager.new('localhost')
|
32
|
+
sm.connect(DB_USER_NAME, DB_PASSWORD)
|
33
|
+
|
34
|
+
au = AddUser.new('newuser', 'password', 'first', 'middle', 'last')
|
35
|
+
au.execute(sm)
|
36
|
+
|
37
|
+
cxn = @database.connect('newuser', 'password')
|
38
|
+
cxn.close
|
39
|
+
|
40
|
+
ru = RemoveUser.new('newuser')
|
41
|
+
ru.execute(sm)
|
42
|
+
|
43
|
+
begin
|
44
|
+
cxn = @database.connect('newuser', 'password')
|
45
|
+
cxn.close
|
46
|
+
assert(false, "Able to connect as supposedly removed user.")
|
47
|
+
rescue FireRubyException
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'TestSetup'
|
4
|
+
require 'test/unit'
|
5
|
+
require 'rubygems'
|
6
|
+
require_gem 'fireruby'
|
7
|
+
|
8
|
+
include FireRuby
|
9
|
+
|
10
|
+
class BackupRestoreTest < Test::Unit::TestCase
|
11
|
+
CURDIR = "#{Dir.getwd}"
|
12
|
+
DB_FILE = "#{CURDIR}#{File::SEPARATOR}backup_restore_unit_test.fdb"
|
13
|
+
BACKUP_FILE = "#{CURDIR}#{File::SEPARATOR}database.bak"
|
14
|
+
|
15
|
+
def setup
|
16
|
+
# Remove existing database files.
|
17
|
+
if File.exist?(DB_FILE)
|
18
|
+
db = Database.new(DB_FILE).drop(DB_USER_NAME, DB_PASSWORD)
|
19
|
+
end
|
20
|
+
|
21
|
+
if File.exist?(BACKUP_FILE)
|
22
|
+
File.delete(BACKUP_FILE)
|
23
|
+
end
|
24
|
+
|
25
|
+
# Create and populate the database files.
|
26
|
+
@database = Database.create(DB_FILE, DB_USER_NAME, DB_PASSWORD)
|
27
|
+
@database.connect(DB_USER_NAME, DB_PASSWORD) do |cxn|
|
28
|
+
cxn.execute_immediate('create table test(id integer)')
|
29
|
+
cxn.execute_immediate('insert into test values (1000)')
|
30
|
+
cxn.execute_immediate('insert into test values (2000)')
|
31
|
+
cxn.execute_immediate('insert into test values (NULL)')
|
32
|
+
cxn.execute_immediate('insert into test values (3000)')
|
33
|
+
cxn.execute_immediate('insert into test values (4000)')
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def teardown
|
38
|
+
# Remove existing database files.
|
39
|
+
if File.exist?(DB_FILE)
|
40
|
+
db = Database.new(DB_FILE).drop(DB_USER_NAME, DB_PASSWORD)
|
41
|
+
end
|
42
|
+
|
43
|
+
if File.exist?(BACKUP_FILE)
|
44
|
+
File.delete(BACKUP_FILE)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def test01
|
49
|
+
sm = ServiceManager.new('localhost')
|
50
|
+
sm.connect(DB_USER_NAME, DB_PASSWORD)
|
51
|
+
|
52
|
+
b = Backup.new(DB_FILE, BACKUP_FILE)
|
53
|
+
b.execute(sm)
|
54
|
+
|
55
|
+
assert(File.exist?(BACKUP_FILE))
|
56
|
+
@database.drop(DB_USER_NAME, DB_PASSWORD)
|
57
|
+
assert(File.exists?(DB_FILE) == false)
|
58
|
+
|
59
|
+
r = Restore.new(BACKUP_FILE, DB_FILE)
|
60
|
+
r.execute(sm)
|
61
|
+
sm.disconnect
|
62
|
+
|
63
|
+
assert(File.exist?(DB_FILE))
|
64
|
+
@database.connect(DB_USER_NAME, DB_PASSWORD) do |cxn|
|
65
|
+
total = 0
|
66
|
+
cxn.execute_immediate('select * from test') do |row|
|
67
|
+
assert([1000, 2000, 3000, 4000, nil].include?(row[0]))
|
68
|
+
total += 1
|
69
|
+
end
|
70
|
+
assert(total == 5)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def test02
|
75
|
+
sm = ServiceManager.new('localhost')
|
76
|
+
sm.connect(DB_USER_NAME, DB_PASSWORD)
|
77
|
+
|
78
|
+
b = Backup.new(DB_FILE, BACKUP_FILE)
|
79
|
+
b.metadata_only = true
|
80
|
+
b.execute(sm)
|
81
|
+
|
82
|
+
assert(File.exist?(BACKUP_FILE))
|
83
|
+
@database.drop(DB_USER_NAME, DB_PASSWORD)
|
84
|
+
assert(File.exists?(DB_FILE) == false)
|
85
|
+
|
86
|
+
r = Restore.new(BACKUP_FILE, DB_FILE)
|
87
|
+
r.execute(sm)
|
88
|
+
sm.disconnect
|
89
|
+
|
90
|
+
assert(File.exist?(DB_FILE))
|
91
|
+
@database.connect(DB_USER_NAME, DB_PASSWORD) do |cxn|
|
92
|
+
cxn.execute_immediate('select count(*) from test') do |row|
|
93
|
+
assert(row[0] == 0)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
data/test/ConnectionTest.rb
CHANGED
@@ -16,7 +16,7 @@ class ConnectionTest < Test::Unit::TestCase
|
|
16
16
|
Database.new(DB_FILE).drop(DB_USER_NAME, DB_PASSWORD)
|
17
17
|
end
|
18
18
|
|
19
|
-
@database = Database.create(DB_FILE, DB_USER_NAME, DB_PASSWORD
|
19
|
+
@database = Database.create(DB_FILE, DB_USER_NAME, DB_PASSWORD)
|
20
20
|
@connections = []
|
21
21
|
end
|
22
22
|
|
data/test/DDLTest.rb
CHANGED
@@ -15,7 +15,7 @@ class DDLTest < Test::Unit::TestCase
|
|
15
15
|
if File::exist?(DB_FILE)
|
16
16
|
Database.new(DB_FILE).drop(DB_USER_NAME, DB_PASSWORD)
|
17
17
|
end
|
18
|
-
@database = Database::create(DB_FILE, DB_USER_NAME, DB_PASSWORD
|
18
|
+
@database = Database::create(DB_FILE, DB_USER_NAME, DB_PASSWORD)
|
19
19
|
end
|
20
20
|
|
21
21
|
def teardown
|
@@ -26,25 +26,33 @@ class DDLTest < Test::Unit::TestCase
|
|
26
26
|
|
27
27
|
def test01
|
28
28
|
@database.connect(DB_USER_NAME, DB_PASSWORD) do |cxn|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
29
|
+
begin
|
30
|
+
cxn.execute_immediate('CREATE TABLE DDL_TABLE_01 (TABLEID '\
|
31
|
+
'INTEGER NOT NULL, '\
|
32
|
+
'FIELD01 FLOAT, FIELD02 CHAR(50), '\
|
33
|
+
'FIELD03 BIGINT, FIELD04 TIMESTAMP '\
|
34
|
+
'NOT NULL, FIELD05 VARCHAR(600))')
|
34
35
|
|
35
|
-
|
36
|
-
|
37
|
-
|
36
|
+
cxn.start_transaction do |tx|
|
37
|
+
r = tx.execute('SELECT COUNT(*) FROM DDL_TABLE_01')
|
38
|
+
assert(r.fetch[0] == 0)
|
39
|
+
r.close
|
40
|
+
end
|
38
41
|
|
39
|
-
|
40
|
-
|
42
|
+
cxn.execute_immediate('ALTER TABLE DDL_TABLE_01 ADD PRIMARY KEY '\
|
43
|
+
'(TABLEID)')
|
41
44
|
|
42
|
-
|
45
|
+
cxn.execute_immediate('CREATE UNIQUE INDEX DDL_TABLE_IDX ON '\
|
43
46
|
'DDL_TABLE_01 (TABLEID)')
|
44
47
|
|
45
|
-
|
48
|
+
cxn.execute_immediate('DROP INDEX DDL_TABLE_IDX')
|
46
49
|
|
47
|
-
|
50
|
+
cxn.execute_immediate('DROP TABLE DDL_TABLE_01')
|
51
|
+
rescue Exception => error
|
52
|
+
puts error.message
|
53
|
+
error.backtrace.each {|step| puts " #{step}"}
|
54
|
+
raise
|
55
|
+
end
|
48
56
|
end
|
49
57
|
end
|
50
58
|
end
|
data/test/GeneratorTest.rb
CHANGED
@@ -13,9 +13,9 @@ class GeneratorTest < Test::Unit::TestCase
|
|
13
13
|
|
14
14
|
def setup
|
15
15
|
if File::exist?(DB_FILE)
|
16
|
-
Database.new(DB_USER_NAME, DB_PASSWORD
|
16
|
+
Database.new(DB_FILE).drop(DB_USER_NAME, DB_PASSWORD)
|
17
17
|
end
|
18
|
-
@database = Database::create(DB_FILE, DB_USER_NAME, DB_PASSWORD
|
18
|
+
@database = Database::create(DB_FILE, DB_USER_NAME, DB_PASSWORD)
|
19
19
|
@connections = []
|
20
20
|
|
21
21
|
@connections.push(@database.connect(DB_USER_NAME, DB_PASSWORD))
|
data/test/ResultSetTest.rb
CHANGED
@@ -15,7 +15,7 @@ class ResultSetTest < Test::Unit::TestCase
|
|
15
15
|
if File::exist?(DB_FILE)
|
16
16
|
Database.new(DB_FILE).drop(DB_USER_NAME, DB_PASSWORD)
|
17
17
|
end
|
18
|
-
@database = Database::create(DB_FILE, DB_USER_NAME, DB_PASSWORD
|
18
|
+
@database = Database::create(DB_FILE, DB_USER_NAME, DB_PASSWORD)
|
19
19
|
@connections = []
|
20
20
|
@transactions = []
|
21
21
|
|
@@ -58,12 +58,13 @@ class ResultSetTest < Test::Unit::TestCase
|
|
58
58
|
end
|
59
59
|
|
60
60
|
def test01
|
61
|
-
|
62
|
-
"SELECT * FROM TEST_TABLE ORDER BY TESTID", 3)
|
61
|
+
r = ResultSet.new(@connections[0], @transactions[0],
|
62
|
+
"SELECT * FROM TEST_TABLE ORDER BY TESTID", 3, nil)
|
63
63
|
|
64
|
-
r
|
65
|
-
|
66
|
-
assert(r.
|
64
|
+
assert(r.connection == @connections[0])
|
65
|
+
assert(r.transaction == @transactions[0])
|
66
|
+
assert(r.sql == "SELECT * FROM TEST_TABLE ORDER BY TESTID")
|
67
|
+
assert(r.dialect == 3)
|
67
68
|
|
68
69
|
assert(r.fetch != nil)
|
69
70
|
assert(r.fetch.class == Row)
|
@@ -71,8 +72,10 @@ class ResultSetTest < Test::Unit::TestCase
|
|
71
72
|
assert(r.fetch[1] == 'Record Four.')
|
72
73
|
r.fetch
|
73
74
|
assert(r.fetch == nil)
|
75
|
+
r.close
|
74
76
|
|
75
|
-
r = ResultSet.new(
|
77
|
+
r = ResultSet.new(@connections[0], @transactions[0],
|
78
|
+
"SELECT * FROM TEST_TABLE ORDER BY TESTID", 3, nil)
|
76
79
|
assert(r.column_count == 2)
|
77
80
|
assert(r.column_name(0) == 'TESTID')
|
78
81
|
assert(r.column_name(1) == 'TESTINFO')
|
@@ -86,12 +89,43 @@ class ResultSetTest < Test::Unit::TestCase
|
|
86
89
|
assert(r.column_alias(1) == 'TESTINFO')
|
87
90
|
assert(r.column_alias(3) == nil)
|
88
91
|
assert(r.column_alias(-1) == nil)
|
92
|
+
r.close
|
89
93
|
|
90
|
-
r = ResultSet.new(
|
94
|
+
r = ResultSet.new(@connections[0], @transactions[0],
|
95
|
+
"SELECT * FROM TEST_TABLE ORDER BY TESTID", 3, nil)
|
91
96
|
total = 0
|
92
97
|
r.each do |row|
|
93
98
|
total += 1
|
94
99
|
end
|
95
100
|
assert(total == 5)
|
101
|
+
r.close
|
102
|
+
end
|
103
|
+
|
104
|
+
def test02
|
105
|
+
r = ResultSet.new(@connections[0], @transactions[0],
|
106
|
+
'select * from test_table where testid between ? and ?',
|
107
|
+
3, [20, 40])
|
108
|
+
assert(r.exhausted? == false)
|
109
|
+
total = 0
|
110
|
+
r.each {|row| total += 1}
|
111
|
+
assert(total ==3)
|
112
|
+
end
|
113
|
+
|
114
|
+
def test03
|
115
|
+
begin
|
116
|
+
ResultSet.new(@connections[0], @transactions[0],
|
117
|
+
"insert into test_table values(?, ?)", 3,
|
118
|
+
[100, 'Should fail.'])
|
119
|
+
assert(false, "Created result set with non-query SQL statement.")
|
120
|
+
rescue FireRubyException
|
121
|
+
end
|
122
|
+
|
123
|
+
begin
|
124
|
+
ResultSet.new(@connections[0], @transactions[0],
|
125
|
+
"select * from test_table where testid = ?", 3,
|
126
|
+
[])
|
127
|
+
assert(false, 'Created result set with insufficient parameters.')
|
128
|
+
rescue FireRubyException
|
129
|
+
end
|
96
130
|
end
|
97
131
|
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'TestSetup'
|
4
|
+
require 'test/unit'
|
5
|
+
require 'rubygems'
|
6
|
+
require_gem 'fireruby'
|
7
|
+
|
8
|
+
include FireRuby
|
9
|
+
|
10
|
+
class RowCountTest < Test::Unit::TestCase
|
11
|
+
CURDIR = "#{Dir.getwd}"
|
12
|
+
DB_FILE = "#{CURDIR}#{File::SEPARATOR}row_count_test.fdb"
|
13
|
+
|
14
|
+
def setup
|
15
|
+
# Create the database for use in testing.
|
16
|
+
if File.exist?(DB_FILE)
|
17
|
+
Database.new(DB_FILE).drop(DB_USER_NAME, DB_PASSWORD)
|
18
|
+
end
|
19
|
+
@database = Database.create(DB_FILE, DB_USER_NAME, DB_PASSWORD)
|
20
|
+
|
21
|
+
# Create the test table.
|
22
|
+
@database.connect(DB_USER_NAME, DB_PASSWORD) do |cxn|
|
23
|
+
cxn.execute_immediate('create table test(id integer)')
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
def teardown
|
29
|
+
if File.exist?(DB_FILE)
|
30
|
+
@database.drop(DB_USER_NAME, DB_PASSWORD)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def test01
|
35
|
+
@database.connect(DB_USER_NAME, DB_PASSWORD) do |cxn|
|
36
|
+
cxn.start_transaction do |tx|
|
37
|
+
assert(cxn.execute_immediate('insert into test values (1000)') == 1)
|
38
|
+
assert(cxn.execute_immediate('insert into test values (1000)') == 1)
|
39
|
+
assert(cxn.execute('insert into test values (2000)', tx) == 1)
|
40
|
+
assert(cxn.execute('insert into test values (2000)', tx) == 1)
|
41
|
+
assert(tx.execute('insert into test values (3000)') == 1)
|
42
|
+
assert(tx.execute('insert into test values (3000)') == 1)
|
43
|
+
assert(tx.execute('insert into test values (4000)') == 1)
|
44
|
+
assert(tx.execute('insert into test values (4000)') == 1)
|
45
|
+
|
46
|
+
assert(cxn.execute_immediate('update test set id = 10000 where '\
|
47
|
+
'id = 1000') == 2)
|
48
|
+
assert(cxn.execute('update test set id = 20000 where id = 2000',
|
49
|
+
tx) == 2)
|
50
|
+
assert(tx.execute('update test set id = 30000 where id = 3000') == 2)
|
51
|
+
|
52
|
+
s = Statement.new(cxn, tx, 'update test set id = 40000 where id = ?',
|
53
|
+
3)
|
54
|
+
assert(s.execute_for([4000]) == 2)
|
55
|
+
|
56
|
+
|
57
|
+
assert(cxn.execute_immediate('delete from test where id = 10000') == 2)
|
58
|
+
assert(cxn.execute('delete from test where id = 20000', tx) == 2)
|
59
|
+
assert(tx.execute('delete from test where id = 30000') == 2)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
data/test/RowTest.rb
CHANGED
@@ -16,19 +16,21 @@ class RowTest < Test::Unit::TestCase
|
|
16
16
|
Database.new(DB_FILE).drop(DB_USER_NAME, DB_PASSWORD)
|
17
17
|
end
|
18
18
|
|
19
|
-
database = Database::create(DB_FILE, DB_USER_NAME, DB_PASSWORD
|
19
|
+
database = Database::create(DB_FILE, DB_USER_NAME, DB_PASSWORD)
|
20
20
|
@connection = database.connect(DB_USER_NAME, DB_PASSWORD)
|
21
21
|
@transaction = @connection.start_transaction
|
22
|
-
@
|
23
|
-
'SELECT * FROM RDB$FIELDS', 3)
|
24
|
-
@results = ResultSet.new(@statement)
|
22
|
+
@results = ResultSet.new(@connection, @transaction,
|
23
|
+
'SELECT * FROM RDB$FIELDS', 3, nil)
|
25
24
|
@empty = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
26
25
|
0, 0, 0, 0, 0, 0, 0, 0, 0]
|
26
|
+
|
27
|
+
@connection.execute_immediate('create table rowtest (COL01 integer, '\
|
28
|
+
'COL02 varchar(10), COL03 integer)')
|
29
|
+
@connection.execute_immediate("insert into rowtest values (1, 'Two', 3)")
|
27
30
|
end
|
28
31
|
|
29
32
|
def teardown
|
30
33
|
@results.close
|
31
|
-
@statement.close
|
32
34
|
@transaction.rollback
|
33
35
|
@connection.close
|
34
36
|
if File::exist?(DB_FILE)
|
@@ -46,4 +48,90 @@ class RowTest < Test::Unit::TestCase
|
|
46
48
|
assert(row[0] == 0)
|
47
49
|
assert(row['RDB$FIELD_TYPE'] == 0)
|
48
50
|
end
|
51
|
+
|
52
|
+
def test02
|
53
|
+
sql = 'select COL01 one, COL02 two, COL03 three from rowtest'
|
54
|
+
rows = @connection.execute_immediate(sql)
|
55
|
+
data = rows.fetch
|
56
|
+
|
57
|
+
count = 0
|
58
|
+
data.each do |name, value|
|
59
|
+
assert(['COL01', 'COL02', 'COL03'].include?(name))
|
60
|
+
assert([1, 'Two', 3].include?(value))
|
61
|
+
count += 1
|
62
|
+
end
|
63
|
+
assert(count == 3)
|
64
|
+
|
65
|
+
count = 0
|
66
|
+
data.each_key do |name|
|
67
|
+
assert(['COL01', 'COL02', 'COL03'].include?(name))
|
68
|
+
count += 1
|
69
|
+
end
|
70
|
+
assert(count == 3)
|
71
|
+
|
72
|
+
count = 0
|
73
|
+
data.each_value do |value|
|
74
|
+
assert([1, 'Two', 3].include?(value))
|
75
|
+
count += 1
|
76
|
+
end
|
77
|
+
assert(count == 3)
|
78
|
+
|
79
|
+
assert(data.fetch('COL02') == 'Two')
|
80
|
+
assert(data.fetch('COL04', 'LALALA') == 'LALALA')
|
81
|
+
assert(data.fetch('COL00') {'NOT FOUND'} == 'NOT FOUND')
|
82
|
+
begin
|
83
|
+
data.fetch('COL05')
|
84
|
+
assert(false, 'Row#fetch succeeded for non-existent column name.')
|
85
|
+
rescue IndexError
|
86
|
+
end
|
87
|
+
|
88
|
+
assert(data.has_key?('COL01'))
|
89
|
+
assert(data.has_key?('COL10') == false)
|
90
|
+
|
91
|
+
assert(data.has_alias?('TWO'))
|
92
|
+
assert(data.has_alias?('FOUR') == false)
|
93
|
+
|
94
|
+
assert(data.has_value?(3))
|
95
|
+
assert(data.has_value?('LALALA') == false)
|
96
|
+
|
97
|
+
assert(data.keys.size == 3)
|
98
|
+
data.keys.each do |name|
|
99
|
+
assert(['COL01', 'COL02', 'COL03'].include?(name))
|
100
|
+
end
|
101
|
+
|
102
|
+
assert(data.aliases.size == 3)
|
103
|
+
data.aliases.each do |name|
|
104
|
+
assert(['ONE', 'TWO', 'THREE'].include?(name))
|
105
|
+
end
|
106
|
+
|
107
|
+
assert(data.values.size == 3)
|
108
|
+
data.values.each do |value|
|
109
|
+
assert([1, 'Two', 3].include?(value))
|
110
|
+
end
|
111
|
+
|
112
|
+
array = data.select {|name, value| name == 'COL02'}
|
113
|
+
assert(array.size == 1)
|
114
|
+
assert(array[0][0] == 'COL02')
|
115
|
+
assert(array[0][1] == 'Two')
|
116
|
+
|
117
|
+
array = data.to_a
|
118
|
+
assert(array.size == 3)
|
119
|
+
assert(array.include?(['COL01', 1]))
|
120
|
+
assert(array.include?(['COL02', 'Two']))
|
121
|
+
assert(array.include?(['COL03', 3]))
|
122
|
+
|
123
|
+
hash = data.to_hash
|
124
|
+
assert(hash.length == 3)
|
125
|
+
assert(hash['COL01'] == 1)
|
126
|
+
assert(hash['COL02'] == 'Two')
|
127
|
+
assert(hash['COL03'] == 3)
|
128
|
+
|
129
|
+
array = data.values_at('COL10', 'COL02', 'COL03')
|
130
|
+
assert(array.size == 3)
|
131
|
+
assert(array.include?('Two'))
|
132
|
+
assert(array.include?(3))
|
133
|
+
assert(array.include?(nil))
|
134
|
+
|
135
|
+
rows.close
|
136
|
+
end
|
49
137
|
end
|
data/test/SQLTest.rb
CHANGED
@@ -18,8 +18,7 @@ class SQLTest < Test::Unit::TestCase
|
|
18
18
|
if File::exist?(DB_FILE)
|
19
19
|
Database.new(DB_FILE).drop(DB_USER_NAME, DB_PASSWORD)
|
20
20
|
end
|
21
|
-
@database = Database::create(DB_FILE, DB_USER_NAME, DB_PASSWORD
|
22
|
-
1024, 'ASCII')
|
21
|
+
@database = Database::create(DB_FILE, DB_USER_NAME, DB_PASSWORD)
|
23
22
|
@connections = []
|
24
23
|
@transactions = []
|
25
24
|
|
@@ -57,13 +56,17 @@ class SQLTest < Test::Unit::TestCase
|
|
57
56
|
t = Time.at(t.to_i + 5)
|
58
57
|
s.execute_for([i, i.to_s, f, t, nil, t])
|
59
58
|
end
|
59
|
+
|
60
|
+
s.close
|
60
61
|
end
|
61
62
|
end
|
62
63
|
|
63
64
|
@connections.push(@database.connect(DB_USER_NAME, DB_PASSWORD))
|
64
|
-
|
65
|
-
|
66
|
-
|
65
|
+
@connections[0].start_transaction do |tx|
|
66
|
+
r = tx.execute("SELECT COUNT(*) FROM TEST_TABLE")
|
67
|
+
assert(r.fetch[0] == ITERATIONS)
|
68
|
+
r.close
|
69
|
+
end
|
67
70
|
end
|
68
71
|
|
69
72
|
def test02
|
@@ -128,6 +131,7 @@ class SQLTest < Test::Unit::TestCase
|
|
128
131
|
s = Statement.new(@connections[0], tx,
|
129
132
|
"UPDATE TEST_TABLE SET TESTSTAMP = NULL", 3)
|
130
133
|
s.execute()
|
134
|
+
s.close
|
131
135
|
|
132
136
|
r = tx.execute("SELECT TESTSTAMP FROM TEST_TABLE")
|
133
137
|
total = 0
|
@@ -147,6 +151,7 @@ class SQLTest < Test::Unit::TestCase
|
|
147
151
|
"TESTFLOAT, TESTSTAMP) VALUES(?, ?, ?, ?)", 3)
|
148
152
|
t = Time.new
|
149
153
|
s.execute_for([25000, 'La la la', 3.14, t])
|
154
|
+
s.close
|
150
155
|
|
151
156
|
# Fetch the record and check the data.
|
152
157
|
r = tx.execute("SELECT TESTTEXT, TESTFLOAT, TESTSTAMP FROM "\
|
@@ -161,9 +166,12 @@ class SQLTest < Test::Unit::TestCase
|
|
161
166
|
@connections[0].execute_immediate("DELETE FROM TEST_TABLE WHERE TESTID "\
|
162
167
|
"IN (1, 3, 5, 7, 9, 12, 14, 16, 18, 20)")
|
163
168
|
@database.connect(DB_USER_NAME, DB_PASSWORD) do |cxn|
|
164
|
-
|
165
|
-
|
166
|
-
|
169
|
+
a = []
|
170
|
+
cxn.start_transaction do |tx|
|
171
|
+
r = tx.execute("SELECT COUNT(*) FROM TEST_TABLE")
|
172
|
+
a = r.fetch
|
173
|
+
r.close
|
174
|
+
end
|
167
175
|
assert(a[0] == 11)
|
168
176
|
end
|
169
177
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'TestSetup'
|
4
|
+
require 'test/unit'
|
5
|
+
require 'rubygems'
|
6
|
+
require_gem 'fireruby'
|
7
|
+
|
8
|
+
include FireRuby
|
9
|
+
|
10
|
+
class ServiceManagerTest < Test::Unit::TestCase
|
11
|
+
def test01
|
12
|
+
sm = ServiceManager.new('localhost')
|
13
|
+
assert(sm.connected? == false)
|
14
|
+
|
15
|
+
assert(sm.connect(DB_USER_NAME, DB_PASSWORD) == sm)
|
16
|
+
assert(sm.connected?)
|
17
|
+
|
18
|
+
assert(sm.disconnect == sm)
|
19
|
+
assert(sm.connected? == false)
|
20
|
+
end
|
21
|
+
end
|
data/test/StatementTest.rb
CHANGED
@@ -15,7 +15,7 @@ class StatementTest < Test::Unit::TestCase
|
|
15
15
|
if File::exist?(DB_FILE)
|
16
16
|
Database.new(DB_FILE).drop(DB_USER_NAME, DB_PASSWORD)
|
17
17
|
end
|
18
|
-
@database = Database::create(DB_FILE, DB_USER_NAME, DB_PASSWORD
|
18
|
+
@database = Database::create(DB_FILE, DB_USER_NAME, DB_PASSWORD)
|
19
19
|
@connections = []
|
20
20
|
@transactions = []
|
21
21
|
end
|
@@ -46,7 +46,7 @@ class StatementTest < Test::Unit::TestCase
|
|
46
46
|
assert(s1.connection == @connections[0])
|
47
47
|
assert(s1.transaction == @transactions[0])
|
48
48
|
assert(s1.dialect == 3)
|
49
|
-
assert(s1.
|
49
|
+
assert(s1.type == Statement::SELECT_STATEMENT)
|
50
50
|
|
51
51
|
s2 = Statement.new(@connections[0],
|
52
52
|
@transactions[0],
|
@@ -56,7 +56,7 @@ class StatementTest < Test::Unit::TestCase
|
|
56
56
|
assert(s2.connection == @connections[0])
|
57
57
|
assert(s2.transaction == @transactions[0])
|
58
58
|
assert(s2.dialect == 1)
|
59
|
-
assert(s2.
|
59
|
+
assert(s2.type == Statement::DELETE_STATEMENT)
|
60
60
|
end
|
61
61
|
|
62
62
|
def test02
|
data/test/TransactionTest.rb
CHANGED
@@ -16,7 +16,7 @@ class TransactionTest < Test::Unit::TestCase
|
|
16
16
|
Database.new(DB_FILE).drop(DB_USER_NAME, DB_PASSWORD)
|
17
17
|
end
|
18
18
|
|
19
|
-
@database = Database.create(DB_FILE, DB_USER_NAME, DB_PASSWORD
|
19
|
+
@database = Database.create(DB_FILE, DB_USER_NAME, DB_PASSWORD)
|
20
20
|
@connections = []
|
21
21
|
@transactions = []
|
22
22
|
|
@@ -95,14 +95,15 @@ class TransactionTest < Test::Unit::TestCase
|
|
95
95
|
sql.push("SELECT RDB$FIELD_NAME FROM RDB$FIELDS")
|
96
96
|
@transactions.push(Transaction.new(@connections[0]))
|
97
97
|
|
98
|
-
assert(@transactions[0].execute(sql[0]) ==
|
99
|
-
|
100
|
-
assert(
|
98
|
+
assert(@transactions[0].execute(sql[0]) == 0)
|
99
|
+
r = @transactions[0].execute(sql[1])
|
100
|
+
assert(r != nil)
|
101
|
+
assert(r.class == ResultSet)
|
101
102
|
|
102
103
|
total = 0
|
103
104
|
@transactions[0].execute(sql[1]) do |row|
|
104
105
|
total += 1
|
105
106
|
end
|
106
|
-
assert(total
|
107
|
+
assert(total == 88)
|
107
108
|
end
|
108
109
|
end
|
data/test/UnitTest.rb
CHANGED
@@ -5,7 +5,13 @@ require 'ConnectionTest'
|
|
5
5
|
require 'TransactionTest'
|
6
6
|
require 'StatementTest'
|
7
7
|
require 'ResultSetTest'
|
8
|
+
require 'RowCountTest'
|
8
9
|
require 'RowTest'
|
9
10
|
require 'GeneratorTest'
|
10
11
|
require 'DDLTest'
|
11
12
|
require 'SQLTest'
|
13
|
+
require 'ServiceManagerTest'
|
14
|
+
if PLATFORM.include?('powerpc-darwin') == false
|
15
|
+
require 'BackupRestoreTest'
|
16
|
+
require 'AddRemoveUserTest'
|
17
|
+
end
|