Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ else
require "yaml"

spec = eval(File.read("activerecord-sqlserver-adapter.gemspec"))
ver = spec.dependencies.detect{ |d|d.name == "activerecord" }.requirement.requirements.first.last.version
ver = spec.dependencies.detect { |d| d.name == "activerecord" }.requirement.requirements.first.last.version
major, minor, tiny, pre = ver.split(".")

if pre
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def calculate(operation, column_name)
if operation.to_s.downcase == "count"
unless distinct_value || distinct_select?(column_name || select_for_count)
relation.distinct!
relation.select_values = [ klass.primary_key || table[Arel.star] ]
relation.select_values = [klass.primary_key || table[Arel.star]]
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def build_insert_sql(insert) # :nodoc:
sql = +"INSERT #{insert.into}"

if returning = insert.send(:insert_all).returning
sql << " OUTPUT " << returning.map {|column| "INSERTED.#{quote_column_name(column)}" }.join(", ")
sql << " OUTPUT " << returning.map { |column| "INSERTED.#{quote_column_name(column)}" }.join(", ")
end

sql << " #{insert.values_list}"
Expand Down Expand Up @@ -198,7 +198,7 @@ def user_options
if row.instance_of? Hash
set_option = row.values[0].gsub(/\s+/, "_")
user_value = row.values[1]
elsif row.instance_of? Array
elsif row.instance_of? Array
set_option = row[0].gsub(/\s+/, "_")
user_value = row[1]
end
Expand Down Expand Up @@ -341,7 +341,7 @@ def sp_executesql_sql(sql, types, params, name)
end
else
types = quote(types.join(", "))
params = params.map.with_index{ |p, i| "@#{i} = #{p}" }.join(", ") # Only p is needed, but with @i helps explain regexp.
params = params.map.with_index { |p, i| "@#{i} = #{p}" }.join(", ") # Only p is needed, but with @i helps explain regexp.
sql = "EXEC sp_executesql #{quote(sql)}"
sql += ", #{types}, #{params}" unless params.empty?
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,20 @@ def collation

private

def create_database_options(options={})
def create_database_options(options = {})
keys = [:collate]
copts = @connection_options
options = {
collate: copts[:collation]
}.merge(options.symbolize_keys).select { |_, v|
v.present?
}.slice(*keys).map { |k,v|
}.slice(*keys).map { |k, v|
"#{k.to_s.upcase} #{v}"
}.join(" ")
options
end

def create_database_edition_options(options={})
def create_database_edition_options(options = {})
keys = [:maxsize, :edition, :service_objective]
copts = @connection_options
edition_options = {
Expand All @@ -53,7 +53,7 @@ def create_database_edition_options(options={})
service_objective: copts[:azure_service_objective]
}.merge(options.symbolize_keys).select { |_, v|
v.present?
}.slice(*keys).map { |k,v|
}.slice(*keys).map { |k, v|
"#{k.to_s.upcase} = #{v}"
}.join(", ")
edition_options = "( #{edition_options} )" if edition_options.present?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ def type_to_sql(type, limit: nil, precision: nil, scale: nil, **)
end

