Skip to content

Commit 04f22a1

Browse files
committed
More cleanup.
1 parent ab34f08 commit 04f22a1

File tree

9 files changed

+17
-69
lines changed

9 files changed

+17
-69
lines changed

lib/active_record/connection_adapters/sqlserver/schema_creation.rb

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -23,34 +23,6 @@ def add_column_options!(sql, options)
2323
end
2424
end
2525

26-
def visit_TableDefinition(o)
27-
quoted_name = "#{quote_table_name((o.temporary ? '#' : '') + o.name.to_s)} "
28-
29-
if o.as
30-
if o.as.is_a?(ActiveRecord::Relation)
31-
select = o.as.to_sql
32-
elsif o.as.is_a?(String)
33-
select = o.as
34-
else
35-
raise 'Only able to generate a table from a SELECT statement passed as a String or ActiveRecord::Relation'
36-
end
37-
38-
create_sql = 'SELECT * INTO '
39-
create_sql << quoted_name
40-
create_sql << 'FROM ('
41-
create_sql << select
42-
create_sql << ') AS __sq'
43-
44-
else
45-
create_sql = "CREATE TABLE "
46-
create_sql << quoted_name
47-
create_sql << "(#{o.columns.map { |c| accept c }.join(', ')}) "
48-
create_sql << "#{o.options}"
49-
end
50-
51-
create_sql
52-
end
53-
5426
end
5527
end
5628
end

test/cases/specific_schema_test_sqlserver.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ class SpecificSchemaTestSQLServer < ActiveRecord::TestCase
99
SSTestDollarTableName.limit(20).offset(1)
1010
end
1111

12+
it 'models can use tinyint pk tables' do
13+
obj = SSTestTinyintPk.create! name: '1'
14+
obj.id.is_a? Fixnum
15+
SSTestTinyintPk.find(obj.id).must_equal obj
16+
end
17+
1218
it 'be able to complex count tables with no primary key' do
1319
SSTestNoPkData.delete_all
1420
10.times { |n| SSTestNoPkData.create! name: "Test#{n}" }

test/models/sql_server_order_row_number.rb

Lines changed: 0 additions & 3 deletions
This file was deleted.

test/models/sql_server_string.rb

Lines changed: 0 additions & 2 deletions
This file was deleted.

test/models/sql_server_tinyint_pk.rb

Lines changed: 0 additions & 3 deletions
This file was deleted.

test/models/sql_server_unicode.rb

Lines changed: 0 additions & 2 deletions
This file was deleted.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class SSTestTinyintPk < ActiveRecord::Base
2+
self.table_name = 'sst_tinyint_pk'
3+
end

test/models/table_with_real_column.rb

Lines changed: 0 additions & 2 deletions
This file was deleted.

test/schema/sqlserver_specific_schema.rb

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,6 @@
7575
t.column 'crazy]]quote', :string
7676
t.column 'with spaces', :string
7777
end
78-
execute %|ALTER TABLE [sst_edge_schemas] ADD [guid_newid] uniqueidentifier DEFAULT NEWID();|
79-
execute %|ALTER TABLE [sst_edge_schemas] ADD [guid_newseqid] uniqueidentifier DEFAULT NEWSEQUENTIALID();|
8078

8179
execute "IF EXISTS(SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'sst_natural_pk_data') DROP TABLE sst_natural_pk_data"
8280
execute <<-NATURALPKTABLESQL
@@ -98,6 +96,14 @@
9896
)
9997
NATURALPKINTTABLESQL
10098

99+
execute "IF EXISTS(SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'sst_tinyint_pk') DROP TABLE sst_tinyint_pk"
100+
execute <<-TINYITPKTABLE
101+
CREATE TABLE sst_tinyint_pk(
102+
id tinyint IDENTITY NOT NULL PRIMARY KEY,
103+
name nvarchar(255)
104+
)
105+
TINYITPKTABLE
106+
101107
# Constraints
102108

103109
create_table(:sst_has_fks, force: true) { |t| t.column(:fk_id, :integer, null: false) }
@@ -141,33 +147,6 @@
141147

142148

143149

144-
# http://blogs.msdn.com/b/craigfr/archive/2008/03/19/ranking-functions-row-number.aspx
145-
execute "IF EXISTS(SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'order_row_number') DROP TABLE order_row_number"
146-
execute <<-ORDERROWNUMBERSQL
147-
CREATE TABLE [order_row_number] (id int IDENTITY, a int, b int, c int)
148-
CREATE UNIQUE CLUSTERED INDEX [idx_order_row_number_id] ON [order_row_number] ([id])
149-
INSERT [order_row_number] VALUES (0, 1, 8)
150-
INSERT [order_row_number] VALUES (0, 3, 6)
151-
INSERT [order_row_number] VALUES (0, 5, 4)
152-
INSERT [order_row_number] VALUES (0, 7, 2)
153-
INSERT [order_row_number] VALUES (0, 9, 0)
154-
INSERT [order_row_number] VALUES (1, 0, 9)
155-
INSERT [order_row_number] VALUES (1, 2, 7)
156-
INSERT [order_row_number] VALUES (1, 4, 5)
157-
INSERT [order_row_number] VALUES (1, 6, 3)
158-
INSERT [order_row_number] VALUES (1, 8, 1)
159-
ORDERROWNUMBERSQL
160-
161-
execute "IF EXISTS(SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'tinyint_pk_table') DROP TABLE tinyint_pk_table"
162-
execute <<-TINYITPKTABLE
163-
CREATE TABLE tinyint_pk_table(
164-
id tinyint NOT NULL PRIMARY KEY,
165-
name nvarchar(255)
166-
)
167-
TINYITPKTABLE
168-
169-
170-
171150

172151

173152

0 commit comments

Comments
 (0)