rubyfb 0.5.9 → 0.6

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.
@@ -40,25 +40,19 @@ class StatementTest < Test::Unit::TestCase
40
40
  @connections.push(@database.connect(DB_USER_NAME, DB_PASSWORD))
41
41
  @transactions.push(@connections.last.start_transaction)
42
42
 
43
- s1 = Statement.new(@connections[0],
44
- @transactions[0],
45
- "SELECT RDB$FIELD_NAME FROM RDB$FIELDS", 3)
43
+ s1 = @connections[0].create_statement("SELECT RDB$FIELD_NAME FROM RDB$FIELDS")
46
44
  assert(s1 != nil)
47
45
  assert(s1.sql == "SELECT RDB$FIELD_NAME FROM RDB$FIELDS")
48
46
  assert(s1.connection == @connections[0])
49
- assert(s1.transaction == @transactions[0])
50
47
  assert(s1.dialect == 3)
51
48
  assert(s1.type == Statement::SELECT_STATEMENT)
52
49
  s1.close
53
50
 
54
- s2 = Statement.new(@connections[0],
55
- @transactions[0],
56
- "DELETE FROM RDB$EXCEPTIONS", 1)
51
+ s2 = @connections[0].create_statement("DELETE FROM RDB$EXCEPTIONS")
57
52
  assert(s2 != nil)
58
53
  assert(s2.sql == "DELETE FROM RDB$EXCEPTIONS")
59
54
  assert(s2.connection == @connections[0])
60
- assert(s2.transaction == @transactions[0])
61
- assert(s2.dialect == 1)
55
+ assert(s2.dialect == 3)
62
56
  assert(s2.type == Statement::DELETE_STATEMENT)
63
57
  s2.close
64
58
  end
@@ -67,12 +61,12 @@ class StatementTest < Test::Unit::TestCase
67
61
  @connections.push(@database.connect(DB_USER_NAME, DB_PASSWORD))
68
62
  @transactions.push(@connections[0].start_transaction)
69
63
 
70
- s = Statement.new(@connections[0], @transactions[0],
64
+ s = @connections[0].create_statement(
71
65
  "SELECT RDB$FIELD_NAME FROM RDB$FIELDS "\
72
- "WHERE RDB$FIELD_NAME LIKE ?", 3)
66
+ "WHERE RDB$FIELD_NAME LIKE ?")
73
67
 
74
68
  begin
75
- r = s.execute
69
+ r = s.execute(@transactions[0])
76
70
  r.close
