activerecord-sqlserver-adapter 3.1.0.rc1 → 3.1.0.rc2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,7 +1,14 @@
1
1
 
2
- * 3.1.0.rc *
2
+ * 3.1.0 *
3
3
 
4
- It just works! Uses "EXEC sp_executesql ..." for just about everything now!
4
+ * Allow complex order objects to not be molested by our visitor overrides. Fixes #99
5
+
6
+ * Default unicode datatypes!
7
+
8
+ * New #lowercase_schema_reflection configuration that allows you to downcase all tables and columns.
9
+ Good for legacy databases. Fixes #86. Thanks @dmajkic.
10
+
11
+ * Rails 3.1 with prepared statement support. Uses "EXEC sp_executesql ..." for just about everything now.
5
12
 
6
13
 
7
14
  * 3.0.15 *
@@ -1,4 +1,4 @@
1
- Copyright (c) 2008-2010
1
+ Copyright (c) 2008-2011
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
@@ -6,8 +6,10 @@ The SQL Server adapter for ActiveRecord.
6
6
 
7
7
  == What's New
8
8
 
9
+ * Rails 3.1 prepared statement support leverages cached query plans.
10
+ * Default unicode datatypes! Disable with #enable_default_unicode_types to false.
11
+ * New #lowercase_schema_reflection configuration option for legacy DBs.
9
12
  * New dblib connection mode using TinyTds!
10
- * Rails 3 support!
11
13
 
12
14
 
13
15
  ==== Testing Rake Tasks Support
@@ -78,17 +80,29 @@ By default any :binary column created by migrations will create a 'varbinary(max
78
80
 
79
81
  ==== Setting Unicode Types As Default
80
82
 
81
- By default the adapter will use non-unicode safe data types for :string and :text types when defining/changing the schema. If you choose, you can set the following class attribute in a config/initializers file that will change this behavior. When set to true it has the equivalent meaning as the two lower items. These examples show detail level alternatives to achieve similar effects.
83
+ By default the adapter will use unicode safe data types for :string and :text types when defining/changing the schema!!! This was changed in version 3.1 since it is about time we push better unicode support and since we default to TinyTDS (DBLIB) which supports unicode queries and data. If you choose, you can set the following class attribute in a config/initializers file that will disable this behavior.
82
84
 
85
+ # Default
83
86
  ActiveRecord::ConnectionAdapters::SQLServerAdapter.enable_default_unicode_types = true
84
-
85
87
  ActiveRecord::ConnectionAdapters::SQLServerAdapter.native_text_database_type = 'nvarchar(max)'
86
88
  ActiveRecord::ConnectionAdapters::SQLServerAdapter.native_string_database_type = 'nvarchar'
89
+
90
+ # Disabled
91
+ ActiveRecord::ConnectionAdapters::SQLServerAdapter.enable_default_unicode_types = false
92
+ ActiveRecord::ConnectionAdapters::SQLServerAdapter.native_text_database_type = 'varchar(max)'
93
+ ActiveRecord::ConnectionAdapters::SQLServerAdapter.native_string_database_type = 'varchar'
87
94
 
88
95
  It is important to remember that unicode types in SQL Server have approximately half the storage capacity as their counter parts. So where a normal string would max out at (8000) a unicode string will top off at (4000).
89
96
 
90
97
 
91
- ==== Schema Information Logging
98
+ ==== Force Schema To Lowercase
99
+
100
+ Although it is not necessary, the Ruby convention is to use lowercase method names. If your database schema is in upper or mixed case, we can force all table and column names during the schema reflection process to be lowercase. Add this to your config/initializers file for the adapter.
101
+
102
+ ActiveRecord::ConnectionAdapters::SQLServerAdapter.lowercase_schema_reflection = true
103
+
104
+
105
+ ==== Schema Information Logging
92
106
 
93
107
  By default all queries to the INFORMATION_SCHEMA table is silenced. If you think logging these queries are useful, you can enable it by adding this like to a initializer file.
94
108
 
@@ -172,5 +186,5 @@ http://pledgie.com/campaigns/11630
172
186
 
173
187
  == License
174
188
 
175
- Copyright © 2008-2010. It is free software, and may be redistributed under the terms specified in the MIT-LICENSE file.
189
+ Copyright © 2008-2011. It is free software, and may be redistributed under the terms specified in the MIT-LICENSE file.
176
190
 
