rubyfb 0.5.2-x86-mswin32-60
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +6 -0
- data/LICENSE +411 -0
- data/Manifest +75 -0
- data/README +460 -0
- data/Rakefile +21 -0
- data/examples/example01.rb +65 -0
- data/ext/AddUser.c +464 -0
- data/ext/AddUser.h +37 -0
- data/ext/Backup.c +783 -0
- data/ext/Backup.h +37 -0
- data/ext/Blob.c +421 -0
- data/ext/Blob.h +65 -0
- data/ext/Common.c +54 -0
- data/ext/Common.h +37 -0
- data/ext/Connection.c +863 -0
- data/ext/Connection.h +50 -0
- data/ext/DataArea.c +274 -0
- data/ext/DataArea.h +38 -0
- data/ext/Database.c +449 -0
- data/ext/Database.h +48 -0
- data/ext/FireRuby.c +240 -0
- data/ext/FireRuby.h +50 -0
- data/ext/FireRubyException.c +268 -0
- data/ext/FireRubyException.h +51 -0
- data/ext/Generator.c +689 -0
- data/ext/Generator.h +53 -0
- data/ext/RemoveUser.c +212 -0
- data/ext/RemoveUser.h +37 -0
- data/ext/Restore.c +855 -0
- data/ext/Restore.h +37 -0
- data/ext/ResultSet.c +810 -0
- data/ext/ResultSet.h +60 -0
- data/ext/Row.c +965 -0
- data/ext/Row.h +55 -0
- data/ext/ServiceManager.c +316 -0
- data/ext/ServiceManager.h +48 -0
- data/ext/Services.c +124 -0
- data/ext/Services.h +42 -0
- data/ext/Statement.c +785 -0
- data/ext/Statement.h +62 -0
- data/ext/Transaction.c +684 -0
- data/ext/Transaction.h +50 -0
- data/ext/TypeMap.c +1182 -0
- data/ext/TypeMap.h +51 -0
- data/ext/extconf.rb +30 -0
- data/lib/SQLType.rb +224 -0
- data/lib/active_record/connection_adapters/rubyfb_adapter.rb +805 -0
- data/lib/mkdoc +1 -0
- data/lib/rubyfb.rb +2 -0
- data/lib/rubyfb_lib.so +0 -0
- data/lib/src.rb +1800 -0
- data/mswin32fb/fbclient_ms.lib +0 -0
- data/mswin32fb/ibase.h +2555 -0
- data/mswin32fb/iberror.h +1741 -0
- data/rubyfb.gemspec +31 -0
- data/test/AddRemoveUserTest.rb +56 -0
- data/test/BackupRestoreTest.rb +99 -0
- data/test/BlobTest.rb +57 -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 +162 -0
- data/test/RoleTest.rb +73 -0
- data/test/RowCountTest.rb +65 -0
- data/test/RowTest.rb +203 -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 +65 -0
- metadata +143 -0
data/test/SQLTypeTest.rb
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'TestSetup'
|
4
|
+
require 'test/unit'
|
5
|
+
require 'rubygems'
|
6
|
+
require 'fireruby'
|
7
|
+
|
8
|
+
include FireRuby
|
9
|
+
|
10
|
+
class SQLTypeTest < Test::Unit::TestCase
|
11
|
+
CURDIR = "#{Dir.getwd}"
|
12
|
+
DB_FILE = "#{CURDIR}#{File::SEPARATOR}sql_type_test.fdb"
|
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 all_types (col01 bigint, col02 blob, "\
|
25
|
+
"col03 char(100), col04 date, col05 decimal(5,2), "\
|
26
|
+
"col06 double precision, col07 float, col08 integer, "\
|
27
|
+
"col09 numeric(10,3), col10 smallint, col11 time, "\
|
28
|
+
"col12 timestamp, col13 varchar(23))")
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def teardown
|
33
|
+
@connection.close if @connection != nil && @connection.open?
|
34
|
+
|
35
|
+
if File::exist?(DB_FILE)
|
36
|
+
Database.new(DB_FILE).drop(DB_USER_NAME, DB_PASSWORD)
|
37
|
+
end
|
38
|
+
puts "#{self.class.name} finished." if TEST_LOGGING
|
39
|
+
end
|
40
|
+
|
41
|
+
def test01
|
42
|
+
types = []
|
43
|
+
types.push(SQLType.new(SQLType::BIGINT))
|
44
|
+
types.push(SQLType.new(SQLType::VARCHAR, 1000))
|
45
|
+
types.push(SQLType.new(SQLType::DECIMAL, nil, 10))
|
46
|
+
types.push(SQLType.new(SQLType::NUMERIC, nil, 5, 3))
|
47
|
+
types.push(SQLType.new(SQLType::BLOB, nil, nil, nil, 1))
|
48
|
+
|
49
|
+
assert(types[0] == types[0])
|
50
|
+
assert(!(types[0] == types[1]))
|
51
|
+
assert(types[1] == SQLType.new(SQLType::VARCHAR, 1000))
|
52
|
+
|
53
|
+
assert(types[0].type == SQLType::BIGINT)
|
54
|
+
assert(types[0].length == nil)
|
55
|
+
assert(types[0].precision == nil)
|
56
|
+
assert(types[0].scale == nil)
|
57
|
+
assert(types[0].subtype == nil)
|
58
|
+
|
59
|
+
assert(types[1].type == SQLType::VARCHAR)
|
60
|
+
assert(types[1].length == 1000)
|
61
|
+
assert(types[1].precision == nil)
|
62
|
+
assert(types[1].scale == nil)
|
63
|
+
assert(types[1].subtype == nil)
|
64
|
+
|
65
|
+
assert(types[2].type == SQLType::DECIMAL)
|
66
|
+
assert(types[2].length == nil)
|
67
|
+
assert(types[2].precision == 10)
|
68
|
+
assert(types[2].scale == nil)
|
69
|
+
assert(types[2].subtype == nil)
|
70
|
+
|
71
|
+
assert(types[3].type == SQLType::NUMERIC)
|
72
|
+
assert(types[3].length == nil)
|
73
|
+
assert(types[3].precision == 5)
|
74
|
+
assert(types[3].scale == 3)
|
75
|
+
assert(types[3].subtype == nil)
|
76
|
+
|
77
|
+
assert(types[4].type == SQLType::BLOB)
|
78
|
+
assert(types[4].length == nil)
|
79
|
+
assert(types[4].precision == nil)
|
80
|
+
assert(types[4].scale == nil)
|
81
|
+
assert(types[4].subtype == 1)
|
82
|
+
end
|
83
|
+
|
84
|
+
def test02
|
85
|
+
types = SQLType.for_table("all_types", @connection)
|
86
|
+
|
87
|
+
assert(types['COL01'] == SQLType.new(SQLType::BIGINT))
|
88
|
+
assert(types['COL02'] == SQLType.new(SQLType::BLOB, nil, nil, nil, 0))
|
89
|
+
assert(types['COL03'] == SQLType.new(SQLType::CHAR, 100))
|
90
|
+
assert(types['COL04'] == SQLType.new(SQLType::DATE))
|
91
|
+
assert(types['COL05'] == SQLType.new(SQLType::DECIMAL, nil, 5, 2))
|
92
|
+
assert(types['COL06'] == SQLType.new(SQLType::DOUBLE))
|
93
|
+
assert(types['COL07'] == SQLType.new(SQLType::FLOAT))
|
94
|
+
assert(types['COL08'] == SQLType.new(SQLType::INTEGER))
|
95
|
+
assert(types['COL09'] == SQLType.new(SQLType::NUMERIC, nil, 10, 3))
|
96
|
+
assert(types['COL10'] == SQLType.new(SQLType::SMALLINT))
|
97
|
+
assert(types['COL11'] == SQLType.new(SQLType::TIME))
|
98
|
+
assert(types['COL12'] == SQLType.new(SQLType::TIMESTAMP))
|
99
|
+
assert(types['COL13'] == SQLType.new(SQLType::VARCHAR, 23))
|
100
|
+
end
|
101
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'TestSetup'
|
4
|
+
require 'test/unit'
|
5
|
+
require 'rubygems'
|
6
|
+
require 'fireruby'
|
7
|
+
|
8
|
+
include FireRuby
|
9
|
+
|
10
|
+
class ServiceManagerTest < Test::Unit::TestCase
|
11
|
+
def setup
|
12
|
+
puts "#{self.class.name} started." if TEST_LOGGING
|
13
|
+
end
|
14
|
+
|
15
|
+
def teardown
|
16
|
+
puts "#{self.class.name} finished." if TEST_LOGGING
|
17
|
+
end
|
18
|
+
|
19
|
+
def test01
|
20
|
+
sm = ServiceManager.new('localhost')
|
21
|
+
assert(sm.connected? == false)
|
22
|
+
|
23
|
+
assert(sm.connect(DB_USER_NAME, DB_PASSWORD) == sm)
|
24
|
+
assert(sm.connected?)
|
25
|
+
|
26
|
+
assert(sm.disconnect == sm)
|
27
|
+
assert(sm.connected? == false)
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,135 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'TestSetup'
|
4
|
+
require 'test/unit'
|
5
|
+
require 'rubygems'
|
6
|
+
require 'fireruby'
|
7
|
+
|
8
|
+
include FireRuby
|
9
|
+
|
10
|
+
class StatementTest < Test::Unit::TestCase
|
11
|
+
CURDIR = "#{Dir.getwd}"
|
12
|
+
DB_FILE = "#{CURDIR}#{File::SEPARATOR}stmt_unit_test.fdb"
|
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
|
+
@transactions = []
|
22
|
+
end
|
23
|
+
|
24
|
+
def teardown
|
25
|
+
@transactions.each do |tx|
|
26
|
+
tx.rollback if tx.active?
|
27
|
+
end
|
28
|
+
@transactions.clear
|
29
|
+
@connections.each do |cxn|
|
30
|
+
cxn.close if cxn.open?
|
31
|
+
end
|
32
|
+
@connections.clear
|
33
|
+
if File::exist?(DB_FILE)
|
34
|
+
Database.new(DB_FILE).drop(DB_USER_NAME, DB_PASSWORD)
|
35
|
+
end
|
36
|
+
puts "#{self.class.name} finished." if TEST_LOGGING
|
37
|
+
end
|
38
|
+
|
39
|
+
def test01
|
40
|
+
@connections.push(@database.connect(DB_USER_NAME, DB_PASSWORD))
|
41
|
+
@transactions.push(@connections.last.start_transaction)
|
42
|
+
|
43
|
+
s1 = Statement.new(@connections[0],
|
44
|
+
@transactions[0],
|
45
|
+
"SELECT RDB$FIELD_NAME FROM RDB$FIELDS", 3)
|
46
|
+
assert(s1 != nil)
|
47
|
+
assert(s1.sql == "SELECT RDB$FIELD_NAME FROM RDB$FIELDS")
|
48
|
+
assert(s1.connection == @connections[0])
|
49
|
+
assert(s1.transaction == @transactions[0])
|
50
|
+
assert(s1.dialect == 3)
|
51
|
+
assert(s1.type == Statement::SELECT_STATEMENT)
|
52
|
+
s1.close
|
53
|
+
|
54
|
+
s2 = Statement.new(@connections[0],
|
55
|
+
@transactions[0],
|
56
|
+
"DELETE FROM RDB$EXCEPTIONS", 1)
|
57
|
+
assert(s2 != nil)
|
58
|
+
assert(s2.sql == "DELETE FROM RDB$EXCEPTIONS")
|
59
|
+
assert(s2.connection == @connections[0])
|
60
|
+
assert(s2.transaction == @transactions[0])
|
61
|
+
assert(s2.dialect == 1)
|
62
|
+
assert(s2.type == Statement::DELETE_STATEMENT)
|
63
|
+
s2.close
|
64
|
+
end
|
65
|
+
|
66
|
+
def test02
|
67
|
+
@connections.push(@database.connect(DB_USER_NAME, DB_PASSWORD))
|
68
|
+
@transactions.push(@connections[0].start_transaction)
|
69
|
+
|
70
|
+
s = Statement.new(@connections[0], @transactions[0],
|
71
|
+
"SELECT RDB$FIELD_NAME FROM RDB$FIELDS "\
|
72
|
+
"WHERE RDB$FIELD_NAME LIKE ?", 3)
|
73
|
+
|
74
|
+
begin
|
75
|
+
r = s.execute
|
76
|
+
r.close
|
77
|
+
assert(false,
|
78
|
+
"Executed statement that required parameter without the "\
|
79
|
+
"parameter being specified.")
|
80
|
+
rescue Exception => error
|
81
|
+
end
|
82
|
+
|
83
|
+
begin
|
84
|
+
r = s.execute_for([])
|
85
|
+
r.close
|
86
|
+
assert(false,
|
87
|
+
"Executed statement that required a parameter with an empty "\
|
88
|
+
"parameter set.")
|
89
|
+
rescue Exception => error
|
90
|
+
end
|
91
|
+
|
92
|
+
begin
|
93
|
+
r = s.execute_for(['LALALA', 25])
|
94
|
+
r.close
|
95
|
+
assert(false,
|
96
|
+
"Executed statement that required a parameter with too many "\
|
97
|
+
"parameters.")
|
98
|
+
rescue Exception => error
|
99
|
+
end
|
100
|
+
|
101
|
+
r = s.execute_for(['LALALA'])
|
102
|
+
assert(r != nil)
|
103
|
+
assert(r.class == ResultSet)
|
104
|
+
r.close
|
105
|
+
|
106
|
+
total = 0
|
107
|
+
s.execute_for(["%"]) do |row|
|
108
|
+
total = total + 1
|
109
|
+
end
|
110
|
+
assert(total = 88)
|
111
|
+
s.close
|
112
|
+
end
|
113
|
+
|
114
|
+
def test03
|
115
|
+
d = nil
|
116
|
+
@database.connect(DB_USER_NAME, DB_PASSWORD) do |cxn|
|
117
|
+
cxn.execute_immediate('CREATE TABLE STRING_TEST(TEXT VARCHAR(10))')
|
118
|
+
cxn.start_transaction do |tx|
|
119
|
+
# Perform an truncated insert.
|
120
|
+
s = Statement.new(cxn, tx, 'INSERT INTO STRING_TEST VALUES(?)', 3)
|
121
|
+
s.execute_for(['012345678901234'])
|
122
|
+
|
123
|
+
# Perform a select of the value inserted.
|
124
|
+
r = cxn.execute('SELECT * FROM STRING_TEST', tx)
|
125
|
+
d = r.fetch
|
126
|
+
|
127
|
+
# Clean up.
|
128
|
+
s.close
|
129
|
+
r.close
|
130
|
+
end
|
131
|
+
assert(d[0] == '0123456789')
|
132
|
+
cxn.execute_immediate('DROP TABLE STRING_TEST')
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
data/test/TestSetup.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# Add extra search paths.
|
4
|
+
basedir = File::dirname(Dir.getwd)
|
5
|
+
$:.push(basedir)
|
6
|
+
$:.push("#{basedir}#{File::SEPARATOR}test")
|
7
|
+
$:.push("#{basedir}#{File::SEPARATOR}lib")
|
8
|
+
|
9
|
+
DB_USER_NAME = 'sysdba'
|
10
|
+
DB_PASSWORD = 'masterkey'
|
11
|
+
TEST_LOGGING = false
|
@@ -0,0 +1,112 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'TestSetup'
|
4
|
+
require 'test/unit'
|
5
|
+
require 'rubygems'
|
6
|
+
require 'fireruby'
|
7
|
+
|
8
|
+
include FireRuby
|
9
|
+
|
10
|
+
class TransactionTest < Test::Unit::TestCase
|
11
|
+
CURDIR = "#{Dir.getwd}"
|
12
|
+
DB_FILE = "#{CURDIR}#{File::SEPARATOR}tx_unit_test.fdb"
|
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
|
+
@transactions = []
|
23
|
+
|
24
|
+
@connections.push(@database.connect(DB_USER_NAME, DB_PASSWORD))
|
25
|
+
@connections.push(@database.connect(DB_USER_NAME, DB_PASSWORD))
|
26
|
+
@connections.push(@database.connect(DB_USER_NAME, DB_PASSWORD))
|
27
|
+
end
|
28
|
+
|
29
|
+
def teardown
|
30
|
+
@transactions.each do |tx|
|
31
|
+
tx.rollback if tx.active?
|
32
|
+
end
|
33
|
+
@transactions.clear
|
34
|
+
@connections.each do |cxn|
|
35
|
+
cxn.close if cxn.open?
|
36
|
+
end
|
37
|
+
if File::exist?(DB_FILE)
|
38
|
+
Database.new(DB_FILE).drop(DB_USER_NAME, DB_PASSWORD)
|
39
|
+
end
|
40
|
+
puts "#{self.class.name} finished." if TEST_LOGGING
|
41
|
+
end
|
42
|
+
|
43
|
+
def test01
|
44
|
+
@transactions.push(@connections[0].start_transaction)
|
45
|
+
assert(@transactions[0].active?)
|
46
|
+
|
47
|
+
@transactions.push(Transaction.new(@connections[1]))
|
48
|
+
assert(@transactions[1].active?)
|
49
|
+
|
50
|
+
assert(@transactions[0].connections == [@connections[0]])
|
51
|
+
assert(@transactions[1].connections == [@connections[1]])
|
52
|
+
|
53
|
+
assert(@transactions[0].for_connection?(@connections[1]) == false)
|
54
|
+
assert(@transactions[1].for_connection?(@connections[0]) == false)
|
55
|
+
assert(@transactions[0].for_connection?(@connections[0]))
|
56
|
+
assert(@transactions[1].for_connection?(@connections[1]))
|
57
|
+
|
58
|
+
@transactions[0].commit
|
59
|
+
assert(@transactions[0].active? == false)
|
60
|
+
assert(@transactions[0].connections == [])
|
61
|
+
assert(@transactions[0].for_connection?(@connections[0]) == false)
|
62
|
+
assert(@transactions[0].for_connection?(@connections[1]) == false)
|
63
|
+
|
64
|
+
@transactions[1].rollback
|
65
|
+
assert(@transactions[1].active? == false)
|
66
|
+
assert(@transactions[1].connections == [])
|
67
|
+
assert(@transactions[1].for_connection?(@connections[0]) == false)
|
68
|
+
assert(@transactions[1].for_connection?(@connections[1]) == false)
|
69
|
+
|
70
|
+
@transactions[0] = Transaction.new([@connections[0], @connections[1]])
|
71
|
+
assert(@transactions[0].active? == true)
|
72
|
+
assert(@transactions[0].for_connection?(@connections[0]))
|
73
|
+
assert(@transactions[0].for_connection?(@connections[1]))
|
74
|
+
assert(@transactions[0].for_connection?(@connections[2]) == false)
|
75
|
+
|
76
|
+
@transactions[0].commit
|
77
|
+
assert(@transactions[0].active? == false)
|
78
|
+
assert(@transactions[0].connections == [])
|
79
|
+
assert(@transactions[0].for_connection?(@connections[0]) == false)
|
80
|
+
assert(@transactions[0].for_connection?(@connections[1]) == false)
|
81
|
+
assert(@transactions[0].for_connection?(@connections[2]) == false)
|
82
|
+
|
83
|
+
@transactions[0] = Transaction.new([@connections[0], @connections[2]])
|
84
|
+
assert(@transactions[0].active?)
|
85
|
+
@transactions[0].rollback
|
86
|
+
assert(@transactions[0].active? == false)
|
87
|
+
assert(@transactions[0].connections == [])
|
88
|
+
assert(@transactions[0].for_connection?(@connections[0]) == false)
|
89
|
+
assert(@transactions[0].for_connection?(@connections[1]) == false)
|
90
|
+
assert(@transactions[0].for_connection?(@connections[2]) == false)
|
91
|
+
end
|
92
|
+
|
93
|
+
def test02
|
94
|
+
sql = []
|
95
|
+
sql.push("UPDATE RDB$EXCEPTIONS SET RDB$MESSAGE = 'WoooHooo'"\
|
96
|
+
"WHERE RDB$EXCEPTION_NAME = 'Lalala'")
|
97
|
+
sql.push("SELECT RDB$FIELD_NAME FROM RDB$FIELDS")
|
98
|
+
@transactions.push(Transaction.new(@connections[0]))
|
99
|
+
|
100
|
+
assert(@transactions[0].execute(sql[0]) == 0)
|
101
|
+
r = @transactions[0].execute(sql[1])
|
102
|
+
assert(r != nil)
|
103
|
+
assert(r.class == ResultSet)
|
104
|
+
r.close
|
105
|
+
|
106
|
+
total = 0
|
107
|
+
@transactions[0].execute(sql[1]) do |row|
|
108
|
+
total += 1
|
109
|
+
end
|
110
|
+
assert(total == 88)
|
111
|
+
end
|
112
|
+
end
|
data/test/TypeTest.rb
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'TestSetup'
|
4
|
+
require 'test/unit'
|
5
|
+
require 'rubygems'
|
6
|
+
require 'fireruby'
|
7
|
+
require 'date'
|
8
|
+
|
9
|
+
include FireRuby
|
10
|
+
|
11
|
+
class TypeTest < Test::Unit::TestCase
|
12
|
+
CURDIR = "#{Dir.getwd}"
|
13
|
+
DB_FILE = "#{CURDIR}#{File::SEPARATOR}types_unit_test.fdb"
|
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(DB_USER_NAME, DB_PASSWORD)
|
20
|
+
end
|
21
|
+
@db = Database.create(DB_FILE, DB_USER_NAME, DB_PASSWORD)
|
22
|
+
cxn = @db.connect(DB_USER_NAME, DB_PASSWORD)
|
23
|
+
cxn.start_transaction do |tx|
|
24
|
+
tx.execute("create table types_table (COL01 integer, "\
|
25
|
+
"COL02 float, COL03 decimal(10,2), "\
|
26
|
+
"COL04 numeric(5,3), COL05 date, COL06 timestamp, "\
|
27
|
+
"COL07 char(10), COL08 time, COL09 varchar(30))")
|
28
|
+
end
|
29
|
+
|
30
|
+
cxn.start_transaction do |tx|
|
31
|
+
stmt = Statement.new(cxn, tx, "insert into types_table values "\
|
32
|
+
"(?, ?, ?, ?, ?, ?, ?, ?, ?)", 3)
|
33
|
+
stmt.execute_for([10, 100.2, 2378.65, 192.345,
|
34
|
+
Date.new(2005, 10, 21), Time.new, 'La la la',
|
35
|
+
Time.new, "Oobly Joobly"])
|
36
|
+
stmt.close
|
37
|
+
end
|
38
|
+
cxn.close
|
39
|
+
end
|
40
|
+
|
41
|
+
def teardown
|
42
|
+
if File::exist?(DB_FILE)
|
43
|
+
@db.drop(DB_USER_NAME, DB_PASSWORD)
|
44
|
+
end
|
45
|
+
puts "#{self.class.name} finished." if TEST_LOGGING
|
46
|
+
end
|
47
|
+
|
48
|
+
def test01
|
49
|
+
rows = cxn = nil
|
50
|
+
begin
|
51
|
+
cxn = @db.connect(DB_USER_NAME, DB_PASSWORD)
|
52
|
+
rows = cxn.execute_immediate('select * from types_table')
|
53
|
+
row = rows.fetch
|
54
|
+
assert(row[0].kind_of?(Integer))
|
55
|
+
assert(row[1].instance_of?(Float))
|
56
|
+
assert(row[2].instance_of?(Float))
|
57
|
+
assert(row[3].instance_of?(Float))
|
58
|
+
assert(row[4].instance_of?(Date))
|
59
|
+
assert(row[5].instance_of?(Time))
|
60
|
+
assert(row[6].instance_of?(String))
|
61
|
+
assert(row[7].instance_of?(Time))
|
62
|
+
assert(row[8].instance_of?(String))
|
63
|
+
ensure
|
64
|
+
rows.close if rows != nil
|
65
|
+
cxn.close if cxn != nil
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def test02
|
70
|
+
$FireRubySettings[:DATE_AS_DATE] = false
|
71
|
+
rows = cxn = nil
|
72
|
+
begin
|
73
|
+
cxn = @db.connect(DB_USER_NAME, DB_PASSWORD)
|
74
|
+
rows = cxn.execute_immediate('select * from types_table')
|
75
|
+
row = rows.fetch
|
76
|
+
assert(row[0].kind_of?(Integer))
|
77
|
+
assert(row[1].instance_of?(Float))
|
78
|
+
assert(row[2].instance_of?(Float))
|
79
|
+
assert(row[3].instance_of?(Float))
|
80
|
+
assert(row[4].instance_of?(Time))
|
81
|
+
assert(row[5].instance_of?(Time))
|
82
|
+
assert(row[6].instance_of?(String))
|
83
|
+
assert(row[7].instance_of?(Time))
|
84
|
+
assert(row[8].instance_of?(String))
|
85
|
+
rows.close
|
86
|
+
ensure
|
87
|
+
rows.close if rows != nil
|
88
|
+
cxn.close if cxn != nil
|
89
|
+
end
|
90
|
+
$FireRubySettings[:DATE_AS_DATE] = true
|
91
|
+
end
|
92
|
+
end
|