rubyfb 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. data/CHANGELOG +6 -0
  2. data/LICENSE +411 -0
  3. data/Manifest +73 -0
  4. data/README +460 -0
  5. data/Rakefile +20 -0
  6. data/examples/example01.rb +65 -0
  7. data/ext/AddUser.c +464 -0
  8. data/ext/AddUser.h +37 -0
  9. data/ext/Backup.c +783 -0
  10. data/ext/Backup.h +37 -0
  11. data/ext/Blob.c +421 -0
  12. data/ext/Blob.h +65 -0
  13. data/ext/Common.c +54 -0
  14. data/ext/Common.h +37 -0
  15. data/ext/Connection.c +863 -0
  16. data/ext/Connection.h +50 -0
  17. data/ext/DataArea.c +274 -0
  18. data/ext/DataArea.h +38 -0
  19. data/ext/Database.c +449 -0
  20. data/ext/Database.h +48 -0
  21. data/ext/FireRuby.c +240 -0
  22. data/ext/FireRuby.h +50 -0
  23. data/ext/FireRubyException.c +268 -0
  24. data/ext/FireRubyException.h +51 -0
  25. data/ext/Generator.c +689 -0
  26. data/ext/Generator.h +53 -0
  27. data/ext/RemoveUser.c +212 -0
  28. data/ext/RemoveUser.h +37 -0
  29. data/ext/Restore.c +855 -0
  30. data/ext/Restore.h +37 -0
  31. data/ext/ResultSet.c +809 -0
  32. data/ext/ResultSet.h +60 -0
  33. data/ext/Row.c +965 -0
  34. data/ext/Row.h +55 -0
  35. data/ext/ServiceManager.c +316 -0
  36. data/ext/ServiceManager.h +48 -0
  37. data/ext/Services.c +124 -0
  38. data/ext/Services.h +42 -0
  39. data/ext/Statement.c +785 -0
  40. data/ext/Statement.h +62 -0
  41. data/ext/Transaction.c +684 -0
  42. data/ext/Transaction.h +50 -0
  43. data/ext/TypeMap.c +1182 -0
  44. data/ext/TypeMap.h +51 -0
  45. data/ext/extconf.rb +28 -0
  46. data/ext/mkmf.bat +1 -0
  47. data/lib/SQLType.rb +224 -0
  48. data/lib/active_record/connection_adapters/rubyfb_adapter.rb +805 -0
  49. data/lib/mkdoc +1 -0
  50. data/lib/rubyfb.rb +2 -0
  51. data/lib/rubyfb_lib.so +0 -0
  52. data/lib/src.rb +1800 -0
  53. data/rubyfb.gemspec +31 -0
  54. data/test/AddRemoveUserTest.rb +56 -0
  55. data/test/BackupRestoreTest.rb +99 -0
  56. data/test/BlobTest.rb +57 -0
  57. data/test/CharacterSetTest.rb +63 -0
  58. data/test/ConnectionTest.rb +111 -0
  59. data/test/DDLTest.rb +54 -0
  60. data/test/DatabaseTest.rb +83 -0
  61. data/test/GeneratorTest.rb +50 -0
  62. data/test/KeyTest.rb +140 -0
  63. data/test/ResultSetTest.rb +162 -0
  64. data/test/RoleTest.rb +73 -0
  65. data/test/RowCountTest.rb +65 -0
  66. data/test/RowTest.rb +203 -0
  67. data/test/SQLTest.rb +182 -0
  68. data/test/SQLTypeTest.rb +101 -0
  69. data/test/ServiceManagerTest.rb +29 -0
  70. data/test/StatementTest.rb +135 -0
  71. data/test/TestSetup.rb +11 -0
  72. data/test/TransactionTest.rb +112 -0
  73. data/test/TypeTest.rb +92 -0
  74. data/test/UnitTest.rb +65 -0
  75. metadata +149 -0