def columns_for_distinct(columns, orders)
order_columns = orders.reject(&:blank?).map{ |s|
order_columns = orders.reject(&:blank?).map { |s|
s = s.to_sql unless s.is_a?(String)
s.gsub(/\s+(?:ASC|DESC)\b/i, "")
.gsub(/\s+NULLS\s+(?:FIRST|LAST)\b/i, "")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def quote_fractional(value)
return 0 if fractional_scale == 0
frac_seconds = seconds_precision(value)
seconds = (frac_seconds.to_f / fractional_operator.to_f).round(fractional_scale)
seconds.to_d.to_s.split(".").last.to(fractional_scale-1)
seconds.to_d.to_s.split(".").last.to(fractional_scale - 1)
end

def fractional_property
Expand All @@ -35,7 +35,7 @@ def fractional_digits
end

def fractional_operator
10 ** fractional_digits
10**fractional_digits
end

def fractional_precision
Expand Down
2 changes: 1 addition & 1 deletion lib/active_record/connection_adapters/sqlserver/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def to_s
end

def quoted
parts.map{ |p| quote(p) if p }.join SEPARATOR
parts.map { |p| quote(p) if p }.join SEPARATOR
end

def quoted_raw
Expand Down
10 changes: 5 additions & 5 deletions lib/active_record/connection_adapters/sqlserver_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ def get_database_version # :nodoc:
# === Abstract Adapter (Misc Support) =========================== #

def initialize_type_map(m = type_map)
m.register_type %r{.*}, SQLServer::Type::UnicodeString.new
m.register_type %r{.*}, SQLServer::Type::UnicodeString.new
# Exact Numerics
register_class_with_limit m, "bigint(8)", SQLServer::Type::BigInteger
m.alias_type "bigint", "bigint(8)"
Expand Down Expand Up @@ -326,11 +326,11 @@ def initialize_type_map(m = type_map)
SQLServer::Type::DateTime.new
end
end
m.register_type %r{\Adatetimeoffset}i do |sql_type|
m.register_type %r{\Adatetimeoffset}i do |sql_type|
precision = extract_precision(sql_type)
SQLServer::Type::DateTimeOffset.new precision: precision
end
m.register_type "smalldatetime", SQLServer::Type::SmallDateTime.new
m.register_type "smalldatetime", SQLServer::Type::SmallDateTime.new
m.register_type %r{\Atime}i do |sql_type|
precision = extract_precision(sql_type) || DEFAULT_TIME_PRECISION
SQLServer::Type::Time.new precision: precision
Expand Down Expand Up @@ -456,9 +456,9 @@ def config_encoding(config)
config[:encoding].present? ? config[:encoding] : nil
end

def configure_connection ; end
def configure_connection; end

def configure_application_name ; end
def configure_application_name; end

def initialize_dateformatter
@database_dateformat = user_options_dateformat
Expand Down
4 changes: 2 additions & 2 deletions lib/arel/visitors/sqlserver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class SQLServer < Arel::Visitors::ToSql
# SQLServer ToSql/Visitor (Overides)

def visit_Arel_Nodes_BindParam o, collector
collector.add_bind(o.value) { |i| "@#{i-1}" }
collector.add_bind(o.value) { |i| "@#{i - 1}" }
end

def visit_Arel_Nodes_Bin o, collector
Expand Down Expand Up @@ -70,7 +70,7 @@ def visit_Arel_Nodes_SelectStatement o, collector
collector = visit o.with, collector
collector << " "
end
collector = o.cores.inject(collector) { |c,x|
collector = o.cores.inject(collector) { |c, x|
visit_Arel_Nodes_SelectCore(x, c)
}
collector = visit_Orders_And_Let_Fetch_Happen o, collector
Expand Down
36 changes: 18 additions & 18 deletions test/cases/adapter_test_sqlserver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ class AdapterTestSQLServer < ActiveRecord::TestCase
end

it "return true to insert sql query for inserts only" do
assert connection.send(:insert_sql?,"INSERT...")
assert connection.send(:insert_sql?, "INSERT...")
assert connection.send(:insert_sql?, "EXEC sp_executesql N'INSERT INTO [fk_test_has_fks] ([fk_id]) VALUES (@0); SELECT CAST(SCOPE_IDENTITY() AS bigint) AS Ident', N'@0 int', @0 = 0")
assert !connection.send(:insert_sql?,"UPDATE...")
assert !connection.send(:insert_sql?,"SELECT...")
assert !connection.send(:insert_sql?, "UPDATE...")
assert !connection.send(:insert_sql?, "SELECT...")
end

it "return unquoted table name object from basic INSERT UPDATE and SELECT statements" do
Expand Down Expand Up @@ -155,17 +155,17 @@ class AdapterTestSQLServer < ActiveRecord::TestCase
end

it "return quoted table_name to #query_requires_identity_insert? when INSERT sql contains id column" do
assert_equal "funny_jokes", connection.send(:query_requires_identity_insert?,@identity_insert_sql)
assert_equal "funny_jokes", connection.send(:query_requires_identity_insert?,@identity_insert_sql_unquoted)
assert_equal "funny_jokes", connection.send(:query_requires_identity_insert?,@identity_insert_sql_unordered)
assert_equal "funny_jokes", connection.send(:query_requires_identity_insert?,@identity_insert_sql_sp)
assert_equal "funny_jokes", connection.send(:query_requires_identity_insert?,@identity_insert_sql_unquoted_sp)
assert_equal "funny_jokes", connection.send(:query_requires_identity_insert?,@identity_insert_sql_unordered_sp)
assert_equal "funny_jokes", connection.send(:query_requires_identity_insert?, @identity_insert_sql)
assert_equal "funny_jokes", connection.send(:query_requires_identity_insert?, @identity_insert_sql_unquoted)
assert_equal "funny_jokes", connection.send(:query_requires_identity_insert?, @identity_insert_sql_unordered)
assert_equal "funny_jokes", connection.send(:query_requires_identity_insert?, @identity_insert_sql_sp)
assert_equal "funny_jokes", connection.send(:query_requires_identity_insert?, @identity_insert_sql_unquoted_sp)
assert_equal "funny_jokes", connection.send(:query_requires_identity_insert?, @identity_insert_sql_unordered_sp)
end

it "return false to #query_requires_identity_insert? for normal SQL" do
[basic_insert_sql, basic_update_sql, basic_select_sql].each do |sql|
assert !connection.send(:query_requires_identity_insert?,sql), "SQL was #{sql}"
assert !connection.send(:query_requires_identity_insert?, sql), "SQL was #{sql}"
end
end

Expand Down Expand Up @@ -227,7 +227,7 @@ class AdapterTestSQLServer < ActiveRecord::TestCase
end

it "NOT ALLOW by default the deletion of a referenced parent" do
SSTestHasPk.connection.disable_referential_integrity { }
SSTestHasPk.connection.disable_referential_integrity {}
assert_raise(ActiveRecord::StatementInvalid) { @parent.destroy }
end

Expand All @@ -237,7 +237,7 @@ class AdapterTestSQLServer < ActiveRecord::TestCase

it "again NOT ALLOW deletion of referenced parent after #disable_referential_integrity block" do
assert_raise(ActiveRecord::StatementInvalid) do
SSTestHasPk.connection.disable_referential_integrity { }
SSTestHasPk.connection.disable_referential_integrity {}
@parent.destroy
end
end
Expand Down Expand Up @@ -318,27 +318,27 @@ class AdapterTestSQLServer < ActiveRecord::TestCase
end

it "not contain system views" do
systables = ["sysconstraints","syssegments"]
systables = ["sysconstraints", "syssegments"]
systables.each do |systable|
assert !connection.views.include?(systable), "This systable #{systable} should not be in the views array."
end
end

it "allow the connection#view_information method to return meta data on the view" do
view_info = connection.send(:view_information,"sst_customers_view")
view_info = connection.send(:view_information, "sst_customers_view")
assert_equal("sst_customers_view", view_info["TABLE_NAME"])
assert_match(/CREATE VIEW sst_customers_view/, view_info["VIEW_DEFINITION"])
end

it "allow the connection#view_table_name method to return true table_name for the view" do
assert_equal "customers", connection.send(:view_table_name,"sst_customers_view")
assert_equal "topics", connection.send(:view_table_name,"topics"), "No view here, the same table name should come back."
assert_equal "customers", connection.send(:view_table_name, "sst_customers_view")
assert_equal "topics", connection.send(:view_table_name, "topics"), "No view here, the same table name should come back."
end

# With same column names

it "have matching column objects" do
columns = ["id","name","balance"]
columns = ["id", "name", "balance"]
assert !SSTestCustomersView.columns.blank?
assert_equal columns.size, SSTestCustomersView.columns.size
columns.each do |colname|
Expand All @@ -365,7 +365,7 @@ class AdapterTestSQLServer < ActiveRecord::TestCase
# With aliased column names

it "have matching column objects" do
columns = ["id","pretend_null"]
columns = ["id", "pretend_null"]
assert !SSTestStringDefaultsView.columns.blank?
assert_equal columns.size, SSTestStringDefaultsView.columns.size
columns.each do |colname|
Expand Down
10 changes: 5 additions & 5 deletions test/cases/coerced_tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -329,14 +329,14 @@ class QuoteARBaseTest < ActiveRecord::TestCase
coerce_tests! :test_quote_ar_object
def test_quote_ar_object_coerced
value = DatetimePrimaryKey.new(id: @time)
assert_equal "'02-14-2017 12:34:56.79'", @connection.quote(value)
assert_equal "'02-14-2017 12:34:56.79'", @connection.quote(value)
end

# Use our date format.
coerce_tests! :test_type_cast_ar_object
def test_type_cast_ar_object_coerced
value = DatetimePrimaryKey.new(id: @time)
assert_equal "02-14-2017 12:34:56.79", @connection.type_cast(value)
assert_equal "02-14-2017 12:34:56.79", @connection.type_cast(value)
end
end
end
Expand Down Expand Up @@ -883,7 +883,7 @@ def test_query_cached_even_when_types_are_reset_coerced
Task.find(1)
end

assert_includes ActiveRecord::SQLCounter.log_all.first , "TC.CONSTRAINT_TYPE = N''PRIMARY KEY''"
assert_includes ActiveRecord::SQLCounter.log_all.first, "TC.CONSTRAINT_TYPE = N''PRIMARY KEY''"
end
end
end
Expand Down Expand Up @@ -986,7 +986,7 @@ def self.search_as_method(term)
where("title LIKE ?", sanitize_sql_like(term, "!"))
end

scope :search_as_scope, -> (term) {
scope :search_as_scope, ->(term) {
where("title LIKE ?", sanitize_sql_like(term, "!"))
}
end
Expand Down Expand Up @@ -1121,7 +1121,7 @@ def test_invalid_datetime_precision_raises_error_coerced
coerce_tests! :test_datetime_precision_is_truncated_on_assignment
def test_datetime_precision_is_truncated_on_assignment_coerced
@connection.create_table(:foos, force: true)
@connection.add_column :foos, :created_at, :datetime, precision: 0
@connection.add_column :foos, :created_at, :datetime, precision: 0
@connection.add_column :foos, :updated_at, :datetime, precision: 6

time = ::Time.now.change(nsec: 123456789)
Expand Down
Loading