fb 0.6.3 → 0.6.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/fb.c +16 -3
  2. data/test/DataTypesTestCases.rb +23 -10
  3. metadata +6 -4
data/fb.c CHANGED
@@ -1453,6 +1453,7 @@ static void fb_cursor_set_inputparams(struct FbCursor *fb_cursor, int argc, VALU
1453
1453
  short dtp;
1454
1454
  VALUE obj;
1455
1455
  long lvalue;
1456
+ ISC_INT64 llvalue;
1456
1457
  long alignment;
1457
1458
  double ratio;
1458
1459
  double dvalue;
@@ -1590,8 +1591,20 @@ static void fb_cursor_set_inputparams(struct FbCursor *fb_cursor, int argc, VALU
1590
1591
  case SQL_INT64 :
1591
1592
  offset = FB_ALIGN(offset, alignment);
1592
1593
  var->sqldata = (char *)(fb_cursor->i_buffer + offset);
1593
- obj = ll_from_obj(obj);
1594
- *(ISC_INT64 *)var->sqldata = NUM2LL(obj);
1594
+
1595
+ if (var->sqlscale < 0) {
1596
+ ratio = 1;
1597
+ for (scnt = 0; scnt > var->sqlscale; scnt--)
1598
+ ratio *= 10;
1599
+ obj = double_from_obj(obj);
1600
+ dvalue = NUM2DBL(obj) * ratio;
1601
+ llvalue = (ISC_INT64)(dvalue + 0.5);
1602
+ } else {
1603
+ obj = ll_from_obj(obj);
1604
+ llvalue = NUM2LL(obj);
1605
+ }
1606
+
1607
+ *(ISC_INT64 *)var->sqldata = llvalue;
1595
1608
  offset += alignment;
1596
1609
  break;
1597
1610
  #endif
@@ -2887,7 +2900,7 @@ static VALUE hash_from_connection_string(VALUE cs)
2887
2900
 
2888
2901
  static void check_page_size(int page_size)
2889
2902
  {
2890
- if (page_size != 1024 && page_size != 2048 && page_size != 4096 && page_size != 8192) {
2903
+ if (page_size != 1024 && page_size != 2048 && page_size != 4096 && page_size != 8192 && page_size != 16384) {
2891
2904
  rb_raise(rb_eFbError, "Invalid page size: %d", page_size);
2892
2905
  }
2893
2906
  }
@@ -113,19 +113,20 @@ class DataTypesTestCases < Test::Unit::TestCase
113
113
  TM TIME,
114
114
  TS TIMESTAMP,
115
115
  N92 NUMERIC(9,2),
116
- D92 DECIMAL(9,2));
116
+ D92 DECIMAL(9,2),
117
+ N154 NUMERIC(15,4));
117
118
  END
118
119
  sql_insert = <<-END
119
120
  insert into test
120
- (I, SI, BI, F, D, C, C10, VC, VC10, VC10000, DT, TM, TS, N92, D92)
121
+ (I, SI, BI, F, D, C, C10, VC, VC10, VC10000, DT, TM, TS, N92, D92, N154)
121
122
  values
122
- (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);
123
+ (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);
123
124
  END
124
125
  sql_select = "select * from TEST order by I"
125
- sql_sum = "select sum(I), sum(SI), sum(BI), sum(F), sum(D), sum(N92), sum(D92) from TEST"
126
- sql_avg = "select avg(I), avg(SI), avg(BI), avg(F), avg(D), avg(N92), avg(D92) from TEST"
127
- sql_max = "select max(I), max(SI), max(BI), max(F), max(D), max(N92), max(D92) from TEST"
128
- sql_min = "select min(I), min(SI), min(BI), min(F), min(D), min(N92), min(D92) from TEST"
126
+ sql_sum = "select sum(I), sum(SI), sum(BI), sum(F), sum(D), sum(N92), sum(D92), sum(N154) from TEST"
127
+ sql_avg = "select avg(I), avg(SI), avg(BI), avg(F), avg(D), avg(N92), avg(D92), avg(N154) from TEST"
128
+ sql_max = "select max(I), max(SI), max(BI), max(F), max(D), max(N92), max(D92), max(N154) from TEST"
129
+ sql_min = "select min(I), min(SI), min(BI), min(F), min(D), min(N92), min(D92), min(N154) from TEST"
129
130
  Database.create(@parms) do |connection|
130
131
  connection.execute(sql_schema);
131
132
  connection.transaction do
@@ -136,7 +137,7 @@ class DataTypesTestCases < Test::Unit::TestCase
136
137
  gen_f(i), gen_d(i),
137
138
  gen_c(i), gen_c10(i), gen_vc(i), gen_vc10(i), gen_vc10000(i),
138
139
  gen_dt(i), gen_tm(i), gen_ts(i),
139
- gen_n92(i), gen_d92(i))
140
+ gen_n92(i), gen_d92(i), gen_n92(i))
140
141
  end
141
142
  end
142
143
  connection.execute(sql_select) do |cursor|
@@ -157,6 +158,7 @@ class DataTypesTestCases < Test::Unit::TestCase
157
158
  assert_equal gen_ts(i), row["TS"], "TIMESTAMP"
158
159
  assert_equal gen_n92(i), row["N92"], "NUMERIC"
159
160
  assert_equal gen_d92(i), row["D92"], "DECIMAL"
