fireruby 0.1.0-mswin32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (132) hide show
  1. data/doc/CVS/Entries +10 -0
  2. data/doc/CVS/Repository +1 -0
  3. data/doc/CVS/Root +1 -0
  4. data/doc/README +39 -0
  5. data/doc/classes/CVS/Entries +2 -0
  6. data/doc/classes/CVS/Entries.Log +1 -0
  7. data/doc/classes/CVS/Repository +1 -0
  8. data/doc/classes/CVS/Root +1 -0
  9. data/doc/classes/FireRuby/CVS/Entries +8 -0
  10. data/doc/classes/FireRuby/CVS/Entries.Log +7 -0
  11. data/doc/classes/FireRuby/CVS/Repository +1 -0
  12. data/doc/classes/FireRuby/CVS/Root +1 -0
  13. data/doc/classes/FireRuby/Connection.html +364 -0
  14. data/doc/classes/FireRuby/Connection.src/CVS/Entries +10 -0
  15. data/doc/classes/FireRuby/Connection.src/CVS/Repository +1 -0
  16. data/doc/classes/FireRuby/Connection.src/CVS/Root +1 -0
  17. data/doc/classes/FireRuby/Connection.src/M000046.html +17 -0
  18. data/doc/classes/FireRuby/Connection.src/M000047.html +17 -0
  19. data/doc/classes/FireRuby/Connection.src/M000048.html +17 -0
  20. data/doc/classes/FireRuby/Connection.src/M000049.html +17 -0
  21. data/doc/classes/FireRuby/Connection.src/M000050.html +17 -0
  22. data/doc/classes/FireRuby/Connection.src/M000051.html +17 -0
  23. data/doc/classes/FireRuby/Connection.src/M000052.html +18 -0
  24. data/doc/classes/FireRuby/Connection.src/M000053.html +18 -0
  25. data/doc/classes/FireRuby/Connection.src/M000054.html +18 -0
  26. data/doc/classes/FireRuby/Database.html +292 -0
  27. data/doc/classes/FireRuby/Database.src/CVS/Entries +7 -0
  28. data/doc/classes/FireRuby/Database.src/CVS/Repository +1 -0
  29. data/doc/classes/FireRuby/Database.src/CVS/Root +1 -0
  30. data/doc/classes/FireRuby/Database.src/M000035.html +17 -0
  31. data/doc/classes/FireRuby/Database.src/M000036.html +17 -0
  32. data/doc/classes/FireRuby/Database.src/M000037.html +17 -0
  33. data/doc/classes/FireRuby/Database.src/M000038.html +18 -0
  34. data/doc/classes/FireRuby/Database.src/M000039.html +17 -0
  35. data/doc/classes/FireRuby/Database.src/M000040.html +17 -0
  36. data/doc/classes/FireRuby/FireRubyError.html +221 -0
  37. data/doc/classes/FireRuby/FireRubyError.src/CVS/Entries +6 -0
  38. data/doc/classes/FireRuby/FireRubyError.src/CVS/Repository +1 -0
  39. data/doc/classes/FireRuby/FireRubyError.src/CVS/Root +1 -0
  40. data/doc/classes/FireRuby/FireRubyError.src/M000041.html +17 -0
  41. data/doc/classes/FireRuby/FireRubyError.src/M000042.html +17 -0
  42. data/doc/classes/FireRuby/FireRubyError.src/M000043.html +17 -0
  43. data/doc/classes/FireRuby/FireRubyError.src/M000044.html +17 -0
  44. data/doc/classes/FireRuby/FireRubyError.src/M000045.html +17 -0
  45. data/doc/classes/FireRuby/Generator.html +343 -0
  46. data/doc/classes/FireRuby/Generator.src/CVS/Entries +9 -0
  47. data/doc/classes/FireRuby/Generator.src/CVS/Repository +1 -0
  48. data/doc/classes/FireRuby/Generator.src/CVS/Root +1 -0
  49. data/doc/classes/FireRuby/Generator.src/M000001.html +17 -0
  50. data/doc/classes/FireRuby/Generator.src/M000002.html +17 -0
  51. data/doc/classes/FireRuby/Generator.src/M000003.html +17 -0
  52. data/doc/classes/FireRuby/Generator.src/M000004.html +17 -0
  53. data/doc/classes/FireRuby/Generator.src/M000005.html +17 -0
  54. data/doc/classes/FireRuby/Generator.src/M000006.html +17 -0
  55. data/doc/classes/FireRuby/Generator.src/M000007.html +17 -0
  56. data/doc/classes/FireRuby/Generator.src/M000008.html +17 -0
  57. data/doc/classes/FireRuby/ResultSet.html +343 -0
  58. data/doc/classes/FireRuby/ResultSet.src/CVS/Entries +10 -0
  59. data/doc/classes/FireRuby/ResultSet.src/CVS/Repository +1 -0
  60. data/doc/classes/FireRuby/ResultSet.src/CVS/Root +1 -0
  61. data/doc/classes/FireRuby/ResultSet.src/M000026.html +17 -0
  62. data/doc/classes/FireRuby/ResultSet.src/M000027.html +17 -0
  63. data/doc/classes/FireRuby/ResultSet.src/M000028.html +17 -0
  64. data/doc/classes/FireRuby/ResultSet.src/M000029.html +17 -0
  65. data/doc/classes/FireRuby/ResultSet.src/M000030.html +17 -0
  66. data/doc/classes/FireRuby/ResultSet.src/M000031.html +17 -0
  67. data/doc/classes/FireRuby/ResultSet.src/M000032.html +17 -0
  68. data/doc/classes/FireRuby/ResultSet.src/M000033.html +17 -0
  69. data/doc/classes/FireRuby/ResultSet.src/M000034.html +17 -0
  70. data/doc/classes/FireRuby/Statement.html +349 -0
  71. data/doc/classes/FireRuby/Statement.src/CVS/Entries +10 -0
  72. data/doc/classes/FireRuby/Statement.src/CVS/Repository +1 -0
  73. data/doc/classes/FireRuby/Statement.src/CVS/Root +1 -0
  74. data/doc/classes/FireRuby/Statement.src/M000017.html +17 -0
  75. data/doc/classes/FireRuby/Statement.src/M000018.html +17 -0
  76. data/doc/classes/FireRuby/Statement.src/M000019.html +17 -0
  77. data/doc/classes/FireRuby/Statement.src/M000020.html +17 -0
  78. data/doc/classes/FireRuby/Statement.src/M000021.html +17 -0
  79. data/doc/classes/FireRuby/Statement.src/M000022.html +17 -0
  80. data/doc/classes/FireRuby/Statement.src/M000023.html +18 -0
  81. data/doc/classes/FireRuby/Statement.src/M000024.html +18 -0
  82. data/doc/classes/FireRuby/Statement.src/M000025.html +17 -0
  83. data/doc/classes/FireRuby/Transaction.html +484 -0
  84. data/doc/classes/FireRuby/Transaction.src/CVS/Entries +9 -0
  85. data/doc/classes/FireRuby/Transaction.src/CVS/Repository +1 -0
  86. data/doc/classes/FireRuby/Transaction.src/CVS/Root +1 -0
  87. data/doc/classes/FireRuby/Transaction.src/M000009.html +17 -0
  88. data/doc/classes/FireRuby/Transaction.src/M000010.html +17 -0
  89. data/doc/classes/FireRuby/Transaction.src/M000011.html +17 -0
  90. data/doc/classes/FireRuby/Transaction.src/M000012.html +17 -0
  91. data/doc/classes/FireRuby/Transaction.src/M000013.html +17 -0
  92. data/doc/classes/FireRuby/Transaction.src/M000014.html +17 -0
  93. data/doc/classes/FireRuby/Transaction.src/M000015.html +18 -0
  94. data/doc/classes/FireRuby/Transaction.src/M000016.html +17 -0
  95. data/doc/classes/FireRuby.html +116 -0
  96. data/doc/created.rid +1 -0
  97. data/doc/files/CVS/Entries +2 -0
  98. data/doc/files/CVS/Repository +1 -0
  99. data/doc/files/CVS/Root +1 -0
  100. data/doc/files/src_rb.html +119 -0
  101. data/doc/fr_class_index.html +34 -0
  102. data/doc/fr_file_index.html +27 -0
  103. data/doc/fr_method_index.html +80 -0
  104. data/doc/index.html +24 -0
  105. data/doc/license.txt +411 -0
  106. data/doc/rdoc-style.css +175 -0
  107. data/lib/CVS/Entries +4 -0
  108. data/lib/CVS/Repository +1 -0
  109. data/lib/CVS/Root +1 -0
  110. data/lib/fireruby.bundle +0 -0
  111. data/lib/fireruby.so +0 -0
  112. data/lib/mkdoc +1 -0
  113. data/lib/src.rb +736 -0
  114. data/test/CVS/Entries +17 -0
  115. data/test/CVS/Repository +1 -0
  116. data/test/CVS/Root +1 -0
  117. data/test/ConnectionTest.rb +91 -0
  118. data/test/DDLTest.rb +49 -0
  119. data/test/DatabaseTest.rb +84 -0
  120. data/test/GeneratorTest.rb +47 -0
  121. data/test/ResultSetTest.rb +96 -0
  122. data/test/SQLTest.rb +154 -0
  123. data/test/StatementTest.rb +101 -0
  124. data/test/TestSetup.rb +10 -0
  125. data/test/TransactionTest.rb +107 -0
  126. data/test/UnitTest.rb +10 -0
  127. data/test/example.c +91 -0
  128. data/test/fb.c +297 -0
  129. data/test/mfb +1 -0
  130. data/test/sql_unit_test.fdb +0 -0
  131. data/test/test.fdb +0 -0
  132. metadata +191 -0