77
71
  assert(false,
78
72
  "Executed statement that required parameter without the "\
@@ -81,7 +75,7 @@ class StatementTest < Test::Unit::TestCase
81
75
  end
82
76
 
83
77
  begin
84
- r = s.execute_for([])
78
+ r = s.exec([], @transactions[0])
85
79
  r.close
86
80
  assert(false,
87
81
  "Executed statement that required a parameter with an empty "\
@@ -90,7 +84,7 @@ class StatementTest < Test::Unit::TestCase
90
84
  end
91
85
 
92
86
  begin
93
- r = s.execute_for(['LALALA', 25])
87
+ r = s.exec(['LALALA', 25], @transactions[0])
94
88
  r.close
95
89
  assert(false,
96
90
  "Executed statement that required a parameter with too many "\
@@ -98,16 +92,16 @@ class StatementTest < Test::Unit::TestCase
98
92
  rescue Exception => error
99
93
  end
100
94
 
101
- r = s.execute_for(['LALALA'])
102
- assert(r != nil)
103
- assert(r.class == ResultSet)
95
+ r = s.exec(['LALALA'], @transactions[0])
96
+ assert_not_nil(r)
97
+ assert_equal(ResultSet, r.class)
104
98
  r.close
105
99
 
106
100
  total = 0
107
- s.execute_for(["%"]) do |row|
108
- total = total + 1
101
+ s.exec(["%"], @transactions[0]) do |row|
102
+ total += 1
109
103
  end
110
- assert(total = 88)
104
+ assert_equal(88, total)
111
105
  s.close
112
106
  end
113
107
 
@@ -117,8 +111,8 @@ class StatementTest < Test::Unit::TestCase
117
111
  cxn.execute_immediate('CREATE TABLE STRING_TEST(TEXT VARCHAR(10))')
118
112
  cxn.start_transaction do |tx|
119
113
  # Perform an truncated insert.
120
- s = Statement.new(cxn, tx, 'INSERT INTO STRING_TEST VALUES(?)', 3)
121
- s.execute_for(['012345678901234'])
114
+ s = cxn.create_statement('INSERT INTO STRING_TEST VALUES(?)')
115
+ s.exec(['012345678901234'], tx)
122
116
 
123
117
  # Perform a select of the value inserted.
124
118
  r = cxn.execute('SELECT * FROM STRING_TEST', tx)
@@ -140,8 +134,8 @@ class StatementTest < Test::Unit::TestCase
140
134
  cxn.execute_immediate('CREATE TABLE STRING_TEST(TEXT VARCHAR(100) CHARACTER SET UTF8)')
141
135
  cxn.start_transaction do |tx|
142
136
  # Perform an truncated insert.
143
- s = Statement.new(cxn, tx, 'INSERT INTO STRING_TEST VALUES(?)', 3)
144
- s.execute_for([utf_str])
137
+ s = cxn.create_statement('INSERT INTO STRING_TEST VALUES(?)')
138
+ s.exec([utf_str], tx)
145
139
 
146
140
  # Perform a select of the value inserted.
147
141
  r = cxn.execute('SELECT * FROM STRING_TEST', tx)
@@ -0,0 +1,80 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+
4
+ require './TestSetup'
5
+ require 'test/unit'
6
+ require 'rubygems'
7
+ require 'rubyfb'
8
+
9
+ include Rubyfb
10
+
11
+ class StoredProcedureTest < Test::Unit::TestCase
12
+ DB_FILE = File.join(DB_DIR, "sp_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
+ d = nil
41
+ @database.connect(DB_USER_NAME, DB_PASSWORD) do |cxn|
42
+ cxn.execute_immediate('
43
+ create procedure SP1 (
44
+ SP_IN_1 VARCHAR(10),
45
+ SP_IN_2 integer
46
+ )
47
+ returns (
48
+ SP_OUT_1 VARCHAR(20),
49
+ SP_OUT_2 INTEGER
50
+ )
51
+ as
52
+ begin
53
+ SP_OUT_1 = :SP_IN_1;
54
+ SP_OUT_2 = SP_IN_2;
55
+ end
56
+ ')
57
+ cxn.start_transaction do |tx|
58
+ # Perform an truncated insert.
59
+ test_data = ["SP1", 7]
60
+
61
+ s = cxn.create_statement('execute procedure SP1(?, ?)')
62
+ result = s.exec(test_data, tx)
63
+
64
+ assert_equal(Rubyfb::ResultSet, result.class)
65
+ row = result.fetch
66
+ assert_not_nil(row)
67
+ assert_nil(result.fetch)
68
+ assert_equal(result.exhausted?, true)
69
+
70
+ assert_equal(test_data[0], row[0])
71
+ assert_equal(test_data[1], row[1])
72
+
73
+ # Clean up.
74
+ result.close
75
+ s.close
76
+ end
77
+ cxn.execute_immediate('DROP PROCEDURE SP1')
78
+ end
79
+ end
80
+ end
@@ -96,7 +96,7 @@ class TransactionTest < Test::Unit::TestCase
96
96
  sql.push("SELECT * FROM RDB$DATABASE")
97
97
  @transactions.push(Transaction.new(@connections[0]))
98
98
 
99
- assert(@transactions[0].execute(sql[0]) == 0)
99
+ assert_equal(0, @transactions[0].execute(sql[0]))
100
100
  r = @transactions[0].execute(sql[1])
101
101
  assert(r != nil)
102
102
  assert(r.class == ResultSet)
data/test/TypeTest.rb CHANGED
@@ -27,11 +27,11 @@ class TypeTest < Test::Unit::TestCase
27
27
  end
28
28
 
29
29
  cxn.start_transaction do |tx|
30
- stmt = Statement.new(cxn, tx, "insert into types_table values "\
31
- "(?, ?, ?, ?, ?, ?, ?, ?, ?)", 3)
32
- stmt.execute_for([10, 100.2, 2378.65, 192.345,
30
+ stmt = cxn.create_statement("insert into types_table values "\
31
+ "(?, ?, ?, ?, ?, ?, ?, ?, ?)")
32
+ stmt.exec([10, 100.2, 2378.65, 192.345,
33
33
  Date.new(2005, 10, 21), Time.new, 'La la la',
34
- Time.new, "Oobly Joobly"])
34
+ Time.new, "Oobly Joobly"], tx)
35
35
  stmt.close
36
36
  end
37
37
  cxn.close
@@ -81,7 +81,6 @@ class TypeTest < Test::Unit::TestCase
81
81
  assert(row[6].instance_of?(String))
82
82
  assert(row[7].instance_of?(Time))
83
83
  assert(row[8].instance_of?(String))
84
- rows.close
85
84
  ensure
86
85
  rows.close if rows != nil
87
86
  cxn.close if cxn != nil
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubyfb
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 7
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 5
9
- - 9
10
- version: 0.5.9
8
+ - 6
9
+ version: "0.6"
11
10
  platform: ruby
12
11
  authors:
13
12
  - George Georgiev
@@ -15,7 +14,7 @@ autorequire:
15
14
  bindir: bin
16
15
  cert_chain: []
17
16
 
18
- date: 2011-06-06 00:00:00 Z
17
+ date: 2011-08-22 00:00:00 Z
19
18
  dependencies: []
20
19
 
21
20
  description: Firebird SQL access library
@@ -121,6 +120,7 @@ files:
121
120
  - test/SQLTypeTest.rb
122
121
  - test/ServiceManagerTest.rb
123
122
  - test/StatementTest.rb
123
+ - test/StoredProcedureTest.rb
124
124
  - test/TestSetup.rb
125
125
  - test/TransactionTest.rb
126
126
  - test/TypeTest.rb