161
+ assert_equal gen_n92(i), row["N154"], "NUMERIC"
160
162
  i += 1
161
163
  end
162
164
  end
@@ -169,6 +171,7 @@ class DataTypesTestCases < Test::Unit::TestCase
169
171
  assert_equal sum_d(0...10), sums[4], "DOUBLE PRECISION"
170
172
  assert_equal sum_n92(0...10), sums[5], "NUMERIC" # 4500.00
171
173
  assert_equal sum_d92(0...10), sums[6], "DECIMAL" # 4500.00
174
+ assert_equal sum_n92(0...10), sums[7], "NUMERIC" # 4500.00
172
175
 
173
176
  avgs = connection.query(sql_avg).first
174
177
  assert_equal sum_i(0...10) / 10, avgs[0], "INTEGER"
@@ -178,6 +181,7 @@ class DataTypesTestCases < Test::Unit::TestCase
178
181
  assert_equal sum_d(0...10) / 10, avgs[4], "DOUBLE PRECISION"
179
182
  assert_equal sum_n92(0...10) / 10, avgs[5], "NUMERIC" # 450.00
180
183
  assert_equal sum_d92(0...10) / 10, avgs[6], "DECIMAL" # 450.00
184
+ assert_equal sum_n92(0...10) / 10, avgs[7], "NUMERIC" # 450.00
181
185
 
182
186
  maxs = connection.query(sql_max).first
183
187
  assert_equal gen_i(9), maxs[0], "INTEGER"
@@ -187,6 +191,7 @@ class DataTypesTestCases < Test::Unit::TestCase
187
191
  assert_equal gen_d(9), maxs[4], "DOUBLE PRECISION"
188
192
  assert_equal gen_n92(9), maxs[5], "NUMERIC"
189
193
  assert_equal gen_d92(9), maxs[6], "DECIMAL"
194
+ assert_equal gen_n92(9), maxs[7], "NUMERIC"
190
195
 
191
196
  mins = connection.query(sql_min).first
192
197
  assert_equal gen_i(0), mins[0], "INTEGER"
@@ -196,6 +201,7 @@ class DataTypesTestCases < Test::Unit::TestCase
196
201
  assert_equal gen_d(0), mins[4], "DOUBLE PRECISION"
197
202
  assert_equal gen_n92(0), mins[5], "NUMERIC"
198
203
  assert_equal gen_d92(0), mins[6], "DECIMAL"
204
+ assert_equal gen_n92(0), mins[7], "NUMERIC"
199
205
  connection.drop
200
206
  end
201
207
  end
@@ -380,8 +386,8 @@ class DataTypesTestCases < Test::Unit::TestCase
380
386
  end
381
387
 
382
388
  def test_insert_correct_types
383
- cols = %w{ I SI BI F D C C10 VC VC10 VC10000 DT TM TS N92 D92 }
384
- types = %w{ INTEGER SMALLINT BIGINT FLOAT DOUBLE\ PRECISION CHAR CHAR(10) VARCHAR(1) VARCHAR(10) VARCHAR(10000) DATE TIME TIMESTAMP NUMERIC(9,2) DECIMAL(9,2) }
389
+ cols = %w{ I SI BI F D C C10 VC VC10 VC10000 DT TM TS N92 D92 N154 }
390
+ types = %w{ INTEGER SMALLINT BIGINT FLOAT DOUBLE\ PRECISION CHAR CHAR(10) VARCHAR(1) VARCHAR(10) VARCHAR(10000) DATE TIME TIMESTAMP NUMERIC(9,2) DECIMAL(9,2) NUMERIC(15,4) }
385
391
  sql_schema = "";
386
392
  assert_equal cols.size, types.size
387
393
  cols.size.times do |i|
@@ -488,6 +494,13 @@ class DataTypesTestCases < Test::Unit::TestCase
488
494
  # puts vals.inspect
489
495
  assert_equal 12345.12, vals[0][0], "DECIMAL (decimal)"
490
496
  assert_equal 12345.12, vals[1][0], "DECIMAL (string)"
497
+ elsif cols[i] == 'N154'
498
+ connection.execute(sql_insert, 12345.12)
499
+ connection.execute(sql_insert, "12345.12")
500
+ vals = connection.query(sql_select)
501
+ # puts vals.inspect
502
+ assert_equal 12345.12, vals[0][0], "NUMERIC (decimal)"
503
+ assert_equal 12345.12, vals[1][0], "NUMERIC (string)"
491
504
  end
492
505
  end
493
506
  connection.drop
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.3
4
+ version: 0.6.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brent Rowland
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-09-10 00:00:00 -07:00
12
+ date: 2009-09-26 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -35,6 +35,8 @@ files:
35
35
  - test/TransactionTestCases.rb
36
36
  has_rdoc: true
37
37
  homepage: http://github.com/rowland/fb
38
+ licenses: []
39
+
38
40
  post_install_message:
39
41
  rdoc_options:
40
42
  - --title
@@ -60,9 +62,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
60
62
  requirements:
61
63
  - Firebird client library fbclient.dll, libfbclient.so or Firebird.framework.
62
64
  rubyforge_project: fblib
63
- rubygems_version: 1.3.1
65
+ rubygems_version: 1.3.5
64
66
  signing_key:
65
- specification_version: 2
67
+ specification_version: 3
66
68
  summary: Firebird and Interbase driver
67
69
  test_files:
68
70
  - test/FbTestSuite.rb