@@ -325,13 +325,14 @@ module ActiveRecord
325
325
  qo[:as] = (options[:ar_result] || options[:fetch] == :rows) ? :array : :hash
326
326
  end
327
327
  results = handle.each(query_options)
328
- options[:ar_result] ? ActiveRecord::Result.new(handle.fields, results) : results
328
+ columns = lowercase_schema_reflection ? handle.fields.map { |c| c.downcase } : handle.fields
329
+ options[:ar_result] ? ActiveRecord::Result.new(columns, results) : results
329
330
  end
330
331
 
331
332
  def handle_to_names_and_values_odbc(handle, options={})
332
333
  @connection.use_utc = ActiveRecord::Base.default_timezone == :utc
333
334
  if options[:ar_result]
334
- columns = handle.columns(true).map { |c| c.name }
335
+ columns = lowercase_schema_reflection ? handle.columns(true).map { |c| c.name.downcase } : handle.columns(true).map { |c| c.name }
335
336
  rows = handle.fetch_all || []
336
337
  ActiveRecord::Result.new(columns, rows)
337
338
  else
@@ -9,7 +9,7 @@ module ActiveRecord
9
9
 
10
10
  def tables(name = nil)
11
11
  info_schema_query do
12
- select_values "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE' AND TABLE_NAME <> 'dtproperties' AND TABLE_SCHEMA = schema_name()"
12
+ select_values "SELECT #{lowercase_schema_reflection_sql('TABLE_NAME')} FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE' AND TABLE_NAME <> 'dtproperties' AND TABLE_SCHEMA = schema_name()"
13
13
  end
14
14
  end
15
15
 
@@ -118,7 +118,7 @@ module ActiveRecord
118
118
 
119
119
  def views(name = nil)
120
120
  @sqlserver_views_cache ||=
121
- info_schema_query { select_values("SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME NOT IN ('sysconstraints','syssegments')") }
121
+ info_schema_query { select_values("SELECT #{lowercase_schema_reflection_sql('TABLE_NAME')} FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME NOT IN ('sysconstraints','syssegments')") }
122
122
  end
123
123
 
124
124
 
@@ -158,24 +158,24 @@ module ActiveRecord
158
158
  table_name = unqualify_table_name(table_name)
