class Purview::Databases::MSSQL

Private Instance Methods

connection_type() click to toggle source
# File lib/purview/databases/mssql.rb, line 6
def connection_type
  Purview::Connections::MSSQL
end
create_index_sql(table_name, index_name, index, index_opts={}) click to toggle source
# File lib/purview/databases/mssql.rb, line 10
def create_index_sql(table_name, index_name, index, index_opts={})
  'CREATE%sINDEX %s ON %s (%s)' % [
    index.unique? ? ' UNIQUE ' : ' ',
    index_name,
    table_name,
    column_names(index).join(', '),
  ]
end
create_table_sql(table_name, table, table_opts={}) click to toggle source
# File lib/purview/databases/mssql.rb, line 19
def create_table_sql(table_name, table, table_opts={})
  'CREATE TABLE %s (%s)' % [
    table_name,
    column_definitions(table).join(', '),
  ]
end
create_temporary_table_sql(table_name, table, table_opts={}) click to toggle source
# File lib/purview/databases/mssql.rb, line 26
def create_temporary_table_sql(table_name, table, table_opts={})
  'CREATE TEMPORARY TABLE %s (%s)' % [
    table_name,
    column_definitions(table).join(', '),
  ]
end
dialect_type() click to toggle source
# File lib/purview/databases/mssql.rb, line 33
def dialect_type
  Purview::Dialects::MSSQL
end
disable_table_sql(table) click to toggle source
# File lib/purview/databases/mssql.rb, line 37
def disable_table_sql(table)
  'UPDATE %s SET %s = %s, %s = %s WHERE %s = %s AND %s IS NOT NULL' % [
    table_metadata_table.name,
    table_metadata_table.enabled_at_column.name,
    null_value,
    table_metadata_table.last_updated_at_column.name,
    quoted(Time.now),
    table_metadata_table.table_name_column.name,
    quoted(table.name),
    table_metadata_table.enabled_at_column.name,
  ]
end
drop_index_sql(table_name, index_name, index, index_opts={}) click to toggle source
# File lib/purview/databases/mssql.rb, line 50
def drop_index_sql(table_name, index_name, index, index_opts={})
  'DROP INDEX %s' % [
    index_name,
  ]
end
drop_table_sql(table_name, table, table_opts={}) click to toggle source
# File lib/purview/databases/mssql.rb, line 56
def drop_table_sql(table_name, table, table_opts={})
  'DROP TABLE %s' % [
    table_name,
  ]
end
enable_table_sql(table, timestamp) click to toggle source
# File lib/purview/databases/mssql.rb, line 62
def enable_table_sql(table, timestamp)
  'UPDATE %s SET %s = %s, %s = %s WHERE %s = %s AND %s IS NULL' % [
    table_metadata_table.name,
    table_metadata_table.enabled_at_column.name,
    quoted(timestamp),
    table_metadata_table.last_updated_at_column.name,
    quoted(Time.now),
    table_metadata_table.table_name_column.name,
    quoted(table.name),
    table_metadata_table.enabled_at_column.name,
  ]
end
ensure_table_metadata_absent_for_table_sql(table) click to toggle source
# File lib/purview/databases/mssql.rb, line 75
def ensure_table_metadata_absent_for_table_sql(table)
  'DELETE FROM %s WHERE %s = %s' % [
    table_metadata_table.name,
    table_metadata_table.table_name_column.name,
    quoted(table.name),
  ]
end
ensure_table_metadata_exists_for_table_sql(table) click to toggle source
# File lib/purview/databases/mssql.rb, line 83
def ensure_table_metadata_exists_for_table_sql(table)
  'INSERT INTO %s (%s) SELECT %s WHERE NOT EXISTS (SELECT 1 FROM %s WHERE %s = %s)' % [
    table_metadata_table.name,
    table_metadata_table.table_name_column.name,
    quoted(table.name),
    table_metadata_table.name,
    table_metadata_table.table_name_column.name,
    quoted(table.name),
  ]
end
ensure_table_metadata_table_exists_sql() click to toggle source
# File lib/purview/databases/mssql.rb, line 94
def ensure_table_metadata_table_exists_sql
  'CREATE TABLE IF NOT EXISTS %s (%s)' % [
    table_metadata_table.name,
    column_definitions(table_metadata_table).join(', '),
  ]
