Skip to content

Commit 9d07027

Browse files
committed
Standardrb
1 parent 4b9ae57 commit 9d07027

File tree

15 files changed

+31
-37
lines changed

15 files changed

+31
-37
lines changed

lib/active_record/connection_adapters/sqlserver/database_statements.rb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ def write_query?(sql) # :nodoc:
1414
end
1515

1616
def perform_query(raw_connection, sql, binds, type_casted_binds, prepare:, notification_payload:, batch:)
17-
result, affected_rows = if id_insert_table_name = query_requires_identity_insert?(sql)
17+
id_insert_table_name = query_requires_identity_insert?(sql)
18+
19+
result, affected_rows = if id_insert_table_name
1820
# If the table name is a view, we need to get the base table name for enabling identity insert.
1921
id_insert_table_name = view_table_name(id_insert_table_name) if view_exists?(id_insert_table_name)
2022

@@ -46,11 +48,7 @@ def affected_rows(raw_result)
4648

4749
# Returns the affected rows from results or handle.
4850
def affected_rows_from_results_or_handle(raw_result, handle)
49-
if affected_rows_from_result = affected_rows(raw_result)
50-
affected_rows_from_result
51-
else
52-
handle.affected_rows
53-
end
51+
affected_rows(raw_result) || handle.affected_rows
5452
end
5553

5654
def raw_execute(sql, name = nil, binds = [], prepare: false, async: false, allow_retry: false, materialize_transactions: true, batch: false)
@@ -157,7 +155,9 @@ def default_insert_value(column)
157155
def build_insert_sql(insert) # :nodoc:
158156
sql = "INSERT #{insert.into}"
159157

160-
if returning = insert.send(:insert_all).returning
158+
returning = insert.send(:insert_all).returning
159+
160+
if returning
161161
returning_sql = if returning.is_a?(String)
162162
returning
163163
else
@@ -317,7 +317,7 @@ def sql_for_insert(sql, pk, binds, returning)
317317

318318
def set_identity_insert(table_name, conn, enable)
319319
internal_raw_execute("SET IDENTITY_INSERT #{table_name} #{enable ? "ON" : "OFF"}", conn, perform_do: true)
320-
rescue Exception
320+
rescue
321321
raise ActiveRecordError, "IDENTITY_INSERT could not be turned #{enable ? "ON" : "OFF"} for table #{table_name}"
322322
end
323323

@@ -456,7 +456,7 @@ def handle_to_names_and_values(handle, options = {})
456456
end
457457

458458
def finish_statement_handle(handle)
459-
handle.cancel if handle
459+
handle&.cancel
460460
handle
461461
end
462462

lib/active_record/connection_adapters/sqlserver/schema_statements.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@ def column_type(ci:)
592592
when /^numeric|decimal$/i
593593
"#{ci["type"]}(#{ci["numeric_precision"]},#{ci["numeric_scale"]})"
594594
when /^float|real$/i
595-
"#{ci["type"]}"
595+
ci["type"]
596596
when /^char|nchar|varchar|nvarchar|binary|varbinary|bigint|int|smallint$/
597597
(ci["length"].to_i == -1) ? "#{ci["type"]}(max)" : "#{ci["type"]}(#{ci["length"]})"
598598
else

lib/active_record/connection_adapters/sqlserver/showplan.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def with_showplan_on
3232
def set_showplan_option(enable = true)
3333
sql = "SET #{showplan_option} #{enable ? "ON" : "OFF"}"
3434
raw_execute(sql, "SCHEMA")
35-
rescue Exception
35+
rescue
3636
raise ActiveRecordError, "#{showplan_option} could not be turned #{enable ? "ON" : "OFF"}, perhaps you do not have SHOWPLAN permissions?"
3737
end
3838

lib/active_record/connection_adapters/sqlserver/type/smalldatetime.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def fast_string_to_time_format
2020
end
2121

2222
def apply_seconds_precision(value)
23-
value.change usec: 0 if value
23+
value&.change(usec: 0)
2424
end
2525
end
2626
end

lib/active_record/connection_adapters/sqlserver/type/time.rb

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,12 @@ module Type
77
class Time < ActiveRecord::Type::Time
88
include TimeValueFractional2
99

10-
def serialize(value)
10+
def serialize(_value)
1111
value = super
1212
return value unless value.acts_like?(:time)
1313

1414
time = "#{value.to_formatted_s(:_sqlserver_time)}.#{quote_fractional(value)}"
15-
16-
Data.new time, self
15+
Data.new(time, self)
1716
end
1817

1918
def deserialize(value)
@@ -34,9 +33,8 @@ def quoted(value)
3433

3534
private
3635

37-
def cast_value(value)
36+
def cast_value(_value)
3837
value = super
39-
4038
return value unless value.is_a?(::Time)
4139

4240
value = value.change(year: 2000, month: 0o1, day: 0o1)

lib/active_record/connection_adapters/sqlserver/type/uuid.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ module Type
77
class Uuid < String
88
ACCEPTABLE_UUID = %r{\A\{?([a-fA-F0-9]{4}-?){8}\}?\z}x
99

10-
alias_method :serialize, :deserialize
11-
1210
def type
1311
:uuid
1412
end

lib/active_record/connection_adapters/sqlserver/utils.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def quote(part)
113113
end
114114

115115
def unquote(part)
116-
if part && part.start_with?("[")
116+
if part&.start_with?("[")
117117
part[1..-2]
118118
else
119119
part

lib/active_record/connection_adapters/sqlserver_adapter.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ def dbconsole(config, options = {})
6767
sqlserver_config = config.configuration_hash
6868
args = []
6969

70-
args += ["-d", "#{config.database}"] if config.database
71-
args += ["-U", "#{sqlserver_config[:username]}"] if sqlserver_config[:username]
72-
args += ["-P", "#{sqlserver_config[:password]}"] if sqlserver_config[:password]
70+
args += ["-d", config.database.to_s] if config.database
71+
args += ["-U", sqlserver_config[:username].to_s] if sqlserver_config[:username]
72+
args += ["-P", sqlserver_config[:password].to_s] if sqlserver_config[:password]
7373

7474
if sqlserver_config[:host]
7575
host_arg = "tcp:#{sqlserver_config[:host]}"

lib/active_record/connection_adapters/sqlserver_column.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def is_utf8?
2828
end
2929

3030
def case_sensitive?
31-
collation && collation.match(/_CS/)
31+
collation&.match(/_CS/)
3232
end
3333

3434
def init_with(coder)

lib/arel/visitors/sqlserver.rb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,11 @@ def visit_Arel_Nodes_Offset(o, collector)
125125
def visit_Arel_Nodes_Limit(o, collector)
126126
if node_value(o) == 0
127127
collector << FETCH0
128-
collector << ROWS_ONLY
129128
else
130129
collector << FETCH
131130
visit o.expr, collector
132-
collector << ROWS_ONLY
133131
end
132+
collector << ROWS_ONLY
134133
end
135134

136135
def visit_Arel_Nodes_Grouping(o, collector)
@@ -208,7 +207,7 @@ def visit_Arel_Table(o, collector)
208207
quote_table_name(o.name)
209208
end
210209
end
211-
rescue Exception
210+
rescue
212211
quote_table_name(o.name)
213212
end
214213

@@ -335,7 +334,7 @@ def node_value(node)
335334
end
336335

337336
def select_statement_lock?
338-
@select_statement && @select_statement.lock
337+
@select_statement&.lock
339338
end
340339

341340
def make_Fetch_Possible_And_Deterministic(o)

0 commit comments

Comments
 (0)