159
159
  sql = %{
160
160
  SELECT
161
- columns.TABLE_NAME as table_name,
162
- columns.COLUMN_NAME as name,
163
- columns.DATA_TYPE as type,
164
- columns.COLUMN_DEFAULT as default_value,
165
- columns.NUMERIC_SCALE as numeric_scale,
166
- columns.NUMERIC_PRECISION as numeric_precision,
161
+ #{lowercase_schema_reflection_sql('columns.TABLE_NAME')} AS table_name,
162
+ #{lowercase_schema_reflection_sql('columns.COLUMN_NAME')} AS name,
163
+ columns.DATA_TYPE AS type,
164
+ columns.COLUMN_DEFAULT AS default_value,
165
+ columns.NUMERIC_SCALE AS numeric_scale,
166
+ columns.NUMERIC_PRECISION AS numeric_precision,
167
167
  CASE
168
168
  WHEN columns.DATA_TYPE IN ('nchar','nvarchar') THEN columns.CHARACTER_MAXIMUM_LENGTH
169
169
  ELSE COL_LENGTH(columns.TABLE_SCHEMA+'.'+columns.TABLE_NAME, columns.COLUMN_NAME)
170
- END as length,
170
+ END AS length,
171
171
  CASE
172
172
  WHEN columns.IS_NULLABLE = 'YES' THEN 1
173
173
  ELSE NULL
174
- END as is_nullable,
174
+ END AS is_nullable,
175
175
  CASE
176
176
  WHEN COLUMNPROPERTY(OBJECT_ID(columns.TABLE_SCHEMA+'.'+columns.TABLE_NAME), columns.COLUMN_NAME, 'IsIdentity') = 0 THEN NULL
177
177
  ELSE 1
178
- END as is_identity
178
+ END AS is_identity
179
179
  FROM #{db_name_with_period}INFORMATION_SCHEMA.COLUMNS columns
180
180
  WHERE columns.TABLE_NAME = @0
181
181
  AND columns.TABLE_SCHEMA = #{table_schema.blank? ? "schema_name()" : "@1"}
@@ -279,6 +279,10 @@ module ActiveRecord
279
279
  column
280
280
  end
281
281
 
282
+ def lowercase_schema_reflection_sql(node)
283
+ lowercase_schema_reflection ? "LOWER(#{node})" : node
284
+ end
285
+
282
286
  # === SQLServer Specific (View Reflection) ====================== #
283
287
 
284
288
  def view_table_name(table_name)
@@ -313,14 +317,13 @@ module ActiveRecord
313
317
 
314
318
  def views_real_column_name(table_name,column_name)
315
319
  view_definition = view_information(table_name)[:VIEW_DEFINITION]
316
-
317
320
  match_data = view_definition.match(/([\w-]*)\s+as\s+#{column_name}/im)
318
321
  match_data ? match_data[1] : column_name
319
322
  end
320
323
 
321
324
  # === SQLServer Specific (Column/View Caches) =================== #
322
325
 
323
- def initialize_sqlserver_caches(reset_columns=true)
326
+ def initialize_sqlserver_caches
324
327
  @sqlserver_views_cache = nil
325
328
  @sqlserver_view_information_cache = {}
326
329
  @sqlserver_quoted_column_and_table_names = {}
@@ -161,16 +161,18 @@ module ActiveRecord
161
161
  include Sqlserver::Errors
162
162
 
163
163
  ADAPTER_NAME = 'SQLServer'.freeze
164
- VERSION = '3.1.0.rc1'.freeze
164
+ VERSION = '3.1.0.rc2'.freeze
165
165
  DATABASE_VERSION_REGEXP = /Microsoft SQL Server\s+"?(\d{4}|\w+)"?/
166
166
  SUPPORTED_VERSIONS = [2005,2008,2010,2011].freeze
167
167
 
168
- attr_reader :database_version, :database_year,
169
- :connection_supports_native_types
168
+ attr_reader :database_version, :database_year
170
169
 
171
170
  cattr_accessor :native_text_database_type, :native_binary_database_type, :native_string_database_type,
172
171
  :log_info_schema_queries, :enable_default_unicode_types, :auto_connect,
173
- :cs_equality_operator
172
+ :cs_equality_operator, :lowercase_schema_reflection
173
+
174
+ self.enable_default_unicode_types = true
175
+
174
176
 
175
177
  def initialize(logger,config)
176
178
  @connection_options = config
@@ -263,8 +265,7 @@ module ActiveRecord
263
265
  end
264
266
 
265
267
  def clear_cache!
266
- # This requires db admin perms and I'm not even sure it is a good idea.
267
- # raw_connection_do "DBCC FREEPROCCACHE WITH NO_INFOMSGS" rescue nil
268
+ initialize_sqlserver_caches
268
269
  end
269
270
 
270
271
  # === Abstract Adapter (Misc Support) =========================== #
@@ -35,6 +35,8 @@ module Arel
35
35
  table = Arel::Table.new(x.relation.table_alias || x.relation.name)
36
36
  expr = table[x.name]
37
37
  Arel::Nodes::Ordering.new expr
38
+ when Arel::Nodes::Ordering
39
+ x
38
40
  when String
39
41
  x.split(',').map do |s|
40
42
  expr, direction = s.split
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-sqlserver-adapter
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15424103
4
+ hash: 15424097
5
5
  prerelease: 6
6
6
  segments:
7
7
  - 3
8
8
  - 1
9
9
  - 0
10
10
  - rc
11
- - 1
12
- version: 3.1.0.rc1
11
+ - 2
12
+ version: 3.1.0.rc2
13
13
  platform: ruby
14
14
  authors:
15
15
  - Ken Collins
@@ -21,7 +21,7 @@ autorequire:
21
21
  bindir: bin
22
22
  cert_chain: []
23
23
 
24
- date: 2011-05-22 00:00:00 -04:00
24
+ date: 2011-05-31 00:00:00 -04:00
25
25
  default_executable:
26
26
  dependencies:
27
27
  - !ruby/object:Gem::Dependency
@@ -32,12 +32,14 @@ dependencies:
32
32
  requirements:
33
33
  - - ~>
34
34
  - !ruby/object:Gem::Version
35
- hash: 3
35
+ hash: 15424103
36
36
  segments:
37
37
  - 3
38
38
  - 1
39
39
  - 0
40
- version: 3.1.0
40
+ - rc
41
+ - 1
42
+ version: 3.1.0.rc1
41
43
  type: :runtime
42
44
  version_requirements: *id001
43
45
  description: SQL Server 2005 and 2008 Adapter For ActiveRecord