fb 0.8.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 56b7ad010f318291b4148cebb5414df0b7c1a79c
4
- data.tar.gz: 5ca9b16f94542bbf38d4242c4bafd7006bf2053f
3
+ metadata.gz: 7d8e0d820f068703a7427f675e1e40bf5202287c
4
+ data.tar.gz: 280d0ae8ceb2eaf63ff07ff049986c53d45bd7d5
5
5
  SHA512:
6
- metadata.gz: 942287471507083b6dc9f79afa188442c32b3d397eb1119b9fd48f6fabf45e576dcab4f8d7282593d9a7f788692636a8534d9901ae60d6189142d75c8118da4b
7
- data.tar.gz: 5f576f90e7cb59f5aeaa3bff5cb1471200b3d1a08bef3f0f1c3dd218ed79c6a89a0cc3e8de0c222c300ff4a5ccde6c6f7f36e4ae98c5469f597772232f397931
6
+ metadata.gz: 41569151e53743c4f48178f848ec884125c3c2a8bee7d23b098626e8ddc2f0c1f5354bc59526738e7b0f042b68526b283e942a1b26cc0f296c72d321a67bc992
7
+ data.tar.gz: aaa348851b9b97b6c2508cbe7e6495bb0f7aaf521949171b5f7fa29db9053bf14d082e8367c63d9d157d86f0fcc7f708af7844c82d6e10af5cd3ff7d50018208
data/extconf.rb CHANGED
@@ -18,23 +18,42 @@ def unquote(string)
18
18
  string.sub(/\A(['"])?(.*?)\1?\z/m, '\2') unless string.nil?
19
19
  end
20
20
 
21
+ def key_exists?(path)
22
+ begin
23
+ Win32::Registry::HKEY_LOCAL_MACHINE.open(path, ::Win32::Registry::KEY_READ)
24
+ return true
25
+ rescue
26
+ return false
27
+ end
28
+ end
29
+
21
30
  def read_firebird_registry
22
31
  require 'win32/registry'
23
- Win32::Registry::HKEY_LOCAL_MACHINE.open('SOFTWARE\Firebird Project\Firebird Server\Instances', Win32::Registry::Constants::KEY_READ) do |reg|
24
- return reg.read_s('DefaultInstance') rescue nil
32
+ if key_exists?('SOFTWARE\Firebird Project\Firebird Server\Instances')
33
+ Win32::Registry::HKEY_LOCAL_MACHINE.open('SOFTWARE\Firebird Project\Firebird Server\Instances', Win32::Registry::Constants::KEY_READ) do |reg|
34
+ return reg.read_s('DefaultInstance') rescue nil
35
+ end
36
+ else
37
+ return false
25
38
  end
26
39
  end
27
40
 
28
41
  def search_firebird_path
29
42
  program_files = ENV['ProgramFiles'].gsub('\\', '/').gsub(/(\w+\s+[\w\s]+)/) { |s| s.size > 8 ? s[0,6] + '~1' : s }
30
- Dir["#{program_files}/Firebird/Firebird_*"].sort.last
43
+ program_files_x86 = ENV['ProgramFiles'].gsub('\\', '/').gsub(/(\w+\s+[\w\s]+)/) { |s| s.size > 8 ? s[0,6] + '~2' : s }
44
+ result = Dir["#{program_files}/Firebird/Firebird_*"].sort.last || Dir["#{program_files_x86}/Firebird/Firebird_*"].sort.last
31
45
  end
32
46
 
33
47
  if RUBY_PLATFORM =~ /(mingw32|mswin32)/ and ARGV.grep(/^--with-opt-dir=/).empty?
34
48
  opt = unquote(ENV['FIREBIRD'])
35
49
  opt = opt || read_firebird_registry
36
50
  opt = opt || search_firebird_path
37
- ARGV << "--with-opt-dir=#{opt}" if opt
51
+ if opt
52
+ ARGV << "--with-opt-dir=#{opt}"
53
+ else
54
+ puts "No any Firebird instances found in system."
55
+ exit
56
+ end
38
57
  end
39
58
 
40
59
  require 'mkmf'
data/fb.c CHANGED
@@ -41,6 +41,7 @@
41
41
  #include <ibase.h>
42
42
  #include <float.h>
43
43
  #include <time.h>
44
+ #include <stdbool.h>
44
45
 
45
46
 
46
47
  #define SQLDA_COLSINIT 50
@@ -403,6 +404,12 @@ static VALUE fb_sql_type_from_code(int code, int subtype)
403
404
  case SQL_ARRAY:
404
405
  sql_type = "ARRAY";
405
406
  break;
407
+ #if (FB_API_VER >= 30)
408
+ case SQL_BOOLEAN:
409
+ case blr_boolean:
410
+ sql_type = "BOOLEAN";
411
+ break;
412
+ #endif
406
413
  case SQL_QUAD:
407
414
  case blr_quad:
408
415
  sql_type = "DECIMAL";
@@ -1520,6 +1527,14 @@ static void fb_cursor_set_inputparams(struct FbCursor *fb_cursor, long argc, VAL
1520
1527
  break;
1521
1528
  #endif
1522
1529
 
1530
+ #if (FB_API_VER >= 30)
1531
+ case SQL_BOOLEAN:
1532
+ offset = FB_ALIGN(offset, alignment);
1533
+ var->sqldata = (char *)(fb_cursor->i_buffer + offset);
1534
+ *(bool *)var->sqldata = obj;
1535
+ offset += alignment;
1536
+ break;
1537
+ #endif
1523
1538
  default :
1524
1539
  rb_raise(rb_eFbError, "Specified table includes unsupported datatype (%d)", dtp);
1525
1540
  }
@@ -1611,6 +1626,9 @@ static VALUE precision_from_sqlvar(XSQLVAR *sqlvar)
1611
1626
  case SQL_TIMESTAMP: return Qnil;
1612
1627
  case SQL_BLOB: return Qnil;
1613
1628
  case SQL_ARRAY: return Qnil;
1629
+ #if (FB_API_VER >= 30)
1630
+ case SQL_BOOLEAN: return Qnil;
1631
+ #endif
1614
1632
  case SQL_QUAD: return Qnil;
1615
1633
  case SQL_TYPE_TIME: return Qnil;
1616
1634
  case SQL_TYPE_DATE: return Qnil;
@@ -1791,6 +1809,7 @@ static VALUE fb_cursor_fetch(struct FbCursor *fb_cursor)
1791
1809
  dtp = var->sqltype & ~1;
1792
1810
 
1793
1811
  /* Check if column is null */
1812
+
1794
1813
 
1795
1814
  if ((var->sqltype & 1) && (*var->sqlind < 0)) {
1796
1815
  val = Qnil;
@@ -1906,6 +1925,12 @@ static VALUE fb_cursor_fetch(struct FbCursor *fb_cursor)
1906
1925
  val = Qnil;
1907
1926
  break;
1908
1927
 
1928
+ #if (FB_API_VER >= 30)
1929
+ case SQL_BOOLEAN:
1930
+ val = ((*(int*)var->sqldata) == 1) ? Qtrue : Qfalse;
1931
+ break;
1932
+ #endif
1933
+
1909
1934
  default:
1910
1935
  rb_raise(rb_eFbError, "Specified table includes unsupported datatype (%ld)", dtp);
1911
1936
  break;
@@ -20,27 +20,43 @@ class ConnectionTestCases < FbTestCase
20
20
  def test_query_select
21
21
  sql_select = "SELECT * FROM RDB$DATABASE"
22
22
  Database.create(@parms) do |connection|
23
+
23
24
  d = connection.query(sql_select)
24
25
  assert_instance_of Array, d
25
26
  assert_equal 1, d.size
26
27
  assert_instance_of Array, d.first
27
- assert_equal 4, d.first.size
28
-
28
+ if @fb_version == 3
29
+ assert_equal 5, d.first.size
30
+ else
31
+ assert_equal 4, d.first.size
32
+ end
33
+
29
34
  a = connection.query(:array, sql_select)
30
35
  assert_instance_of Array, a
31
36
  assert_equal 1, a.size
32
37
  assert_instance_of Array, a.first
33
- assert_equal 4, a.first.size
38
+ if @fb_version == 3
39
+ assert_equal 5, a.first.size
40
+ else
41
+ assert_equal 4, a.first.size
42
+ end
34
43
 
35
44
  h = connection.query(:hash, sql_select)
36
45
  assert_instance_of Array, h
37
46
  assert_equal 1, h.size
38
47
  assert_instance_of Hash, h.first
39
- assert_equal 4, h.first.keys.size
48
+ if @fb_version == 3
49
+ assert_equal 5, h.first.keys.size
50
+ else
51
+ assert_equal 4, h.first.keys.size
52
+ end
40
53
  assert h.first.keys.include?("RDB$DESCRIPTION")
41
54
  assert h.first.keys.include?("RDB$RELATION_ID")
42
55
  assert h.first.keys.include?("RDB$SECURITY_CLASS")
43
56
  assert h.first.keys.include?("RDB$CHARACTER_SET_NAME")
57
+ if @fb_version == 3
58
+ assert h.first.keys.include?("RDB$LINGER")
59
+ end
44
60
  end
45
61
  end
46
62
 
@@ -9,13 +9,17 @@ class CursorTestCases < FbTestCase
9
9
  assert_instance_of Cursor, cursor
10
10
  row = cursor.fetch :array
11
11
  assert_instance_of Array, row
12
- assert_equal 4, row.size
12
+ if @fb_version == 3
13
+ assert_equal 5, row.size
14
+ else
15
+ assert_equal 4, row.size
16
+ end
13
17
  end
14
18
  connection.execute("select * from rdb$database where rdb$description = 'bogus'") do |cursor|
15
19
  assert_instance_of Cursor, cursor
16
20
  row = cursor.fetch :array
17
21
  assert_instance_of NilClass, row
18
- assert_equal nil, row
22
+ assert_nil row
19
23
  end
20
24
  connection.drop
21
25
  end
@@ -27,13 +31,17 @@ class CursorTestCases < FbTestCase
27
31
  assert_instance_of Cursor, cursor
28
32
  row = cursor.fetch :hash
29
33
  assert_instance_of Hash, row
30
- assert_equal 4, row.size
34
+ if @fb_version == 3
35
+ assert_equal 5, row.size
36
+ else
37
+ assert_equal 4, row.size
38
+ end
31
39
  end
32
40
  connection.execute("select * from rdb$database where rdb$description = 'bogus'") do |cursor|
33
41
  assert_instance_of Cursor, cursor
34
42
  row = cursor.fetch :hash
35
43
  assert_instance_of NilClass, row
36
- assert_equal nil, row
44
+ assert_nil row
37
45
  end
38
46
  connection.drop
39
47
  end
@@ -47,7 +55,11 @@ class CursorTestCases < FbTestCase
47
55
  assert_instance_of Array, rows
48
56
  assert_equal 1, rows.size
49
57
  assert_instance_of Array, rows[0]
50
- assert_equal 4, rows[0].size
58
+ if @fb_version == 3
59
+ assert_equal 5, rows[0].size
60
+ else
61
+ assert_equal 4, rows[0].size
62
+ end
51
63
  end
52
64
  connection.drop
53
65
  end
@@ -61,7 +73,11 @@ class CursorTestCases < FbTestCase
61
73
  assert_instance_of Array, rows
62
74
  assert_equal 1, rows.size
63
75
  assert_instance_of Hash, rows[0]
64
- assert_equal 4, rows[0].size
76
+ if @fb_version == 3
77
+ assert_equal 5, rows[0].size
78
+ else
79
+ assert_equal 4, rows[0].size
80
+ end
65
81
  end
66
82
  connection.drop
67
83
  end
@@ -73,11 +89,18 @@ class CursorTestCases < FbTestCase
73
89
  fields = cursor.fields
74
90
  fields_ary = cursor.fields :array
75
91
  assert_equal fields, fields_ary
76
- assert_equal 4, fields.size
92
+ if @fb_version == 3
93
+ assert_equal 5, fields.size
94
+ else
95
+ assert_equal 4, fields.size
96
+ end
77
97
  assert_equal "RDB$DESCRIPTION", fields[0].name;
78
98
  assert_equal "RDB$RELATION_ID", fields[1].name;
79
99
  assert_equal "RDB$SECURITY_CLASS", fields[2].name;
80
100
  assert_equal "RDB$CHARACTER_SET_NAME", fields[3].name;
101
+ if @fb_version == 3
102
+ assert_equal "RDB$LINGER", fields[4].name;
103
+ end
81
104
  end
82
105
  connection.drop
83
106
  end
@@ -89,11 +112,18 @@ class CursorTestCases < FbTestCase
89
112
  fields = cursor.fields
90
113
  fields_ary = cursor.fields :array
91
114
  assert_equal fields, fields_ary
92
- assert_equal 4, fields.size
115
+ if @fb_version == 3
116
+ assert_equal 5, fields.size
117
+ else
118
+ assert_equal 4, fields.size
119
+ end
93
120
  assert_equal "rdb$description", fields[0].name;
94
121
  assert_equal "rdb$relation_id", fields[1].name;
95
122
  assert_equal "rdb$security_class", fields[2].name;
96
123
  assert_equal "rdb$character_set_name", fields[3].name;
124
+ if @fb_version == 3
125
+ assert_equal "rdb$linger", fields[4].name;
126
+ end
97
127
  end
98
128
  connection.drop
99
129
  end
@@ -103,11 +133,18 @@ class CursorTestCases < FbTestCase
103
133
  Database.create(@parms) do |connection|
104
134
  connection.execute("select * from rdb$database") do |cursor|
105
135
  fields = cursor.fields :hash
106
- assert_equal 4, fields.size
136
+ if @fb_version == 3
137
+ assert_equal 5, fields.size
138
+ else
139
+ assert_equal 4, fields.size
140
+ end
107
141
  assert_equal 520, fields["RDB$DESCRIPTION"].type_code
108
142
  assert_equal 500, fields["RDB$RELATION_ID"].type_code
109
143
  assert_equal 452, fields["RDB$SECURITY_CLASS"].type_code
110
144
  assert_equal 452, fields["RDB$CHARACTER_SET_NAME"].type_code
145
+ if @fb_version == 3
146
+ assert_equal 496, fields["RDB$LINGER"].type_code
147
+ end
111
148
  end
112
149
  connection.drop
113
150
  end
@@ -117,11 +154,18 @@ class CursorTestCases < FbTestCase
117
154
  Database.create(@parms.merge(:downcase_names => true)) do |connection| # xxx true
118
155
  connection.execute("select * from rdb$database") do |cursor|
119
156
  fields = cursor.fields :hash
120
- assert_equal 4, fields.size
157
+ if @fb_version == 3
158
+ assert_equal 5, fields.size
159
+ else
160
+ assert_equal 4, fields.size
161
+ end
121
162
  assert_equal 520, fields["rdb$description"].type_code
122
163
  assert_equal 500, fields["rdb$relation_id"].type_code
123
164
  assert_equal 452, fields["rdb$security_class"].type_code
124
165
  assert_equal 452, fields["rdb$character_set_name"].type_code
166
+ if @fb_version == 3
167
+ assert_equal 496, fields["rdb$linger"].type_code
168
+ end
125
169
  end
126
170
  connection.drop
127
171
  end
@@ -134,7 +178,11 @@ class CursorTestCases < FbTestCase
134
178
  cursor.each :array do |row|
135
179
  count += 1
136
180
  assert_instance_of Array, row
137
- assert_equal 4, row.size
181
+ if @fb_version == 3
182
+ assert_equal 5, row.size
183
+ else
184
+ assert_equal 4, row.size
185
+ end
138
186
  end
139
187
  assert_equal 1, count
140
188
  end
@@ -149,7 +197,11 @@ class CursorTestCases < FbTestCase
149
197
  cursor.each :hash do |row|
150
198
  count += 1
151
199
  assert_instance_of Hash, row
152
- assert_equal 4, row.size
200
+ if @fb_version == 3
201
+ assert_equal 5, row.size
202
+ else
203
+ assert_equal 4, row.size
204
+ end
153
205
  end
154
206
  assert_equal 1, count
155
207
  end
@@ -511,4 +511,55 @@ class DataTypesTestCases < FbTestCase
511
511
  connection.drop
512
512
  end
513
513
  end
514
+
515
+ def test_boolean_type
516
+ if @fb_version == 3
517
+
518
+ sql_schema = "create table testboolean (id int generated by default as identity primary key, bval boolean)"
519
+ sql_insert = "insert into testboolean (bval) values (?)"
520
+ sql_select = "select * from testboolean order by id"
521
+
522
+ Database.create(@parms) do |connection|
523
+
524
+ connection.execute(sql_schema);
525
+
526
+ connection.transaction do
527
+
528
+ connection.execute(sql_insert, nil);
529
+
530
+ connection.execute(sql_insert, false);
531
+
532
+ connection.execute(sql_insert, true);
533
+
534
+ 5.times do |i|
535
+ connection.execute(sql_insert, i.even?);
536
+ end
537
+
538
+ end
539
+
540
+ connection.execute(sql_select) do |cursor|
541
+
542
+ i = 0
543
+
544
+ cursor.each :hash do |row|
545
+ case i
546
+ when 0
547
+ assert_nil row["BVAL"]
548
+ when 1
549
+ assert_equal false, row["BVAL"]
550
+ when 2
551
+ assert_equal true, row["BVAL"]
552
+ else
553
+ end
554
+ i += 1
555
+ end
556
+
557
+ end
558
+
559
+ connection.drop
560
+
561
+ end
562
+ end
563
+ end
564
+
514
565
  end
@@ -40,8 +40,21 @@ module FbTestCases
40
40
  :charset => 'NONE',
41
41
  :role => 'READER' }
42
42
  @parms_s = "database = #{@db_host}:#{@db_file}; username = #{@username}; password = #{@password}; charset = NONE; role = READER;"
43
+ @fb_version = -1
44
+ rm_rf @db_file
45
+
46
+ Database.create(@parms) do |connection|
47
+
48
+ d = connection.query("SELECT substring(rdb$get_context('SYSTEM', 'ENGINE_VERSION') from 1 for 1) from rdb$database")
49
+
50
+ @fb_version = Integer(d.first[0])
51
+
52
+ connection.drop
53
+ end
54
+
43
55
  rm_rf @db_file
44
56
  end
57
+
45
58
  end
46
59
 
47
60
  class Fb::Connection
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brent Rowland
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-20 00:00:00.000000000 Z
11
+ date: 2018-01-10 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Ruby Firebird Extension Library
14
14
  email: rowland@rowlandresearch.com