end
get_table_metadata_value_sql(table, column) click to toggle source
# File lib/purview/databases/mssql.rb, line 114
def get_table_metadata_value_sql(table, column)
  'SELECT %s FROM %s WHERE %s = %s' % [
    column.name,
    table_metadata_table.name,
    table_metadata_table.table_name_column.name,
    quoted(table.name),
  ]
end
initialize_table_sql(table, timestamp) click to toggle source
# File lib/purview/databases/mssql.rb, line 101
def initialize_table_sql(table, timestamp)
  'UPDATE %s SET %s = %s, %s = %s WHERE %s = %s AND %s IS NULL' % [
    table_metadata_table.name,
    table_metadata_table.max_timestamp_pulled_column.name,
    quoted(timestamp),
    table_metadata_table.last_updated_at_column.name,
    quoted(Time.now),
    table_metadata_table.table_name_column.name,
    quoted(table.name),
    table_metadata_table.max_timestamp_pulled_column.name,
  ]
end
limit_map() click to toggle source
Calls superclass method Purview::Databases::Base#limit_map
# File lib/purview/databases/mssql.rb, line 123
def limit_map
  super.merge(Purview::Types::String => 255)
end
limitless_types() click to toggle source
# File lib/purview/databases/mssql.rb, line 127
def limitless_types
  super + [
    Purview::Types::Money,
    Purview::Types::UUID,
  ]
end
lock_table_sql(table, timestamp) click to toggle source
# File lib/purview/databases/mssql.rb, line 134
def lock_table_sql(table, timestamp)
  'UPDATE %s SET %s = %s, %s = %s WHERE %s = %s AND %s IS NULL' % [
    table_metadata_table.name,
    table_metadata_table.locked_at_column.name,
    quoted(timestamp),
    table_metadata_table.last_updated_at_column.name,
    quoted(Time.now),
    table_metadata_table.table_name_column.name,
    quoted(table.name),
    table_metadata_table.locked_at_column.name,
  ]
end
next_table_sql(timestamp) click to toggle source
# File lib/purview/databases/mssql.rb, line 147
def next_table_sql(timestamp)
  'SELECT TOP 1 %s FROM %s WHERE %s IS NOT NULL AND %s IS NOT NULL AND %s IS NULL ORDER BY (CASE WHEN %s IS NULL THEN 0 ELSE 1 END), %s' % [
    table_metadata_table.table_name_column.name,
    table_metadata_table.name,
    table_metadata_table.enabled_at_column.name,
    table_metadata_table.max_timestamp_pulled_column.name,
    table_metadata_table.locked_at_column.name,
    table_metadata_table.last_pulled_at_column.name,
    table_metadata_table.last_pulled_at_column.name,
  ]
end
set_table_metadata_value_sql(table, column, value) click to toggle source
# File lib/purview/databases/mssql.rb, line 159
def set_table_metadata_value_sql(table, column, value)
  'UPDATE %s SET %s = %s, %s = %s WHERE %s = %s' % [
    table_metadata_table.name,
    column.name,
    quoted(value),
    table_metadata_table.last_updated_at_column.name,
    quoted(Time.now),
    table_metadata_table.table_name_column.name,
    quoted(table.name),
  ]
end
type_map() click to toggle source
Calls superclass method Purview::Databases::Base#type_map
# File lib/purview/databases/mssql.rb, line 171
def type_map
  super.merge(
    Purview::Types::Money => 'money',
    Purview::Types::UUID => 'uniqueidentifier',
  )
end
unlock_table_sql(table) click to toggle source
# File lib/purview/databases/mssql.rb, line 178
def unlock_table_sql(table)
  'UPDATE %s SET %s = %s, %s = %s WHERE %s = %s AND %s IS NOT NULL' % [
    table_metadata_table.name,
    table_metadata_table.locked_at_column.name,
    null_value,
    table_metadata_table.last_updated_at_column.name,
    quoted(Time.now),
    table_metadata_table.table_name_column.name,
    quoted(table.name),
    table_metadata_table.locked_at_column.name,
  ]
end