rubyfb 0.6 → 0.6.1
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.
- data/Rakefile +1 -1
- data/ext/TypeMap.c +27 -85
- data/lib/active_record/connection_adapters/rubyfb_adapter.rb +3 -0
- data/lib/rubyfb_lib.so +0 -0
- data/rubyfb.gemspec +15 -15
- data/test/SQLTest.rb +10 -9
- metadata +5 -4
data/Rakefile
CHANGED
data/ext/TypeMap.c
CHANGED
@@ -57,6 +57,27 @@ void populateDateField(VALUE, XSQLVAR *);
|
|
57
57
|
void populateTimeField(VALUE, XSQLVAR *);
|
58
58
|
void populateTimestampField(VALUE, XSQLVAR *);
|
59
59
|
|
60
|
+
long long sql_scale(VALUE value, XSQLVAR *field) {
|
61
|
+
if(field->sqlscale == 0) {
|
62
|
+
value = rb_funcall(value, rb_intern("to_i"), 0);
|
63
|
+
} else {
|
64
|
+
value = rb_funcall(value, rb_intern("to_f"), 0);
|
65
|
+
// this requires special care - decimal point shift can cause type overflow
|
66
|
+
// the easyest way is to use ruby arithmetics (although it's not the fastes)
|
67
|
+
value = rb_funcall(value, rb_intern("*"), 1, LONG2NUM((long)pow(10, abs(field->sqlscale))));
|
68
|
+
}
|
69
|
+
return NUM2LL(value);
|
70
|
+
}
|
71
|
+
|
72
|
+
VALUE sql_unscale(VALUE value, XSQLVAR *field) {
|
73
|
+
if(field->sqlscale == 0) {
|
74
|
+
return value;
|
75
|
+
}
|
76
|
+
return rb_float_new(
|
77
|
+
NUM2DBL(rb_funcall(value, rb_intern("to_f"), 0)) / pow(10, abs(field->sqlscale))
|
78
|
+
);
|
79
|
+
}
|
80
|
+
|
60
81
|
/**
|
61
82
|
* This function converts a single XSQLVAR entry to a Ruby VALUE type.
|
62
83
|
*
|
@@ -129,38 +150,17 @@ VALUE toValue(XSQLVAR *entry,
|
|
129
150
|
break;
|
130
151
|
|
131
152
|
case SQL_INT64: /* Type: DECIMAL, NUMERIC */
|
132
|
-
|
133
|
-
double divisor = pow(10, abs(entry->sqlscale));
|
134
|
-
|
135
|
-
actual = *((long long *)entry->sqldata);
|
136
|
-
rb_ary_push(value, rb_float_new(actual / divisor));
|
137
|
-
} else {
|
138
|
-
rb_ary_push(value, LL2NUM(*((long long *)entry->sqldata)));
|
139
|
-
}
|
153
|
+
rb_ary_push(value, sql_unscale(LL2NUM(*((long long *)entry->sqldata)), entry));
|
140
154
|
rb_ary_push(value, getColumnType(entry));
|
141
155
|
break;
|
142
156
|
|
143
157
|
case SQL_LONG: /* Type: INTEGER, DECIMAL, NUMERIC */
|
144
|
-
|
145
|
-
double divisor = pow(10, abs(entry->sqlscale));
|
146
|
-
|
147
|
-
actual = *((int32_t *)entry->sqldata);
|
148
|
-
rb_ary_push(value, rb_float_new(actual / divisor));
|
149
|
-
} else {
|
150
|
-
rb_ary_push(value, LONG2NUM(*((int32_t *)entry->sqldata)));
|
151
|
-
}
|
158
|
+
rb_ary_push(value, sql_unscale(LONG2NUM(*((int32_t *)entry->sqldata)), entry));
|
152
159
|
rb_ary_push(value, getColumnType(entry));
|
153
160
|
break;
|
154
161
|
|
155
162
|
case SQL_SHORT: /* Type: SMALLINT, DECIMAL, NUMERIC */
|
156
|
-
|
157
|
-
double divisor = pow(10, abs(entry->sqlscale));
|
158
|
-
|
159
|
-
actual = *((short *)entry->sqldata);
|
160
|
-
rb_ary_push(value, rb_float_new(actual / divisor));
|
161
|
-
} else {
|
162
|
-
rb_ary_push(value, INT2NUM(*((short *)entry->sqldata)));
|
163
|
-
}
|
163
|
+
rb_ary_push(value, sql_unscale(INT2NUM(*((short *)entry->sqldata)), entry));
|
164
164
|
rb_ary_push(value, getColumnType(entry));
|
165
165
|
break;
|
166
166
|
|
@@ -865,21 +865,7 @@ void populateFloatField(VALUE value, XSQLVAR *field) {
|
|
865
865
|
*
|
866
866
|
*/
|
867
867
|
void populateInt64Field(VALUE value, XSQLVAR *field) {
|
868
|
-
|
869
|
-
long long store = 0;
|
870
|
-
|
871
|
-
if(TYPE(value) == T_STRING) {
|
872
|
-
if(field->sqlscale != 0) {
|
873
|
-
actual = rb_funcall(value, rb_intern("to_f"), 0);
|
874
|
-
} else {
|
875
|
-
actual = rb_funcall(value, rb_intern("to_i"), 0);
|
876
|
-
}
|
877
|
-
}
|
878
|
-
if(field->sqlscale != 0) {
|
879
|
-
actual = rb_funcall(actual, rb_intern("*"), 1, INT2NUM((long)pow(10, abs(field->sqlscale))));
|
880
|
-
}
|
881
|
-
store = NUM2LL(actual);
|
882
|
-
memcpy(field->sqldata, &store, field->sqllen);
|
868
|
+
*((long long *)field->sqldata) = sql_scale(value, field);
|
883
869
|
field->sqltype = SQL_INT64;
|
884
870
|
}
|
885
871
|
|
@@ -893,29 +879,7 @@ void populateInt64Field(VALUE value, XSQLVAR *field) {
|
|
893
879
|
*
|
894
880
|
*/
|
895
881
|
void populateLongField(VALUE value, XSQLVAR *field) {
|
896
|
-
|
897
|
-
long long full = 0;
|
898
|
-
long store = 0;
|
899
|
-
|
900
|
-
if(rb_obj_is_kind_of(value, rb_cInteger)) {
|
901
|
-
actual = value;
|
902
|
-
} else if(TYPE(value) == T_FLOAT) {
|
903
|
-
double number = NUM2DBL(value);
|
904
|
-
|
905
|
-
if(field->sqlscale != 0) {
|
906
|
-
number = number * pow(10, abs(field->sqlscale));
|
907
|
-
actual = INT2NUM((long)number);
|
908
|
-
}
|
909
|
-
} else if(TYPE(value) == T_STRING) {
|
910
|
-
actual = rb_funcall(value, rb_intern("to_i"), 0);
|
911
|
-
} else {
|
912
|
-
rb_fireruby_raise(NULL,
|
913
|
-
"Error converting input parameter to long integer.");
|
914
|
-
}
|
915
|
-
|
916
|
-
full = TYPE(actual) == T_FIXNUM ? FIX2INT(actual) : NUM2INT(actual);
|
917
|
-
store = (long)full;
|
918
|
-
memcpy(field->sqldata, &store, field->sqllen);
|
882
|
+
*((long *)field->sqldata) = sql_scale(value, field);
|
919
883
|
field->sqltype = SQL_LONG;
|
920
884
|
}
|
921
885
|
|
@@ -929,29 +893,7 @@ void populateLongField(VALUE value, XSQLVAR *field) {
|
|
929
893
|
*
|
930
894
|
*/
|
931
895
|
void populateShortField(VALUE value, XSQLVAR *field) {
|
932
|
-
|
933
|
-
long long full = 0;
|
934
|
-
short store = 0;
|
935
|
-
|
936
|
-
if(rb_obj_is_kind_of(value, rb_cInteger)) {
|
937
|
-
actual = value;
|
938
|
-
} else if(TYPE(value) == T_FLOAT) {
|
939
|
-
double number = NUM2DBL(value);
|
940
|
-
|
941
|
-
if(field->sqlscale != 0) {
|
942
|
-
number = number * pow(10, abs(field->sqlscale));
|
943
|
-
actual = INT2NUM((long)number);
|
944
|
-
}
|
945
|
-
} else if(TYPE(value) == T_STRING) {
|
946
|
-
actual = rb_funcall(value, rb_intern("to_i"), 0);
|
947
|
-
} else {
|
948
|
-
rb_fireruby_raise(NULL,
|
949
|
-
"Error converting input parameter to short integer.");
|
950
|
-
}
|
951
|
-
|
952
|
-
full = TYPE(actual) == T_FIXNUM ? FIX2INT(actual) : NUM2INT(actual);
|
953
|
-
store = (short)full;
|
954
|
-
memcpy(field->sqldata, &store, field->sqllen);
|
896
|
+
*((short *)field->sqldata) = sql_scale(value, field);
|
955
897
|
field->sqltype = SQL_SHORT;
|
956
898
|
}
|
957
899
|
|
@@ -74,7 +74,10 @@ module ActiveRecord
|
|
74
74
|
|
75
75
|
#FIXME ugly - but ... https://github.com/rails/rails/issues/1623
|
76
76
|
module FinderMethods
|
77
|
+
alias :rubyfb_exists_save :exists?
|
77
78
|
def exists?(id = nil)
|
79
|
+
return rubyfb_exists_save(id) unless ActiveRecord::VERSION::MAJOR >= 3 && (ActiveRecord::VERSION::MINOR > 0 || ActiveRecord::VERSION::TINY >= 9)
|
80
|
+
|
78
81
|
id = id.id if ActiveRecord::Base === id
|
79
82
|
|
80
83
|
join_dependency = construct_join_dependency_for_association_find
|
data/lib/rubyfb_lib.so
CHANGED
Binary file
|
data/rubyfb.gemspec
CHANGED
@@ -1,23 +1,23 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
|
-
s.name =
|
5
|
-
s.version = "0.6"
|
4
|
+
s.name = "rubyfb"
|
5
|
+
s.version = "0.6.1"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
-
s.authors = [
|
9
|
-
s.date =
|
10
|
-
s.description =
|
11
|
-
s.email =
|
12
|
-
s.extensions = [
|
13
|
-
s.extra_rdoc_files = [
|
14
|
-
s.files = [
|
15
|
-
s.homepage =
|
16
|
-
s.rdoc_options = [
|
17
|
-
s.require_paths = [
|
18
|
-
s.rubyforge_project =
|
19
|
-
s.rubygems_version =
|
20
|
-
s.summary =
|
8
|
+
s.authors = ["George Georgiev"]
|
9
|
+
s.date = "2011-10-16"
|
10
|
+
s.description = "Firebird SQL access library"
|
11
|
+
s.email = "georgiev@heatbs.com"
|
12
|
+
s.extensions = ["ext/extconf.rb"]
|
13
|
+
s.extra_rdoc_files = ["CHANGELOG", "LICENSE", "README", "examples/example01.rb", "ext/extconf.rb", "lib/Connection.rb", "lib/ProcedureCall.rb", "lib/SQLType.rb", "lib/rubyfb.rb", "lib/rubyfb_options.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/rfbint.h", "ext/rfbsleep.h", "ext/rfbstr.c", "ext/rfbstr.h", "ext/uncrustify.cfg", "lib/Connection.rb", "lib/ProcedureCall.rb", "lib/SQLType.rb", "lib/active_record/connection_adapters/rubyfb_adapter.rb", "lib/arel/visitors/rubyfb.rb", "lib/arel/visitors/rubyfb_15compat.rb", "lib/mkdoc", "lib/rubyfb.rb", "lib/rubyfb_lib.so", "lib/rubyfb_options.rb", "lib/src.rb", "mswin32fb/fbclient_mingw.def", "mswin32fb/fbclient_mingw.lib", "mswin32fb/fbclient_ms.lib", "mswin32fb/ibase.h", "mswin32fb/iberror.h", "test/AddRemoveUserTest.rb", "test/BackupRestoreTest.rb", "test/BlobTest.rb", "test/CharacterSetTest.rb", "test/ConnectionTest.rb", "test/DDLTest.rb", "test/DatabaseTest.rb", "test/FieldCharacterSetTest.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/StoredProcedureTest.rb", "test/TestSetup.rb", "test/TransactionTest.rb", "test/TypeTest.rb", "rubyfb.gemspec"]
|
15
|
+
s.homepage = "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 = "rubyfb"
|
19
|
+
s.rubygems_version = "1.8.10"
|
20
|
+
s.summary = "Firebird SQL access library"
|
21
21
|
|
22
22
|
if s.respond_to? :specification_version then
|
23
23
|
s.specification_version = 3
|
data/test/SQLTest.rb
CHANGED
@@ -90,11 +90,11 @@ class SQLTest < Test::Unit::TestCase
|
|
90
90
|
r = @transactions[0].execute("SELECT * FROM TEST_TABLE WHERE TESTID IN "\
|
91
91
|
"(2, 4, 6, 8, 10) ORDER BY TESTID ASCENDING")
|
92
92
|
a = r.fetch
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
93
|
+
assert_equal(2, a[0])
|
94
|
+
assert_equal('3.0', a[1])
|
95
|
+
assert_equal(3.0, a[2])
|
96
|
+
assert_nil(a[3])
|
97
|
+
assert_nil(a[4])
|
98
98
|
|
99
99
|
a = r.fetch
|
100
100
|
assert(a[0] == 4)
|
@@ -155,14 +155,15 @@ class SQLTest < Test::Unit::TestCase
|
|
155
155
|
s.close
|
156
156
|
|
157
157
|
# Fetch the record and check the data.
|
158
|
-
r = tx.execute("SELECT TESTTEXT, TESTFLOAT, TESTSTAMP FROM "\
|
158
|
+
r = tx.execute("SELECT TESTTEXT, TESTFLOAT, TESTSTAMP, cast(TESTFLOAT as varchar(20)) as TESTFLOAT_TXT FROM "\
|
159
159
|
"TEST_TABLE WHERE TESTID = 25000")
|
160
160
|
a = r.fetch
|
161
161
|
r.close
|
162
162
|
end
|
163
|
-
|
164
|
-
|
165
|
-
|
163
|
+
assert_equal('3.14', a[3])
|
164
|
+
assert_equal('La la la', a[0])
|
165
|
+
assert_equal(3.14, a[1])
|
166
|
+
assert_equal(t.to_i, a[2].to_i)
|
166
167
|
|
167
168
|
@connections[0].execute_immediate("DELETE FROM TEST_TABLE WHERE TESTID "\
|
168
169
|
"IN (1, 3, 5, 7, 9, 12, 14, 16, 18, 20)")
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubyfb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 5
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 6
|
9
|
-
|
9
|
+
- 1
|
10
|
+
version: 0.6.1
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- George Georgiev
|
@@ -14,7 +15,7 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date: 2011-
|
18
|
+
date: 2011-10-16 00:00:00 Z
|
18
19
|
dependencies: []
|
19
20
|
|
20
21
|
description: Firebird SQL access library
|
@@ -161,7 +162,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
161
162
|
requirements: []
|
162
163
|
|
163
164
|
rubyforge_project: rubyfb
|
164
|
-
rubygems_version: 1.8.
|
165
|
+
rubygems_version: 1.8.10
|
165
166
|
signing_key:
|
166
167
|
specification_version: 3
|
167
168
|
summary: Firebird SQL access library
|