data/test/CVS/Entries ADDED
@@ -0,0 +1,17 @@
1
+ /.gdb_history/1.1.1.1/Tue Mar 15 10:36:35 2005//
2
+ /ConnectionTest.rb/1.1.1.1/Tue Mar 15 10:36:35 2005//
3
+ /DDLTest.rb/1.1.1.1/Tue Mar 15 10:36:35 2005//
4
+ /DatabaseTest.rb/1.1.1.1/Tue Mar 15 10:36:35 2005//
5
+ /GeneratorTest.rb/1.1.1.1/Tue Mar 15 10:36:35 2005//
6
+ /ResultSetTest.rb/1.1.1.1/Tue Mar 15 10:36:36 2005//
7
+ /SQLTest.rb/1.1.1.1/Tue Mar 15 10:36:45 2005//
8
+ /StatementTest.rb/1.1.1.1/Tue Mar 15 10:36:45 2005//
9
+ /TestSetup.rb/1.1.1.1/Tue Mar 15 10:37:07 2005//
10
+ /TransactionTest.rb/1.1.1.1/Tue Mar 15 10:37:07 2005//
11
+ /UnitTest.rb/1.1.1.1/Tue Mar 15 10:37:07 2005//
12
+ /example.c/1.1.1.1/Tue Mar 15 10:36:35 2005//
13
+ /fb.c/1.1.1.1/Tue Mar 15 10:36:35 2005//
14
+ /mfb/1.1.1.1/Tue Mar 15 10:36:35 2005//
15
+ /sql_unit_test.fdb/1.1.1.1/Tue Mar 15 10:36:45 2005//
16
+ /test.fdb/1.1.1.1/Tue Mar 15 10:37:07 2005//
17
+ D
@@ -0,0 +1 @@
1
+ /var/cvs/fireruby/fireruby/test
data/test/CVS/Root ADDED
@@ -0,0 +1 @@
1
+ :ext:paw220470@rubyforge.org:/var/cvs/fireruby
@@ -0,0 +1,91 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'TestSetup'
4
+ require 'test/unit'
5
+ require 'fireruby'
6
+
7
+ include FireRuby
8
+
9
+ class ConnectionTest < Test::Unit::TestCase
10
+ CURDIR = "#{Dir.getwd}"
11
+ DB_FILE = "#{CURDIR}#{File::SEPARATOR}con_unit_test.fdb"
12
+
13
+ def setup
14
+ if File::exist?(DB_FILE)
15
+ db = Database.new(DB_USER_NAME, DB_PASSWORD, DB_FILE)
16
+ db.drop
17
+ end
18
+
19
+ @database = Database.create(DB_FILE, DB_USER_NAME, DB_PASSWORD, 1024, nil)
20
+ @connections = []
21
+ end
22
+
23
+ def teardown
24
+ @connections.each {|connection| connection.close}
25
+ @connections.clear
26
+
27
+ if File::exist?(DB_FILE)
28
+ db = Database.new(DB_USER_NAME, DB_PASSWORD, DB_FILE)
29
+ db.drop
30
+ end
31
+ end
32
+
33
+ def test01
34
+ @connections.push(@database.connect)
35
+
36
+ assert(@connections[0].open?)
37
+ assert(@connections[0].closed? == false)
38
+ assert(@connections[0].database == @database)
39
+ assert(@connections[0].to_s == "#{DB_USER_NAME}@#{DB_FILE} (OPEN)")
40
+
41
+ @connections[0].close
42
+ assert(@connections[0].open? == false)
43
+ assert(@connections[0].closed?)
44
+ assert(@connections[0].database == @database)
45
+ assert(@connections[0].to_s == "(CLOSED)")
46
+
47
+ @connections[0] = @database.connect
48
+ assert(@connections[0].open?)
49
+ @connections.push(Connection.new(@database))
50
+ assert(@connections[0].open?)
51
+ assert(@connections[1].open?)
52
+ end
53
+
54
+ def test02
55
+ @connections.push(@database.connect)
56
+
57
+ tx = @connections[0].start_transaction
58
+ assert(tx != nil)
59
+ assert(tx.class == Transaction)
60
+ assert(tx.active?)
61
+ tx.rollback
62
+
63
+ tx = nil
64
+ @connections[0].start_transaction do |transaction|
65
+ assert(transaction != nil)
66
+ assert(transaction.class == Transaction)
67
+ assert(transaction.active?)
68
+ tx = transaction
69
+ end
70
+ assert(tx != nil)
71
+ assert(tx.class == Transaction)
72
+ assert(tx.active? == false)
73
+ end
74
+
75
+ def test03
76
+ @connections.push(@database.connect)
77
+ tx = @connections[0].start_transaction
78
+ total = 0
79
+ @connections[0].execute("SELECT RDB$FIELD_NAME FROM RDB$FIELDS", tx) do |row|
80
+ total = total + 1
81
+ end
82
+ assert(total == 88)
83
+ tx.commit
84
+
85
+ total = 0
86
+ @connections[0].execute_immediate("SELECT RDB$FIELD_NAME FROM RDB$FIELDS") do |row|
87
+ total = total + 1
88
+ end
89
+ assert(total == 88)
90
+ end
91
+ end
data/test/DDLTest.rb ADDED
@@ -0,0 +1,49 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'TestSetup'
4
+ require 'test/unit'
5
+ require 'fireruby'
6
+
7
+ include FireRuby
8
+
9
+ class DDLTest < Test::Unit::TestCase
10
+ CURDIR = "#{Dir.getwd}"
11
+ DB_FILE = "#{CURDIR}#{File::SEPARATOR}ddl_unit_test.fdb"
12
+
13
+ def setup
14
+ if File::exist?(DB_FILE)
15
+ Database.new(DB_USER_NAME, DB_PASSWORD, DB_FILE).drop
16
+ end
17
+ @database = Database::create(DB_FILE, DB_USER_NAME, DB_PASSWORD, 1024, nil)
18
+ end
19
+
20
+ def teardown
21
+ if File::exist?(DB_FILE)
22
+ Database.new(DB_USER_NAME, DB_PASSWORD, DB_FILE).drop
23
+ end
24
+ end
25
+
26
+ def test01
27
+ @database.connect do |cxn|
28
+ cxn.execute_immediate('CREATE TABLE DDL_TABLE_01 (TABLEID '\
29
+ 'INTEGER NOT NULL, '\
30
+ 'FIELD01 FLOAT, FIELD02 CHAR(50), '\
31
+ 'FIELD03 BIGINT, FIELD04 TIMESTAMP '\
32
+ 'NOT NULL, FIELD05 VARCHAR(600))')
33
+
34
+ r = cxn.execute_immediate('SELECT COUNT(*) FROM DDL_TABLE_01')
35
+ assert(r.fetch == [0])
36
+ r.close
37
+
38
+ cxn.execute_immediate('ALTER TABLE DDL_TABLE_01 ADD PRIMARY KEY '\
39
+ '(TABLEID)')
40
+
41
+ cxn.execute_immediate('CREATE UNIQUE INDEX DDL_TABLE_IDX ON '\
42
+ 'DDL_TABLE_01 (TABLEID)')
43
+
44
+ cxn.execute_immediate('DROP INDEX DDL_TABLE_IDX')
45
+
46
+ cxn.execute_immediate('DROP TABLE DDL_TABLE_01')
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,84 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'TestSetup'
4
+ require 'test/unit'
5
+ require 'fireruby'
6
+
7
+ include FireRuby
8
+
9
+ class DatabaseTest < Test::Unit::TestCase
10
+ CURDIR = "#{Dir.getwd}"
11
+ DB_FILE = "#{CURDIR}#{File::SEPARATOR}db_unit_test.fdb"
12
+ CREATE_FILE = "#{CURDIR}#{File::SEPARATOR}db_create_test.fdb"
13
+
14
+ def setup
15
+ if File.exist?(DB_FILE)
16
+ db = Database.new(DB_USER_NAME, DB_PASSWORD, DB_FILE)
17
+ db.drop
18
+ end
19
+ if File.exist?(CREATE_FILE)
20
+ db = Database.new(DB_USER_NAME, DB_PASSWORD, CREATE_FILE)
21
+ db.drop
22
+ end
23
+
24
+ Database::create(DB_FILE, DB_USER_NAME, DB_PASSWORD, 1024, 'ASCII')
25
+ end
26
+
27
+ def teardown
28
+ if File::exist?(DB_FILE)
29
+ db = Database.new(DB_USER_NAME, DB_PASSWORD, DB_FILE)
30
+ db.drop
31
+ end
32
+ if File::exist?(CREATE_FILE)
33
+ db = Database.new(DB_USER_NAME, DB_PASSWORD, CREATE_FILE)
34
+ db.drop
35
+ end
36
+ end
37
+
38
+
39
+ def test01
40
+ puts "Executing test01.\n\n"
41
+ db = Database.create(CREATE_FILE, DB_USER_NAME, DB_PASSWORD, 2048, 'ASCII')
42
+
43
+ assert(File.exist?(CREATE_FILE))
44
+ assert(db.user == DB_USER_NAME)
45
+ assert(db.file == CREATE_FILE)
46
+
47
+ begin
48
+ Database.create(CREATE_FILE, DB_USER_NAME, DB_PASSWORD, 2048, 'ASCII')
49
+ assert(false,
50
+ "Successfully created a database file that already exists.")
51
+ rescue Exception
52
+ end
53
+
54
+ db.drop
55
+ assert(File.exist?(CREATE_FILE) == false)
56
+ end
57
+
58
+ def test02
59
+ puts "Executing test02.\n\n"
60
+ db = Database.new(DB_USER_NAME, DB_PASSWORD, DB_FILE);
61
+
62
+ assert(db.user == DB_USER_NAME)
63
+ assert(db.file == DB_FILE)
64
+
65
+ c = db.connect
66
+ assert(c != nil)
67
+ c.close
68
+ end
69
+
70
+ def test03
71
+ db = Database.new(DB_USER_NAME, DB_PASSWORD, DB_FILE);
72
+ c = nil
73
+
74
+ db.connect do |connection|
75
+ assert(connection != nil)
76
+ assert(connection.class == Connection)
77
+ assert(connection.open?)
78
+ c = connection
79
+ end
80
+ assert(c != nil)
81
+ assert(c.class == Connection)
82
+ assert(c.closed?)
83
+ end
84
+ end
@@ -0,0 +1,47 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'TestSetup'
4
+ require 'test/unit'
5
+ require 'fireruby'
6
+
7
+ include FireRuby
8
+
9
+ class GeneratorTest < Test::Unit::TestCase
10
+ CURDIR = "#{Dir.getwd}"
11
+ DB_FILE = "#{CURDIR}#{File::SEPARATOR}generator_unit_test.fdb"
12
+
13
+ def setup
14
+ if File::exist?(DB_FILE)
15
+ Database.new(DB_USER_NAME, DB_PASSWORD, DB_FILE).drop
16
+ end
17
+ @database = Database::create(DB_FILE, DB_USER_NAME, DB_PASSWORD, 1024, nil)
18
+ @connections = []
19
+
20
+ @connections.push(@database.connect)
21
+ end
22
+
23
+ def teardown
24
+ @connections.each do |cxn|
25
+ cxn.close if cxn.open?
26
+ end
27
+ @connections.clear
28
+ if File::exist?(DB_FILE)
29
+ Database.new(DB_USER_NAME, DB_PASSWORD, DB_FILE).drop
30
+ end
31
+ end
32
+
33
+ def test01
34
+ assert(Generator::exists?('TEST_GEN', @connections[0]) == false)
35
+ g = Generator::create('TEST_GEN', @connections[0])
36
+ assert(Generator::exists?('TEST_GEN', @connections[0]))
37
+ assert(g.last == 0)
38
+ assert(g.next(1) == 1)
39
+ assert(g.last == 1)
40
+ assert(g.next(10) == 11)
41
+ assert(g.connection == @connections[0])
42
+ assert(g.name == 'TEST_GEN')
43
+
44
+ g.drop
45
+ assert(Generator::exists?('TEST_GEN', @connections[0]) == false)
46
+ end
47
+ end
@@ -0,0 +1,96 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'TestSetup'
4
+ require 'test/unit'
5
+ require 'fireruby'
6
+
7
+ include FireRuby
8
+
9
+ class ResultSetTest < Test::Unit::TestCase
10
+ CURDIR = "#{Dir.getwd}"
11
+ DB_FILE = "#{CURDIR}#{File::SEPARATOR}result_set_unit_test.fdb"
12
+
13
+ def setup
14
+ if File::exist?(DB_FILE)
15
+ Database.new(DB_USER_NAME, DB_PASSWORD, DB_FILE).drop
16
+ end
17
+ @database = Database::create(DB_FILE, DB_USER_NAME, DB_PASSWORD, 1024, nil)
18
+ @connections = []
19
+ @transactions = []
20
+
21
+ @connections.push(@database.connect)
22
+
23
+ @connections[0].start_transaction do |tx|
24
+ tx.execute("CREATE TABLE TEST_TABLE (TESTID INTEGER NOT NULL "\
25
+ "primary KEY, TESTINFO VARCHAR(100))")
26
+ end
27
+
28
+ @connections[0].start_transaction do |tx|
29
+ begin
30
+ tx.execute("INSERT INTO TEST_TABLE VALUES (10, 'Record One.')")
31
+ tx.execute("INSERT INTO TEST_TABLE VALUES (20, 'Record Two.')")
32
+ tx.execute("INSERT INTO TEST_TABLE VALUES (30, 'Record Three.')")
33
+ tx.execute("INSERT INTO TEST_TABLE VALUES (40, 'Record Four.')")
34
+ tx.execute("INSERT INTO TEST_TABLE VALUES (50, 'Record Five.')")
35
+ rescue Exception => error
36
+ puts error.message
37
+ error.backtrace.each {|step| puts " #{step}"}
38
+ raise
39
+ end
40
+ end
41
+
42
+ @transactions.push(@connections[0].start_transaction)
43
+ end
44
+
45
+ def teardown
46
+ @transactions.each do |tx|
47
+ tx.rollback if tx.active?
48
+ end
49
+ @transactions.clear
50
+ @connections.each do |cxn|
51
+ cxn.close if cxn.open?
52
+ end
53
+ @connections.clear
54
+ if File::exist?(DB_FILE)
55
+ Database.new(DB_USER_NAME, DB_PASSWORD, DB_FILE).drop
56
+ end
57
+ end
58
+
59
+ def test01
60
+ s = Statement.new(@connections[0], @transactions[0],
61
+ "SELECT * FROM TEST_TABLE ORDER BY TESTID", 3)
62
+
63
+ r = ResultSet.new(s)
64
+
65
+ assert(r.statement == s)
66
+
67
+ assert(r.fetch != nil)
68
+ assert(r.fetch.class == Array)
69
+ assert(r.fetch[0] == 30)
70
+ assert(r.fetch[1] == 'Record Four.')
71
+ r.fetch
72
+ assert(r.fetch == nil)
73
+
74
+ r = ResultSet.new(s)
75
+ assert(r.column_count == 2)
76
+ assert(r.column_name(0) == 'TESTID')
77
+ assert(r.column_name(1) == 'TESTINFO')
78
+ assert(r.column_name(3) == nil)
79
+ assert(r.column_name(-1) == nil)
80
+ assert(r.column_table(0) == 'TEST_TABLE')
81
+ assert(r.column_table(1) == 'TEST_TABLE')
82
+ assert(r.column_table(2) == nil)
83
+ assert(r.column_table(-1) == nil)
84
+ assert(r.column_alias(0) == 'TESTID')
85
+ assert(r.column_alias(1) == 'TESTINFO')
86
+ assert(r.column_alias(3) == nil)
87
+ assert(r.column_alias(-1) == nil)
88
+
89
+ r = ResultSet.new(s)
90
+ total = 0
91
+ r.each do |row|
92
+ total += 1
93
+ end
94
+ assert(total == 5)
95
+ end
96
+ end
data/test/SQLTest.rb ADDED
@@ -0,0 +1,154 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'TestSetup'
4
+ require 'test/unit'
5
+ require 'fireruby'
6
+
7
+ include FireRuby
8
+
9
+ class SQLTest < Test::Unit::TestCase
10
+ CURDIR = "#{Dir.getwd}"
11
+ DB_FILE = "#{CURDIR}#{File::SEPARATOR}sql_unit_test.fdb"
12
+ ITERATIONS = 100
13
+
14
+ INSERT_SQL = "INSERT INTO TEST_TABLE VALUES(?, ?, ?, ?, ?, ?)"
15
+
16
+ def setup
17
+ if File::exist?(DB_FILE)
18
+ Database.new(DB_USER_NAME, DB_PASSWORD, DB_FILE).drop
19
+ end
20
+ @database = Database::create(DB_FILE, DB_USER_NAME, DB_PASSWORD,
21
+ 1024, 'ASCII')
22
+ @connections = []
23
+ @transactions = []
24
+
25
+ @database.connect do |cxn|
26
+ cxn.execute_immediate('CREATE TABLE TEST_TABLE (TESTID INTEGER '\
27
+ 'NOT NULL PRIMARY KEY, TESTTEXT VARCHAR(100), '\
28
+ 'TESTFLOAT FLOAT, TESTDATE DATE, TESTTIME '\
29
+ 'TIME, TESTSTAMP TIMESTAMP)')
30
+ end
31
+ end
32
+
33
+ def teardown
34
+ @transactions.each do |tx|
35
+ tx.rollback if tx.active?
36
+ end
37
+
38
+ @connections.each do |cxn|
39
+ cxn.close if cxn.open?
40
+ end
41
+
42
+ #if File::exist?(DB_FILE)
43
+ # Database.new(DB_USER_NAME, DB_PASSWORD, DB_FILE).drop
44
+ #end
45
+ end
46
+
47
+ def test01
48
+ @database.connect do |cxn|
49
+ cxn.start_transaction do |tx|
50
+ s = Statement.new(cxn, tx, INSERT_SQL, 3)
51
+ f = 0.0
52
+ t = Time.new
53
+
54
+ 1.upto(ITERATIONS) do |i|
55
+ f += 0.321
56
+ t = Time.at(t.to_i + 5)
57
+ s.execute_for([i, i.to_s, f, t, nil, t])
58
+ end
59
+ end
60
+ end
61
+
62
+ @connections.push(@database.connect)
63
+ r = @connections[0].execute_immediate("SELECT COUNT(*) FROM TEST_TABLE")
64
+ assert(r.fetch[0] == ITERATIONS)
65
+ r.close
66
+ end
67
+
68
+ def test02
69
+ f = 0.0
70
+ @database.connect do |cxn|
71
+ 1.upto(20) do |i|
72
+ f += i
73
+ sql = "INSERT INTO TEST_TABLE VALUES (#{i}, "\
74
+ "#{f.to_s}, #{f}, NULL, NULL, 'NOW')"
75
+ cxn.execute_immediate(sql)
76
+ end
77
+ end
78
+
79
+ @connections.push(@database.connect)
80
+ @transactions.push(@connections[0].start_transaction)
81
+ r = @transactions[0].execute("SELECT COUNT(*) FROM TEST_TABLE")
82
+ assert(r.fetch[0] == 20)
83
+ r.close
84
+
85
+ r = @transactions[0].execute("SELECT * FROM TEST_TABLE WHERE TESTID IN "\
86
+ "(2, 4, 6, 8, 10) ORDER BY TESTID ASCENDING")
87
+ a = r.fetch
88
+ assert(a.delete_at(5) != nil)
89
+ assert(a == [2, '3.0', 3.0, nil, nil])
90
+
91
+ a = r.fetch
92
+ assert(a.delete_at(5) != nil)
93
+ assert(a == [4, '10.0', 10.0, nil, nil])
94
+
95
+ a = r.fetch
96
+ assert(a.delete_at(5) != nil)
97
+ assert(a == [6, '21.0', 21.0, nil, nil])
98
+
99
+ a = r.fetch
100
+ assert(a.delete_at(5) != nil)
101
+ assert(a == [8, '36.0', 36.0, nil, nil])
102
+
103
+ a = r.fetch
104
+ assert(a.delete_at(5) != nil)
105
+ assert(a == [10, '55.0', 55.0, nil, nil])
106
+
107
+ r.close
108
+
109
+ @transactions[0].commit
110
+
111
+ @connections[0].start_transaction do |tx|
112
+ s = Statement.new(@connections[0], tx,
113
+ "UPDATE TEST_TABLE SET TESTSTAMP = NULL", 3)
114
+ s.execute()
115
+
116
+ r = tx.execute("SELECT TESTSTAMP FROM TEST_TABLE")
117
+ total = 0
118
+ r.each do |row|
119
+ assert(row[0] == nil)
120
+ total = total + 1
121
+ end
122
+ assert(total == 20)
123
+ end
124
+
125
+ a = []
126
+ @connections[0].start_transaction do |tx|
127
+ # Perform an insert via a parameterized statement.
128
+ s = Statement.new(@connections[0], tx,
129
+ "INSERT INTO TEST_TABLE (TESTID, TESTTEXT, "\
130
+ "TESTFLOAT, TESTSTAMP) VALUES(?, ?, ?, ?)", 3)
131
+ t = Time.new
132
+ s.execute_for([25000, 'La la la', 3.14, t])
133
+
134
+ # Fetch the record and check the data.
135
+ r = tx.execute("SELECT TESTTEXT, TESTFLOAT, TESTSTAMP FROM "\
136
+ "TEST_TABLE WHERE TESTID = 25000")
137
+ a = r.fetch
138
+ r.close
139
+ puts ['La la la', 3.14, t].join(', ')
140
+ puts a.join(', ')
141
+ end
142
+ assert(a == ['La la la', 3.14, t])
143
+
144
+ @connections[0].execute_immediate("DELETE FROM TEST_TABLE WHERE TESTID "\
145
+ "IN (1, 3, 5, 7, 9, 12, 14, 16, 18, 20)")
146
+ @database.connect do |cxn|
147
+ r = cxn.execute_immediate("SELECT COUNT(*) FROM TEST_TABLE")
148
+ a = r.fetch
149
+ r.close
150
+ assert(a[0] == 10)
151
+ end
152
+ end
153
+ end
154
+
@@ -0,0 +1,101 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'TestSetup'
4
+ require 'test/unit'
5
+ require 'fireruby'
6
+
7
+ include FireRuby
8
+
9
+ class StatementTest < Test::Unit::TestCase
10
+ CURDIR = "#{Dir.getwd}"
11
+ DB_FILE = "#{CURDIR}#{File::SEPARATOR}stmt_unit_test.fdb"
12
+
13
+ def setup
14
+ if File::exist?(DB_FILE)
15
+ Database.new(DB_USER_NAME, DB_PASSWORD, DB_FILE).drop
16
+ end
17
+ @database = Database::create(DB_FILE, DB_USER_NAME, DB_PASSWORD, 1024, nil)
18
+ @connections = []
19
+ @transactions = []
20
+ end
21
+
22
+ def teardown
23
+ @transactions.each do |tx|
24
+ tx.rollback if tx.active?
25
+ end
26
+ @transactions.clear
27
+ @connections.each do |cxn|
28
+ cxn.close if cxn.open?
29
+ end
30
+ @connections.clear
31
+ if File::exist?(DB_FILE)
32
+ Database.new(DB_USER_NAME, DB_PASSWORD, DB_FILE).drop
33
+ end
34
+ end
35
+
36
+ def test01
37
+ @connections.push(@database.connect)
38
+ @transactions.push(@connections.last.start_transaction)
39
+
40
+ s1 = Statement.new(@connections[0],
41
+ @transactions[0],
42
+ "SELECT RDB$FIELD_NAME FROM RDB$FIELDS", 3)
43
+ assert(s1 != nil)
44
+ assert(s1.sql == "SELECT RDB$FIELD_NAME FROM RDB$FIELDS")
45
+ assert(s1.connection == @connections[0])
46
+ assert(s1.transaction == @transactions[0])
47
+ assert(s1.dialect == 3)
48
+ assert(s1.is_query? == true)
49
+
50
+ s2 = Statement.new(@connections[0],
51
+ @transactions[0],
52
+ "DELETE FROM RDB$EXCEPTIONS", 1)
53
+ assert(s2 != nil)
54
+ assert(s2.sql == "DELETE FROM RDB$EXCEPTIONS")
55
+ assert(s2.connection == @connections[0])
56
+ assert(s2.transaction == @transactions[0])
57
+ assert(s2.dialect == 1)
58
+ assert(s2.is_query? == false)
59
+ end
60
+
61
+ def test02
62
+ @connections.push(@database.connect)
63
+ @transactions.push(@connections[0].start_transaction)
64
+
65
+ s = Statement.new(@connections[0], @transactions[0],
66
+ "SELECT RDB$FIELD_NAME FROM RDB$FIELDS "\
67
+ "WHERE RDB$FIELD_NAME LIKE ?", 3)
68
+
69
+ begin
70
+ s.execute
71
+ assert(false,
72
+ "Executed statement that required parameter without the "\
73
+ "parameter being specified.")
74
+ rescue Exception => error
75
+ end
76
+
77
+ begin
78
+ s.execute_for([])
79
+ assert(false,
80
+ "Executed statement that required a parameter with an empty "\
81
+ "parameter set.")
82
+ rescue Exception => error
83
+ end
84
+
85
+ begin
86
+ s.execute_for(['LALALA', 25])
87
+ assert(false,
88
+ "Executed statement that required a parameter with too many "\
89
+ "parameters.")
90
+ rescue Exception => error
91
+ end
92
+
93
+ assert(s.execute_for(['LALALA']) != nil)
94
+ assert(s.execute_for(['LALALA']).class == ResultSet)
95
+ total = 0
96
+ s.execute_for(["%"]) do |row|
97
+ total = total + 1
98
+ end
99
+ assert(total = 88)
100
+ end
101
+ end
data/test/TestSetup.rb ADDED
@@ -0,0 +1,10 @@
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'