data/rubyfb.gemspec ADDED
@@ -0,0 +1,31 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{rubyfb}
5
+ s.version = "0.5.2"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["George Georgiev"]
9
+ s.date = %q{2010-08-12}
10
+ s.description = %q{Firebird SQL access library}
11
+ s.email = %q{georgiev@heatbs.com}
12
+ s.extensions = ["ext/extconf.rb"]
13
+ s.extra_rdoc_files = ["CHANGELOG", "LICENSE", "README", "examples/example01.rb", "ext/extconf.rb", "lib/SQLType.rb", "lib/rubyfb.rb", "lib/src.rb"]
14
+ s.files = ["CHANGELOG", "LICENSE", "Manifest", "README", "Rakefile", "examples/example01.rb", "ext/AddUser.c", "ext/AddUser.h", "ext/Backup.c", "ext/Backup.h", "ext/Blob.c", "ext/Blob.h", "ext/Common.c", "ext/Common.h", "ext/Connection.c", "ext/Connection.h", "ext/DataArea.c", "ext/DataArea.h", "ext/Database.c", "ext/Database.h", "ext/FireRuby.c", "ext/FireRuby.h", "ext/FireRubyException.c", "ext/FireRubyException.h", "ext/Generator.c", "ext/Generator.h", "ext/RemoveUser.c", "ext/RemoveUser.h", "ext/Restore.c", "ext/Restore.h", "ext/ResultSet.c", "ext/ResultSet.h", "ext/Row.c", "ext/Row.h", "ext/ServiceManager.c", "ext/ServiceManager.h", "ext/Services.c", "ext/Services.h", "ext/Statement.c", "ext/Statement.h", "ext/Transaction.c", "ext/Transaction.h", "ext/TypeMap.c", "ext/TypeMap.h", "ext/extconf.rb", "ext/mkmf.bat", "lib/SQLType.rb", "lib/active_record/connection_adapters/rubyfb_adapter.rb", "lib/mkdoc", "lib/rubyfb.rb", "lib/rubyfb_lib.so", "lib/src.rb", "test/AddRemoveUserTest.rb", "test/BackupRestoreTest.rb", "test/BlobTest.rb", "test/CharacterSetTest.rb", "test/ConnectionTest.rb", "test/DDLTest.rb", "test/DatabaseTest.rb", "test/GeneratorTest.rb", "test/KeyTest.rb", "test/ResultSetTest.rb", "test/RoleTest.rb", "test/RowCountTest.rb", "test/RowTest.rb", "test/SQLTest.rb", "test/SQLTypeTest.rb", "test/ServiceManagerTest.rb", "test/StatementTest.rb", "test/TestSetup.rb", "test/TransactionTest.rb", "test/TypeTest.rb", "test/UnitTest.rb", "rubyfb.gemspec"]
15
+ s.homepage = %q{http://rubyforge.org/projects/rubyfb}
16
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Rubyfb", "--main", "README"]
17
+ s.require_paths = ["lib", "ext"]
18
+ s.rubyforge_project = %q{rubyfb}
19
+ s.rubygems_version = %q{1.3.6}
20
+ s.summary = %q{Firebird SQL access library}
21
+
22
+ if s.respond_to? :specification_version then
23
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
24
+ s.specification_version = 3
25
+
26
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
27
+ else
28
+ end
29
+ else
30
+ end
31
+ end
@@ -0,0 +1,56 @@
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 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
+ 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
+ sleep(3)
46
+
47
+ sm.disconnect
48
+
49
+ begin
50
+ cxn = @database.connect('newuser', 'password')
51
+ cxn.close
52
+ assert(false, "Able to connect as supposedly removed user.")
53
+ rescue FireRubyException
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,99 @@
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 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
+ 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/BlobTest.rb ADDED
@@ -0,0 +1,57 @@
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 BlobTest < Test::Unit::TestCase
11
+ CURDIR = "#{Dir.getwd}"
12
+ DB_FILE = "#{CURDIR}#{File::SEPARATOR}blob_unit_test.fdb"
13
+ TXT_FILE = "#{CURDIR}#{File::SEPARATOR}data.txt"
14
+ DATA = "aasdfjakhdsfljkashdfslfhaslhasyhfawyufalwuhlhsdlkfhasljlkshflalksjhasjhalsjhdf\nasdflkajshdfjkahsdfjajdfalsdfasdf\nasdfasdfasdkljfhajdfhkjasdfagdsflalkjfgagsdflasdf\nasdfasdfasdf"
15
+
16
+ def setup
17
+ puts "#{self.class.name} started." if TEST_LOGGING
18
+ # Remove existing database files.
19
+ @database = Database.new(DB_FILE)
20
+ if File.exist?(DB_FILE)
21
+ @database.drop(DB_USER_NAME, DB_PASSWORD)
22
+ end
23
+ Database.create(DB_FILE, DB_USER_NAME, DB_PASSWORD)
24
+ end
25
+
26
+ def teardown
27
+ # Remove existing database files.
28
+ if File.exist?(DB_FILE)
29
+ @database.drop(DB_USER_NAME, DB_PASSWORD)
30
+ end
31
+
32
+ puts "#{self.class.name} finished." if TEST_LOGGING
33
+ end
34
+
35
+ def test01
36
+ d = nil
37
+ @database.connect(DB_USER_NAME, DB_PASSWORD) do |cxn|
38
+ cxn.execute_immediate('create table blob_test (data blob sub_type 0)')
39
+ cxn.start_transaction do |tx|
40
+
41
+ s = Statement.new(cxn, tx, 'INSERT INTO BLOB_TEST VALUES(?)', 3)
42
+ s.execute_for([DATA])
43
+
44
+ # Perform a select of the value inserted.
45
+ r = cxn.execute('SELECT * FROM BLOB_TEST', tx)
46
+ d = r.fetch
47
+
48
+ assert_equal(d[0].to_s, DATA)
49
+
50
+ # Clean up.
51
+ s.close
52
+ r.close
53
+ end
54
+ cxn.execute_immediate('DROP TABLE BLOB_TEST')
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,63 @@
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 CharacterSetTest < Test::Unit::TestCase
11
+ CURDIR = "#{Dir.getwd}"
12
+ DB_FILE = "#{CURDIR}#{File::SEPARATOR}cxnarset_unit_test.fdb"
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 'fireruby'
7
+
8
+ include FireRuby
9
+
10
+ class ConnectionTest < Test::Unit::TestCase
11
+ CURDIR = "#{Dir.getwd}"
12
+ DB_FILE = "#{CURDIR}#{File::SEPARATOR}con_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
+ 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 == 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 == 88)
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 'fireruby'
7
+
8
+ include FireRuby
9
+
10
+ class DDLTest < Test::Unit::TestCase
11
+ CURDIR = "#{Dir.getwd}"
12
+ DB_FILE = "#{CURDIR}#{File::SEPARATOR}ddl_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
+ 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 BIGINT, 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 'fireruby'
7
+
8
+ include FireRuby
9
+
10
+ class DatabaseTest < Test::Unit::TestCase
11
+ CURDIR = "#{Dir.getwd}"
12
+ DB_FILE = "#{CURDIR}#{File::SEPARATOR}db_unit_test.fdb"
13
+ CREATE_FILE = "#{CURDIR}#{File::SEPARATOR}db_create_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
+ if File.exist?(CREATE_FILE)
22
+ db = Database.new(CREATE_FILE)
23
+ db.drop(DB_USER_NAME, DB_PASSWORD)
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 'fireruby'
7
+
8
+ include FireRuby
9
+
10
+ class GeneratorTest < Test::Unit::TestCase
11
+ CURDIR = "#{Dir.getwd}"
12
+ DB_FILE = "#{CURDIR}#{File::SEPARATOR}generator_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
+
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