Module: Sequel::MSSQL::DatabaseMethods

Included in:
ADO::MSSQL::DatabaseMethods, JDBC::MSSQL::DatabaseMethods, ODBC::MSSQL::DatabaseMethods, TinyTDS::Database
Defined in:
lib/sequel/adapters/shared/mssql.rb

Constant Summary collapse

AUTO_INCREMENT =
'IDENTITY(1,1)'.freeze
SERVER_VERSION_RE =
/^(\d+)\.(\d+)\.(\d+)/.freeze
SERVER_VERSION_SQL =
"SELECT CAST(SERVERPROPERTY('ProductVersion') AS varchar)".freeze
SQL_BEGIN =
"BEGIN TRANSACTION".freeze
SQL_COMMIT =
"COMMIT TRANSACTION".freeze
SQL_ROLLBACK =
"IF @@TRANCOUNT > 0 ROLLBACK TRANSACTION".freeze
SQL_ROLLBACK_TO_SAVEPOINT =
'IF @@TRANCOUNT > 0 ROLLBACK TRANSACTION autopoint_%d'.freeze
SQL_SAVEPOINT =
'SAVE TRANSACTION autopoint_%d'.freeze
DECIMAL_TYPE_RE =

The types to check for 0 scale to transform :decimal types to :integer.

/number|numeric|decimal/io

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#mssql_unicode_stringsObject

Whether to use N” to quote strings, which allows unicode characters inside the strings. True by default for compatibility, can be set to false for a possible performance increase. This sets the default for all datasets created from this Database object.



20
21
22
# File 'lib/sequel/adapters/shared/mssql.rb', line 20

def mssql_unicode_strings
  @mssql_unicode_strings
end

Instance Method Details

#database_typeObject

Microsoft SQL Server uses the :mssql type.



27
28
29
# File 'lib/sequel/adapters/shared/mssql.rb', line 27

def database_type
  :mssql
end

#server_version(server = nil) ⇒ Object

The version of the MSSQL server, as an integer (e.g. 10001600 for SQL Server 2008 Express).



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/sequel/adapters/shared/mssql.rb', line 33

def server_version(server=nil)
  return @server_version if @server_version
  @server_version = synchronize(server) do |conn|
    (conn.server_version rescue nil) if conn.respond_to?(:server_version)
  end
  unless @server_version
    m = SERVER_VERSION_RE.match(fetch(SERVER_VERSION_SQL).single_value.to_s)
    @server_version = (m[1].to_i * 1000000) + (m[2].to_i * 10000) + m[3].to_i
  end
  @server_version
end

#supports_savepoints?Boolean

MSSQL supports savepoints, though it doesn’t support committing/releasing them savepoint

Returns:

  • (Boolean)


46
47
48
# File 'lib/sequel/adapters/shared/mssql.rb', line 46

def supports_savepoints?
  true
end

#supports_transaction_isolation_levels?Boolean

MSSQL supports transaction isolation levels

Returns:

  • (Boolean)


51
52
53
# File 'lib/sequel/adapters/shared/mssql.rb', line 51

def supports_transaction_isolation_levels?
  true
end

#tables(opts = {}) ⇒ Object

Microsoft SQL Server supports using the INFORMATION_SCHEMA to get information on tables.



57
58
59
# File 'lib/sequel/adapters/shared/mssql.rb', line 57

def tables(opts={})
  information_schema_tables('BASE TABLE', opts)
end

#views(opts = {}) ⇒ Object

Microsoft SQL Server supports using the INFORMATION_SCHEMA to get information on views.



63
64
65
# File 'lib/sequel/adapters/shared/mssql.rb', line 63

def views(opts={})
  information_schema_tables('VIEW', opts)
end