Module: ActiveRecord::ConnectionAdapters::MSSQL::DatabaseStatements

Included in:
ActiveRecord::ConnectionAdapters::MSSQLAdapter
Defined in:
lib/arjdbc/mssql/database_statements.rb

Instance Method Summary collapse

Instance Method Details

#exec_insert(sql, name = nil, binds = [], pk = nil, sequence_name = nil) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
# File 'lib/arjdbc/mssql/database_statements.rb', line 54

def exec_insert(sql, name = nil, binds = [], pk = nil, sequence_name = nil)
  table_name_for_identity_insert = identity_insert_table_name(sql)

  if table_name_for_identity_insert
    with_identity_insert_enabled(table_name_for_identity_insert) do
      super
    end
  else
    super
  end
end

#exec_proc(proc_name, *variables) ⇒ Object Also known as: execute_procedure



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/arjdbc/mssql/database_statements.rb', line 8

def exec_proc(proc_name, *variables)
  vars =
    if variables.any? && variables.first.is_a?(Hash)
      variables.first.map { |k, v| "@#{k} = #{quote(v)}" }
    else
      variables.map { |v| quote(v) }
    end.join(', ')
  sql = "EXEC #{proc_name} #{vars}".strip
  log(sql, 'Execute Procedure') do
    result = @connection.execute_query_raw(sql)
    result.map! do |row|
      row = row.is_a?(Hash) ? row.with_indifferent_access : row
      yield(row) if block_given?
      row
    end
    result
  end
end

#execute(sql, name = nil) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/arjdbc/mssql/database_statements.rb', line 37

def execute(sql, name = nil)
  # with identity insert on block
  if insert_sql?(sql)
    table_name_for_identity_insert = identity_insert_table_name(sql)

    if table_name_for_identity_insert
      with_identity_insert_enabled(table_name_for_identity_insert) do
        super
      end
    else
      super
    end
  else
    super
  end
end

#insert_fixtures_set(fixture_set, tables_to_delete = []) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/arjdbc/mssql/database_statements.rb', line 80

def insert_fixtures_set(fixture_set, tables_to_delete = [])
  fixture_inserts = []

  fixture_set.each do |table_name, fixtures|
    fixtures.each_slice(insert_rows_length) do |batch|
      fixture_inserts << build_fixture_sql(batch, table_name)
    end
  end

  table_deletes = tables_to_delete.map do |table|
    "DELETE FROM #{quote_table_name(table)}".dup
  end
  total_sql = Array.wrap(combine_multi_statements(table_deletes + fixture_inserts))

  disable_referential_integrity do
    transaction(requires_new: true) do
      total_sql.each do |sql|
        execute sql, 'Fixtures Load'
        yield if block_given?
      end
    end
  end
end

#supports_transaction_isolation_level?(level) ⇒ Boolean

Not a rails method, own method to test different isolation levels supported by the mssql adapter.

Returns:

  • (Boolean)


68
69
70
# File 'lib/arjdbc/mssql/database_statements.rb', line 68

def supports_transaction_isolation_level?(level)
  @connection.supports_transaction_isolation?(level)
end

#transaction_isolationObject



76
77
78
# File 'lib/arjdbc/mssql/database_statements.rb', line 76

def transaction_isolation
  @connection.get_transaction_isolation
end

#transaction_isolation=(value) ⇒ Object



72
73
74
# File 'lib/arjdbc/mssql/database_statements.rb', line 72

def transaction_isolation=(value)
  @connection.set_transaction_isolation(value)
end

#truncate(table_name, name = nil) ⇒ Object

Implements the truncate method.



105
106
107
# File 'lib/arjdbc/mssql/database_statements.rb', line 105

def truncate(table_name, name = nil)
  execute "TRUNCATE TABLE #{quote_table_name(table_name)}", name
end

#truncate_tables(*table_names) ⇒ Object

:nodoc:



109
110
111
112
113
114
115
116
117
# File 'lib/arjdbc/mssql/database_statements.rb', line 109

def truncate_tables(*table_names) # :nodoc:
  return if table_names.empty?

  disable_referential_integrity do
    table_names.each do |table_name|
      mssql_truncate(table_name)
    end
  end
end

#write_query?(sql) ⇒ Boolean

:nodoc:

Returns:

  • (Boolean)


33
34
35
# File 'lib/arjdbc/mssql/database_statements.rb', line 33

def write_query?(sql) # :nodoc:
  !READ_QUERY.match?(sql)
end