File tree Expand file tree Collapse file tree 5 files changed +47
-1
lines changed
lib/active_record/connection_adapters/sqlserver_adapter/core_ext Expand file tree Collapse file tree 5 files changed +47
-1
lines changed Original file line number Diff line number Diff line change 11
22MASTER
33
4- *
4+ * Add support for tinyint data types. In MySQL all these types would be boolean, however in
5+ our adapter, they will use the full 1 => 255 Fixnum value as you would expect. [Ken Collins]
56
67
78* 2.2.21 * (September 10th, 2009)
Original file line number Diff line number Diff line change @@ -46,6 +46,14 @@ def self.parse(obj)
4646 obj . to_s
4747 end
4848 end
49+
50+ # We want our true 1 to 255 tinyint range.
51+ class SqlserverForcedTinyint
52+ def self . parse ( obj )
53+ return nil if ::DBI ::Type ::Null . parse ( obj ) . nil?
54+ obj . to_i
55+ end
56+ end
4957
5058 end
5159
@@ -68,6 +76,8 @@ def type_name_to_module_with_sqlserver_types(type_name)
6876 DBI ::Type ::SqlserverTimestamp
6977 when /^float|decimal|money$/i
7078 DBI ::Type ::SqlserverForcedString
79+ when /^tinyint$/i
80+ DBI ::Type ::SqlserverForcedTinyint
7181 else
7282 type_name_to_module_without_sqlserver_types ( type_name )
7383 end
Original file line number Diff line number Diff line change 11require 'cases/sqlserver_helper'
22require 'models/binary'
33
4+ class SqlServerEdgeSchema < ActiveRecord ::Base ; end ;
5+
46class ColumnTestSqlserver < ActiveRecord ::TestCase
57
68 def setup
@@ -260,5 +262,19 @@ def setup
260262
261263 end
262264
265+ context 'For tinyint columns' do
266+
267+ setup do
268+ @tinyint = SqlServerEdgeSchema . columns_hash [ 'tinyint' ]
269+ end
270+
271+ should 'be all it should be' do
272+ assert_equal :integer , @tinyint . type
273+ assert_nil @tinyint . scale
274+ assert_equal 'tinyint(1)' , @tinyint . sql_type
275+ end
276+
277+ end
278+
263279
264280end
Original file line number Diff line number Diff line change @@ -68,6 +68,24 @@ class SpecificSchemaTestSqlserver < ActiveRecord::TestCase
6868
6969 end
7070
71+ context 'with tinyint column' do
72+
73+ setup do
74+ @tiny1 = @edge_class . create! :tinyint => 1
75+ @tiny255 = @edge_class . create! :tinyint => 255
76+ end
77+
78+ should 'not treat tinyint like boolean as mysql does' do
79+ assert_equal 1 , @edge_class . find_by_tinyint ( 1 ) . tinyint
80+ assert_equal 255 , @edge_class . find_by_tinyint ( 255 ) . tinyint
81+ end
82+
83+ should 'throw an error when going out of our tiny int bounds' do
84+ assert_raise ( ActiveRecord ::StatementInvalid ) { @edge_class . create! :tinyint => 256 }
85+ end
86+
87+ end
88+
7189 end
7290
7391
Original file line number Diff line number Diff line change 6565 create_table :sql_server_edge_schemas , :force => true do |t |
6666 t . string :description
6767 t . column :bigint , :bigint
68+ t . column :tinyint , :tinyint
6869 end
6970
7071 execute "IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = 'customers_view') DROP VIEW customers_view"
You can’t perform that action at this time.
0 commit comments