forked from rails-sqlserver/activerecord-sqlserver-adapter
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial 3.2 compatability. All tests green.
* Make use of the new ConnectionAdapters::SchemaCache for our needs. * New Sqlserver::Utils class for out helpers. Moved table name unquotes there.
- Loading branch information
1 parent
55aa57f
commit 7a18ff1
Showing
13 changed files
with
227 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,9 @@ | ||
|
||
* 3.2.0 * | ||
|
||
* | ||
|
||
|
||
* 3.1.5 * | ||
|
||
* Better support for orders with an expression. Fixes #155. [Jason Frey, Joe Rafaniello] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
lib/active_record/connection_adapters/sqlserver/schema_cache.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
module ActiveRecord | ||
module ConnectionAdapters | ||
module Sqlserver | ||
class SchemaCache < ActiveRecord::ConnectionAdapters::SchemaCache | ||
|
||
attr_reader :view_information | ||
|
||
def initialize(conn) | ||
super | ||
@table_names = nil | ||
@view_names = nil | ||
@view_information = {} | ||
@quoted_names = {} | ||
end | ||
|
||
# Superclass Overrides | ||
|
||
def table_exists?(table_name) | ||
return false if table_name.blank? | ||
key = table_name_key(table_name) | ||
return @tables[key] if @tables.key? key | ||
@tables[key] = connection.table_exists?(table_name) | ||
end | ||
|
||
def clear! | ||
super | ||
@table_names = nil | ||
@view_names = nil | ||
@view_information.clear | ||
@quoted_names.clear | ||
end | ||
|
||
def clear_table_cache!(table_name) | ||
key = table_name_key(table_name) | ||
super(key) | ||
super(table_name) | ||
# SQL Server Specific | ||
if @table_names | ||
@table_names.delete key | ||
@table_names.delete table_name | ||
end | ||
if @view_names | ||
@view_names.delete key | ||
@view_names.delete table_name | ||
end | ||
@view_information.delete key | ||
end | ||
|
||
# SQL Server Specific | ||
|
||
def table_names | ||
@table_names ||= connection.tables | ||
end | ||
|
||
def view_names | ||
@view_names ||= connection.views | ||
end | ||
|
||
def view_exists?(table_name) | ||
table_exists?(table_name) | ||
end | ||
|
||
def view_information(table_name) | ||
key = table_name_key(table_name) | ||
return @view_information[key] if @view_information.key? key | ||
@view_information[key] = connection.send(:view_information, table_name) | ||
end | ||
|
||
def quote_name(name) | ||
return @quoted_names[name] if @quoted_names.key? name | ||
@quoted_names[name] = name.to_s.split('.').map{ |n| n =~ /^\[.*\]$/ ? n : "[#{n.to_s.gsub(']', ']]')}]" }.join('.') | ||
end | ||
|
||
|
||
private | ||
|
||
def table_name_key(table_name) | ||
Utils.unqualify_table_name(table_name) | ||
end | ||
|
||
end | ||
end | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
module ActiveRecord | ||
module ConnectionAdapters | ||
module Sqlserver | ||
class Utils | ||
|
||
class << self | ||
|
||
def unqualify_table_name(table_name) | ||
table_name.to_s.split('.').last.tr('[]','') | ||
end | ||
|
||
def unqualify_table_schema(table_name) | ||
table_name.to_s.split('.')[-2].gsub(/[\[\]]/,'') rescue nil | ||
end | ||
|
||
def unqualify_db_name(table_name) | ||
table_names = table_name.to_s.split('.') | ||
table_names.length == 3 ? table_names.first.tr('[]','') : nil | ||
end | ||
|
||
end | ||
|
||
end | ||
end | ||
end | ||
end | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.