Skip to content
Browse files

Tons of bug fixes.

* Fix exists? with offset by patching visitor. Fixes #171 and Fixes #167
* Set default text size to 2147483647 for TinyTDS connections. Fixes #181
* Set @config ivar for 3rd party libs. Fixes #177
* Strengthen #query_requires_identity_insert? by looking for VALUES at the end. Fixes #178
* Make #sql_type_for_statement work for integers that may have empty parens or none at all. Fixes #175
  • Loading branch information...
1 parent c551ffe commit 13e6fb314b45d33e756ee76d08e1ac4e36256f9b @metaskills metaskills committed
View
13 CHANGELOG
@@ -1,4 +1,17 @@
+* 3.1.7 *
+
+* Fix exists? with offset by patching visitor. Fixes #171 and Fixes #167
+
+* Set default text size to 2147483647 for TinyTDS connections. Fixes #181
+
+* Set @config ivar for 3rd party libs. Fixes #177
+
+* Strengthen #query_requires_identity_insert? by looking for VALUES at the end. Fixes #178
+
+* Make #sql_type_for_statement work for integers that may have empty parens or none at all. Fixes #175
+
+
* 3.1.6 *
* Add explicit order-by clause for windowed results. Fixes #161.
View
2 lib/active_record/connection_adapters/sqlserver/schema_statements.rb
@@ -372,7 +372,7 @@ def query_requires_identity_insert?(sql)
if insert_sql?(sql)
table_name = get_table_name(sql)
id_column = identity_column(table_name)
- id_column && sql =~ /^\s*(INSERT|EXEC sp_executesql N'INSERT)[^(]+\([^)]*\b(#{id_column.name})\b,?[^)]*\)/i ? quote_table_name(table_name) : false
+ id_column && sql =~ /^\s*(INSERT|EXEC sp_executesql N'INSERT)[^(]+\([^)]*\b(#{id_column.name})\b,?[^)]*\).*?VALUES/i ? quote_table_name(table_name) : false
else
false
end
View
4 lib/active_record/connection_adapters/sqlserver_adapter.rb
@@ -91,7 +91,7 @@ def is_real?
def sql_type_for_statement
if is_integer? || is_real?
- sql_type.sub(/\(\d+\)/,'')
+ sql_type.sub(/\((\d+)?\)/,'')
else
sql_type
end
@@ -197,6 +197,7 @@ def initialize(logger,config)
@connection_options = config
connect
super(@connection, logger)
+ @config = config
@database_version = info_schema_query { select_value('SELECT @@version') }
@database_year = begin
if @database_version =~ /Microsoft SQL Azure/i
@@ -423,6 +424,7 @@ def connect
client.execute("SET CURSOR_CLOSE_ON_COMMIT OFF").do
client.execute("SET IMPLICIT_TRANSACTIONS OFF").do
end
+ client.execute("SET TEXTSIZE 2147483647").do
end
when :odbc
if config[:dsn].include?(';')
View
2 lib/arel/visitors/sqlserver.rb
@@ -155,7 +155,7 @@ def visit_Arel_Nodes_SelectStatementWithOutOffset(o, windowed=false)
end
[ ("SELECT" if !windowed),
(visit(o.limit) if o.limit && !windowed),
- (projections.map{ |x| visit(x) }.join(', ')),
+ (projections.map{ |x| v = visit(x); v == "1" ? "1 AS [__wrp]" : v }.join(', ')),
(source_with_lock_for_select_statement(o)),
("WHERE #{core.wheres.map{ |x| visit(x) }.join ' AND ' }" unless core.wheres.empty?),
("GROUP BY #{groups.map { |x| visit x }.join ', ' }" unless groups.empty?),
View
6 test/cases/offset_and_limit_test_sqlserver.rb
@@ -20,9 +20,13 @@ class OffsetAndLimitTestSqlserver < ActiveRecord::TestCase
context 'When selecting with offset' do
- should 'have limit (top) of 2147483647 if only offset is passed' do
+ should 'have limit (top) of 9223372036854775807 if only offset is passed' do
assert_sql(/SELECT TOP \(9223372036854775807\) \[__rnt\]\.\* FROM.*WHERE \[__rnt\]\.\[__rn\] > \(1\)/) { Book.all(:offset=>1) }
end
+
+ should 'support calling exists?' do
+ assert Book.offset(3).exists?
+ end
end

0 comments on commit 13e6fb3

Please sign in to comment.
Something went wrong with that request. Please try again.