ibruby 0.5.0-i586-linux
Sign up to get free protection for your applications and to get access to all the features.
- data/doc/README +456 -0
- data/doc/license.txt +411 -0
- data/examples/example01.rb +65 -0
- data/lib/SQLType.rb +230 -0
- data/lib/ib_lib.so +0 -0
- data/lib/ibruby.rb +22 -0
- data/lib/mkdoc +1 -0
- data/lib/src.rb +1795 -0
- data/test/AddRemoveUserTest.rb +55 -0
- data/test/BackupRestoreTest.rb +99 -0
- data/test/BooleanTest.rb +113 -0
- data/test/CharacterSetTest.rb +63 -0
- data/test/ConnectionTest.rb +111 -0
- data/test/DDLTest.rb +54 -0
- data/test/DatabaseTest.rb +83 -0
- data/test/GeneratorTest.rb +50 -0
- data/test/KeyTest.rb +140 -0
- data/test/ResultSetTest.rb +164 -0
- data/test/RoleTest.rb +104 -0
- data/test/RowCountTest.rb +65 -0
- data/test/RowTest.rb +205 -0
- data/test/SQLTest.rb +182 -0
- data/test/SQLTypeTest.rb +101 -0
- data/test/ServiceManagerTest.rb +29 -0
- data/test/StatementTest.rb +135 -0
- data/test/TestSetup.rb +11 -0
- data/test/TransactionTest.rb +112 -0
- data/test/TypeTest.rb +92 -0
- data/test/UnitTest.rb +64 -0
- metadata +77 -0
@@ -0,0 +1,55 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'TestSetup'
|
4
|
+
require 'test/unit'
|
5
|
+
#require 'rubygems'
|
6
|
+
require 'ibruby'
|
7
|
+
|
8
|
+
include IBRuby
|
9
|
+
|
10
|
+
class AddRemoveUserTest < Test::Unit::TestCase
|
11
|
+
CURDIR = "#{Dir.getwd}"
|
12
|
+
DB_FILE = "#{CURDIR}#{File::SEPARATOR}add_remove_user_unit_test.ib"
|
13
|
+
|
14
|
+
def setup
|
15
|
+
puts "#{self.class.name} started." if TEST_LOGGING
|
16
|
+
# Remove existing database files.
|
17
|
+
@database = Database.new(DB_FILE)
|
18
|
+
if File.exist?(DB_FILE)
|
19
|
+
@database.drop(DB_USER_NAME, DB_PASSWORD)
|
20
|
+
end
|
21
|
+
Database.create(DB_FILE, DB_USER_NAME, DB_PASSWORD)
|
22
|
+
end
|
23
|
+
|
24
|
+
def teardown
|
25
|
+
# Remove existing database files.
|
26
|
+
if File.exist?(DB_FILE)
|
27
|
+
@database.drop(DB_USER_NAME, DB_PASSWORD)
|
28
|
+
end
|
29
|
+
puts "#{self.class.name} finished." if TEST_LOGGING
|
30
|
+
end
|
31
|
+
|
32
|
+
def test01
|
33
|
+
sm = ServiceManager.new('localhost')
|
34
|
+
sm.connect(DB_USER_NAME, DB_PASSWORD)
|
35
|
+
|
36
|
+
au = AddUser.new('newuser', 'password', 'first', 'middle', 'last')
|
37
|
+
au.execute(sm)
|
38
|
+
sleep(3)
|
39
|
+
|
40
|
+
cxn = @database.connect('newuser', 'password')
|
41
|
+
cxn.close
|
42
|
+
|
43
|
+
ru = RemoveUser.new('newuser')
|
44
|
+
ru.execute(sm)
|
45
|
+
|
46
|
+
sm.disconnect
|
47
|
+
|
48
|
+
begin
|
49
|
+
cxn = @database.connect('newuser', 'password')
|
50
|
+
cxn.close
|
51
|
+
assert(false, "Able to connect as supposedly removed user.")
|
52
|
+
rescue IBRubyException
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'TestSetup'
|
4
|
+
require 'test/unit'
|
5
|
+
#require 'rubygems'
|
6
|
+
require 'ibruby'
|
7
|
+
|
8
|
+
include IBRuby
|
9
|
+
|
10
|
+
class BackupRestoreTest < Test::Unit::TestCase
|
11
|
+
CURDIR = "#{Dir.getwd}"
|
12
|
+
DB_FILE = "#{CURDIR}#{File::SEPARATOR}backup_restore_unit_test.ib"
|
13
|
+
BACKUP_FILE = "#{CURDIR}#{File::SEPARATOR}database.ibak"
|
14
|
+
|
15
|
+
def setup
|
16
|
+
puts "#{self.class.name} started." if TEST_LOGGING
|
17
|
+
# Remove existing database files.
|
18
|
+
if File.exist?(DB_FILE)
|
19
|
+
db = Database.new(DB_FILE).drop(DB_USER_NAME, DB_PASSWORD)
|
20
|
+
end
|
21
|
+
|
22
|
+
if File.exist?(BACKUP_FILE)
|
23
|
+
File.delete(BACKUP_FILE)
|
24
|
+
end
|
25
|
+
|
26
|
+
# Create and populate the database files.
|
27
|
+
@database = Database.create(DB_FILE, DB_USER_NAME, DB_PASSWORD)
|
28
|
+
@database.connect(DB_USER_NAME, DB_PASSWORD) do |cxn|
|
29
|
+
cxn.execute_immediate('create table test(id integer)')
|
30
|
+
cxn.execute_immediate('insert into test values (1000)')
|
31
|
+
cxn.execute_immediate('insert into test values (2000)')
|
32
|
+
cxn.execute_immediate('insert into test values (NULL)')
|
33
|
+
cxn.execute_immediate('insert into test values (3000)')
|
34
|
+
cxn.execute_immediate('insert into test values (4000)')
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def teardown
|
39
|
+
# Remove existing database files.
|
40
|
+
if File.exist?(DB_FILE)
|
41
|
+
db = Database.new(DB_FILE).drop(DB_USER_NAME, DB_PASSWORD)
|
42
|
+
end
|
43
|
+
|
44
|
+
if File.exist?(BACKUP_FILE)
|
45
|
+
File.delete(BACKUP_FILE)
|
46
|
+
end
|
47
|
+
puts "#{self.class.name} finished." if TEST_LOGGING
|
48
|
+
end
|
49
|
+
|
50
|
+
def test01
|
51
|
+
sm = ServiceManager.new('localhost')
|
52
|
+
sm.connect(DB_USER_NAME, DB_PASSWORD)
|
53
|
+
|
54
|
+
b = Backup.new(DB_FILE, BACKUP_FILE)
|
55
|
+
b.execute(sm)
|
56
|
+
|
57
|
+
assert(File.exist?(BACKUP_FILE))
|
58
|
+
@database.drop(DB_USER_NAME, DB_PASSWORD)
|
59
|
+
assert(File.exists?(DB_FILE) == false)
|
60
|
+
|
61
|
+
r = Restore.new(BACKUP_FILE, DB_FILE)
|
62
|
+
r.execute(sm)
|
63
|
+
sm.disconnect
|
64
|
+
|
65
|
+
assert(File.exist?(DB_FILE))
|
66
|
+
@database.connect(DB_USER_NAME, DB_PASSWORD) do |cxn|
|
67
|
+
total = 0
|
68
|
+
cxn.execute_immediate('select * from test') do |row|
|
69
|
+
assert([1000, 2000, 3000, 4000, nil].include?(row[0]))
|
70
|
+
total += 1
|
71
|
+
end
|
72
|
+
assert(total == 5)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def test02
|
77
|
+
sm = ServiceManager.new('localhost')
|
78
|
+
sm.connect(DB_USER_NAME, DB_PASSWORD)
|
79
|
+
|
80
|
+
b = Backup.new(DB_FILE, BACKUP_FILE)
|
81
|
+
b.metadata_only = true
|
82
|
+
b.execute(sm)
|
83
|
+
|
84
|
+
assert(File.exist?(BACKUP_FILE))
|
85
|
+
@database.drop(DB_USER_NAME, DB_PASSWORD)
|
86
|
+
assert(File.exists?(DB_FILE) == false)
|
87
|
+
|
88
|
+
r = Restore.new(BACKUP_FILE, DB_FILE)
|
89
|
+
r.execute(sm)
|
90
|
+
sm.disconnect
|
91
|
+
|
92
|
+
assert(File.exist?(DB_FILE))
|
93
|
+
@database.connect(DB_USER_NAME, DB_PASSWORD) do |cxn|
|
94
|
+
cxn.execute_immediate('select count(*) from test') do |row|
|
95
|
+
assert(row[0] == 0)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
data/test/BooleanTest.rb
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'TestSetup'
|
4
|
+
require 'test/unit'
|
5
|
+
#require 'rubygems'
|
6
|
+
require 'ibruby'
|
7
|
+
|
8
|
+
include IBRuby
|
9
|
+
|
10
|
+
class RowTest < Test::Unit::TestCase
|
11
|
+
CURDIR = "#{Dir.getwd}"
|
12
|
+
DB_FILE = "#{CURDIR}#{File::SEPARATOR}boolean_unit_test.ib"
|
13
|
+
|
14
|
+
def setup
|
15
|
+
puts "#{self.class.name} started." if TEST_LOGGING
|
16
|
+
if File::exist?(DB_FILE)
|
17
|
+
Database.new(DB_FILE).drop(DB_USER_NAME, DB_PASSWORD)
|
18
|
+
end
|
19
|
+
|
20
|
+
database = Database::create(DB_FILE, DB_USER_NAME, DB_PASSWORD)
|
21
|
+
@connection = database.connect(DB_USER_NAME, DB_PASSWORD)
|
22
|
+
|
23
|
+
@connection.start_transaction do |tx|
|
24
|
+
tx.execute('create table bool_types (col01 boolean)')
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# test to ensure we can insert boolean data directly in
|
29
|
+
def test01
|
30
|
+
@connection.start_transaction do |tx|
|
31
|
+
tx.execute("delete from bool_types")
|
32
|
+
end
|
33
|
+
@connection.start_transaction do |tx|
|
34
|
+
tx.execute("insert into bool_types values (false)")
|
35
|
+
tx.execute("insert into bool_types values (true)")
|
36
|
+
tx.execute("insert into bool_types values (null)")
|
37
|
+
end
|
38
|
+
|
39
|
+
checkBooleanValues
|
40
|
+
end
|
41
|
+
|
42
|
+
def checkBooleanValues
|
43
|
+
sql = "select col01 from bool_types"
|
44
|
+
rows = @connection.execute_immediate(sql)
|
45
|
+
row = rows.fetch
|
46
|
+
assert(row != nil )
|
47
|
+
assert(row[0] == false)
|
48
|
+
row = rows.fetch
|
49
|
+
assert(row != nil )
|
50
|
+
assert(row[0] == true)
|
51
|
+
row = rows.fetch
|
52
|
+
assert(row != nil )
|
53
|
+
assert(row[0]==nil)
|
54
|
+
|
55
|
+
rows.close
|
56
|
+
end
|
57
|
+
|
58
|
+
#test to ensure we can insert boolean data in using
|
59
|
+
def test02
|
60
|
+
@connection.start_transaction do |tx|
|
61
|
+
tx.execute("delete from bool_types")
|
62
|
+
end
|
63
|
+
@connection.start_transaction do |tx|
|
64
|
+
stmt = Statement.new(@connection, tx,
|
65
|
+
"insert into bool_types values(?)",
|
66
|
+
3)
|
67
|
+
|
68
|
+
stmt.execute_for([false])
|
69
|
+
stmt.execute_for([true])
|
70
|
+
stmt.execute_for([nil])
|
71
|
+
end
|
72
|
+
|
73
|
+
checkBooleanValues
|
74
|
+
end
|
75
|
+
|
76
|
+
#ensures that non-valid string names cause exceptions to be thrown
|
77
|
+
def test03
|
78
|
+
@connection.start_transaction do |tx|
|
79
|
+
stmt = Statement.new(@connection, tx,
|
80
|
+
"insert into bool_types values(?)",
|
81
|
+
3)
|
82
|
+
|
83
|
+
assert_raise(IBRuby::IBRubyException) do
|
84
|
+
stmt.execute_for(['fred'])
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
# does tests for proper handling of string names for booleans (true/false)
|
90
|
+
def test04
|
91
|
+
@connection.start_transaction do |tx|
|
92
|
+
stmt = Statement.new(@connection, tx,
|
93
|
+
"insert into bool_types values(?)",
|
94
|
+
3)
|
95
|
+
|
96
|
+
assert_nothing_raised() do
|
97
|
+
assert( stmt.execute_for(['false']) == 1 )
|
98
|
+
assert( stmt.execute_for(['False']) == 1 )
|
99
|
+
assert( stmt.execute_for(['true']) == 1 )
|
100
|
+
assert( stmt.execute_for(['True']) == 1 )
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
|
106
|
+
def teardown
|
107
|
+
@connection.close
|
108
|
+
if File::exist?(DB_FILE)
|
109
|
+
Database.new(DB_FILE).drop(DB_USER_NAME, DB_PASSWORD)
|
110
|
+
end
|
111
|
+
puts "#{self.class.name} finished." if TEST_LOGGING
|
112
|
+
end
|
113
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'TestSetup'
|
4
|
+
require 'test/unit'
|
5
|
+
#require 'rubygems'
|
6
|
+
require 'ibruby'
|
7
|
+
|
8
|
+
include IBRuby
|
9
|
+
|
10
|
+
class CharacterSetTest < Test::Unit::TestCase
|
11
|
+
CURDIR = "#{Dir.getwd}"
|
12
|
+
DB_FILE = "#{CURDIR}#{File::SEPARATOR}cxnarset_unit_test.ib"
|
13
|
+
CHAR_SET = 'WIN1251'
|
14
|
+
|
15
|
+
def setup
|
16
|
+
puts "#{self.class.name} started." if TEST_LOGGING
|
17
|
+
if File::exist?(DB_FILE)
|
18
|
+
Database.new(DB_FILE).drop(DB_USER_NAME, DB_PASSWORD)
|
19
|
+
end
|
20
|
+
|
21
|
+
@database = Database.create(DB_FILE, DB_USER_NAME, DB_PASSWORD, 1024,
|
22
|
+
CHAR_SET)
|
23
|
+
end
|
24
|
+
|
25
|
+
def teardown
|
26
|
+
if File::exist?(DB_FILE)
|
27
|
+
Database.new(DB_FILE).drop(DB_USER_NAME, DB_PASSWORD)
|
28
|
+
end
|
29
|
+
puts "#{self.class.name} finished." if TEST_LOGGING
|
30
|
+
end
|
31
|
+
|
32
|
+
def test01
|
33
|
+
db = Database.new(DB_FILE, CHAR_SET)
|
34
|
+
|
35
|
+
assert(db.character_set = CHAR_SET)
|
36
|
+
|
37
|
+
db.character_set = 'ASCII'
|
38
|
+
assert(db.character_set == 'ASCII')
|
39
|
+
end
|
40
|
+
|
41
|
+
def test02
|
42
|
+
text = "�?����"
|
43
|
+
db = Database.new(DB_FILE, CHAR_SET)
|
44
|
+
|
45
|
+
begin
|
46
|
+
db.connect("SYSDBA", "masterkey") do |cxn|
|
47
|
+
cxn.start_transaction do |tr|
|
48
|
+
cxn.execute("CREATE TABLE SAMPLE_TABLE(SAMPLE_FIELD VARCHAR(100))",tr)
|
49
|
+
end
|
50
|
+
cxn.start_transaction do |tr|
|
51
|
+
cxn.execute("INSERT INTO SAMPLE_TABLE VALUES ('#{win1251_str}')",tr)
|
52
|
+
cxn.execute("SELECT * FROM SAMPLE_TABLE WHERE SAMPLE_FIELD = "\
|
53
|
+
"'#{win1251_str}'",tr) do |row|
|
54
|
+
# here we have an exception:
|
55
|
+
some_var = row['SAMPLE_FIELD']
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
rescue => error
|
60
|
+
assert("Character set unit test failure.", false)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,111 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'TestSetup'
|
4
|
+
require 'test/unit'
|
5
|
+
#require 'rubygems'
|
6
|
+
require 'ibruby'
|
7
|
+
|
8
|
+
include IBRuby
|
9
|
+
|
10
|
+
class ConnectionTest < Test::Unit::TestCase
|
11
|
+
CURDIR = "#{Dir.getwd}"
|
12
|
+
DB_FILE = "#{CURDIR}#{File::SEPARATOR}con_unit_test.ib"
|
13
|
+
|
14
|
+
def setup
|
15
|
+
puts "#{self.class.name} started." if TEST_LOGGING
|
16
|
+
if File::exist?(DB_FILE)
|
17
|
+
Database.new(DB_FILE).drop(DB_USER_NAME, DB_PASSWORD)
|
18
|
+
end
|
19
|
+
|
20
|
+
@database = Database.create(DB_FILE, DB_USER_NAME, DB_PASSWORD)
|
21
|
+
@connections = []
|
22
|
+
end
|
23
|
+
|
24
|
+
def teardown
|
25
|
+
@connections.each {|connection| connection.close}
|
26
|
+
@connections.clear
|
27
|
+
|
28
|
+
if File::exist?(DB_FILE)
|
29
|
+
Database.new(DB_FILE).drop(DB_USER_NAME, DB_PASSWORD)
|
30
|
+
end
|
31
|
+
puts "#{self.class.name} finished." if TEST_LOGGING
|
32
|
+
end
|
33
|
+
|
34
|
+
def test01
|
35
|
+
@connections.push(@database.connect(DB_USER_NAME, DB_PASSWORD))
|
36
|
+
|
37
|
+
assert(@connections[0].user == DB_USER_NAME)
|
38
|
+
assert(@connections[0].open?)
|
39
|
+
assert(@connections[0].closed? == false)
|
40
|
+
assert(@connections[0].database == @database)
|
41
|
+
assert(@connections[0].to_s == "#{DB_USER_NAME}@#{DB_FILE} (OPEN)")
|
42
|
+
|
43
|
+
@connections[0].close
|
44
|
+
assert(@connections[0].user == DB_USER_NAME)
|
45
|
+
assert(@connections[0].open? == false)
|
46
|
+
assert(@connections[0].closed?)
|
47
|
+
assert(@connections[0].database == @database)
|
48
|
+
assert(@connections[0].to_s == "(CLOSED)")
|
49
|
+
|
50
|
+
@connections[0] = @database.connect(DB_USER_NAME, DB_PASSWORD)
|
51
|
+
assert(@connections[0].open?)
|
52
|
+
@connections.push(Connection.new(@database, DB_USER_NAME, DB_PASSWORD))
|
53
|
+
assert(@connections[0].open?)
|
54
|
+
assert(@connections[1].open?)
|
55
|
+
end
|
56
|
+
|
57
|
+
def test02
|
58
|
+
@connections.push(@database.connect(DB_USER_NAME, DB_PASSWORD))
|
59
|
+
|
60
|
+
tx = @connections[0].start_transaction
|
61
|
+
assert(tx != nil)
|
62
|
+
assert(tx.class == Transaction)
|
63
|
+
assert(tx.active?)
|
64
|
+
tx.rollback
|
65
|
+
|
66
|
+
tx = nil
|
67
|
+
@connections[0].start_transaction do |transaction|
|
68
|
+
assert(transaction != nil)
|
69
|
+
assert(transaction.class == Transaction)
|
70
|
+
assert(transaction.active?)
|
71
|
+
tx = transaction
|
72
|
+
end
|
73
|
+
assert(tx != nil)
|
74
|
+
assert(tx.class == Transaction)
|
75
|
+
assert(tx.active? == false)
|
76
|
+
end
|
77
|
+
|
78
|
+
def test03
|
79
|
+
@connections.push(@database.connect(DB_USER_NAME, DB_PASSWORD))
|
80
|
+
tx = @connections[0].start_transaction
|
81
|
+
total = 0
|
82
|
+
@connections[0].execute("SELECT RDB$FIELD_NAME FROM RDB$FIELDS", tx) do |row|
|
83
|
+
total = total + 1
|
84
|
+
end
|
85
|
+
assert(total == 113) # interbase has 113 field types for a newly created database vs firebird's 88
|
86
|
+
tx.commit
|
87
|
+
|
88
|
+
total = 0
|
89
|
+
@connections[0].execute_immediate("SELECT RDB$FIELD_NAME FROM RDB$FIELDS") do |row|
|
90
|
+
total = total + 1
|
91
|
+
end
|
92
|
+
assert(total == 113)
|
93
|
+
end
|
94
|
+
|
95
|
+
def test04
|
96
|
+
connection = @database.connect(DB_USER_NAME, DB_PASSWORD)
|
97
|
+
|
98
|
+
tx1 = connection.start_transaction
|
99
|
+
tx2 = connection.start_transaction
|
100
|
+
tx3 = connection.start_transaction
|
101
|
+
|
102
|
+
tx2.rollback
|
103
|
+
assert(tx2.active? == false)
|
104
|
+
|
105
|
+
connection.close
|
106
|
+
|
107
|
+
assert(connection.closed?)
|
108
|
+
assert(tx1.active? == false)
|
109
|
+
assert(tx3.active? == false)
|
110
|
+
end
|
111
|
+
end
|
data/test/DDLTest.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'TestSetup'
|
4
|
+
require 'test/unit'
|
5
|
+
#require 'rubygems'
|
6
|
+
require 'ibruby'
|
7
|
+
|
8
|
+
include IBRuby
|
9
|
+
|
10
|
+
class DDLTest < Test::Unit::TestCase
|
11
|
+
CURDIR = "#{Dir.getwd}"
|
12
|
+
DB_FILE = "#{CURDIR}#{File::SEPARATOR}ddl_unit_test.ibb"
|
13
|
+
|
14
|
+
def setup
|
15
|
+
puts "#{self.class.name} started." if TEST_LOGGING
|
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
|
+
end
|
21
|
+
|
22
|
+
def teardown
|
23
|
+
if File::exist?(DB_FILE)
|
24
|
+
Database.new(DB_FILE).drop(DB_USER_NAME, DB_PASSWORD)
|
25
|
+
end
|
26
|
+
puts "#{self.class.name} finished." if TEST_LOGGING
|
27
|
+
end
|
28
|
+
|
29
|
+
def test01
|
30
|
+
@database.connect(DB_USER_NAME, DB_PASSWORD) do |cxn|
|
31
|
+
cxn.execute_immediate('CREATE TABLE DDL_TABLE_01 (TABLEID '\
|
32
|
+
'INTEGER NOT NULL, '\
|
33
|
+
'FIELD01 FLOAT, FIELD02 CHAR(50), '\
|
34
|
+
'FIELD03 NUMERIC(18,0), FIELD04 TIMESTAMP '\
|
35
|
+
'NOT NULL, FIELD05 VARCHAR(600))')
|
36
|
+
|
37
|
+
cxn.start_transaction do |tx|
|
38
|
+
r = tx.execute('SELECT COUNT(*) FROM DDL_TABLE_01')
|
39
|
+
assert(r.fetch[0] == 0)
|
40
|
+
r.close
|
41
|
+
end
|
42
|
+
|
43
|
+
cxn.execute_immediate('ALTER TABLE DDL_TABLE_01 ADD PRIMARY KEY '\
|
44
|
+
'(TABLEID)')
|
45
|
+
|
46
|
+
cxn.execute_immediate('CREATE UNIQUE INDEX DDL_TABLE_IDX ON '\
|
47
|
+
'DDL_TABLE_01 (TABLEID)')
|
48
|
+
|
49
|
+
cxn.execute_immediate('DROP INDEX DDL_TABLE_IDX')
|
50
|
+
|
51
|
+
cxn.execute_immediate('DROP TABLE DDL_TABLE_01')
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'TestSetup'
|
4
|
+
require 'test/unit'
|
5
|
+
#require 'rubygems'
|
6
|
+
require 'ibruby'
|
7
|
+
|
8
|
+
include IBRuby
|
9
|
+
|
10
|
+
class DatabaseTest < Test::Unit::TestCase
|
11
|
+
CURDIR = "#{Dir.getwd}"
|
12
|
+
DB_FILE = "#{CURDIR}#{File::SEPARATOR}db_unit_test.ibb"
|
13
|
+
CREATE_FILE = "#{CURDIR}#{File::SEPARATOR}db_create_test.ibb"
|
14
|
+
|
15
|
+
def setup
|
16
|
+
puts "#{self.class.name} started." if TEST_LOGGING
|
17
|
+
if File.exist?(DB_FILE)
|
18
|
+
db = Database.new(DB_FILE)
|
19
|
+
db.drop
|
20
|
+
end
|
21
|
+
if File.exist?(CREATE_FILE)
|
22
|
+
db = Database.new(CREATE_FILE)
|
23
|
+
db.drop
|
24
|
+
end
|
25
|
+
|
26
|
+
Database::create(DB_FILE, DB_USER_NAME, DB_PASSWORD, 1024, 'ASCII')
|
27
|
+
end
|
28
|
+
|
29
|
+
def teardown
|
30
|
+
if File::exist?(DB_FILE)
|
31
|
+
db = Database.new(DB_FILE)
|
32
|
+
db.drop(DB_USER_NAME, DB_PASSWORD)
|
33
|
+
end
|
34
|
+
if File::exist?(CREATE_FILE)
|
35
|
+
db = Database.new(CREATE_FILE)
|
36
|
+
db.drop(DB_USER_NAME, DB_PASSWORD)
|
37
|
+
end
|
38
|
+
puts "#{self.class.name} finished." if TEST_LOGGING
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
def test01
|
43
|
+
db = Database.create(CREATE_FILE, DB_USER_NAME, DB_PASSWORD, 2048, 'ASCII')
|
44
|
+
|
45
|
+
assert(File.exist?(CREATE_FILE))
|
46
|
+
assert(db.file == CREATE_FILE)
|
47
|
+
|
48
|
+
begin
|
49
|
+
Database.create(CREATE_FILE, DB_USER_NAME, DB_PASSWORD, 2048, 'ASCII')
|
50
|
+
assert(false,
|
51
|
+
"Successfully created a database file that already exists.")
|
52
|
+
rescue Exception
|
53
|
+
end
|
54
|
+
|
55
|
+
db.drop(DB_USER_NAME, DB_PASSWORD)
|
56
|
+
assert(File.exist?(CREATE_FILE) == false)
|
57
|
+
end
|
58
|
+
|
59
|
+
def test02
|
60
|
+
db = Database.new(DB_FILE);
|
61
|
+
|
62
|
+
assert(db.file == DB_FILE)
|
63
|
+
|
64
|
+
c = db.connect(DB_USER_NAME, DB_PASSWORD)
|
65
|
+
assert(c != nil)
|
66
|
+
c.close
|
67
|
+
end
|
68
|
+
|
69
|
+
def test03
|
70
|
+
db = Database.new(DB_FILE);
|
71
|
+
c = nil
|
72
|
+
|
73
|
+
db.connect(DB_USER_NAME, DB_PASSWORD) do |connection|
|
74
|
+
assert(connection != nil)
|
75
|
+
assert(connection.class == Connection)
|
76
|
+
assert(connection.open?)
|
77
|
+
c = connection
|
78
|
+
end
|
79
|
+
assert(c != nil)
|
80
|
+
assert(c.class == Connection)
|
81
|
+
assert(c.closed?)
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'TestSetup'
|
4
|
+
require 'test/unit'
|
5
|
+
#require 'rubygems'
|
6
|
+
require 'ibruby'
|
7
|
+
|
8
|
+
include IBRuby
|
9
|
+
|
10
|
+
class GeneratorTest < Test::Unit::TestCase
|
11
|
+
CURDIR = "#{Dir.getwd}"
|
12
|
+
DB_FILE = "#{CURDIR}#{File::SEPARATOR}generator_unit_test.ib"
|
13
|
+
|
14
|
+
def setup
|
15
|
+
puts "#{self.class.name} started." if TEST_LOGGING
|
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
|
+
@connections = []
|
21
|
+
|
22
|
+
@connections.push(@database.connect(DB_USER_NAME, DB_PASSWORD))
|
23
|
+
end
|
24
|
+
|
25
|
+
def teardown
|
26
|
+
@connections.each do |cxn|
|
27
|
+
cxn.close if cxn.open?
|
28
|
+
end
|
29
|
+
@connections.clear
|
30
|
+
if File::exist?(DB_FILE)
|
31
|
+
Database.new(DB_FILE).drop(DB_USER_NAME, DB_PASSWORD)
|
32
|
+
end
|
33
|
+
puts "#{self.class.name} finished." if TEST_LOGGING
|
34
|
+
end
|
35
|
+
|
36
|
+
def test01
|
37
|
+
assert(Generator::exists?('TEST_GEN', @connections[0]) == false)
|
38
|
+
g = Generator::create('TEST_GEN', @connections[0])
|
39
|
+
assert(Generator::exists?('TEST_GEN', @connections[0]))
|
40
|
+
assert(g.last == 0)
|
41
|
+
assert(g.next(1) == 1)
|
42
|
+
assert(g.last == 1)
|
43
|
+
assert(g.next(10) == 11)
|
44
|
+
assert(g.connection == @connections[0])
|
45
|
+
assert(g.name == 'TEST_GEN')
|
46
|
+
|
47
|
+
g.drop
|
48
|
+
assert(Generator::exists?('TEST_GEN', @connections[0]) == false)
|
49
|
+
end
|
50
|
+
end
|