Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion activerecord-sqlserver-adapter.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'minitest-spec-rails'
spec.add_development_dependency 'mocha'
spec.add_development_dependency 'nokogiri'
spec.add_development_dependency 'pry'
spec.add_development_dependency 'pry-byebug'
spec.add_development_dependency 'rake'
end
18 changes: 18 additions & 0 deletions bin/console
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/sh
# Run a Ruby REPL.

set -e

cd $(dirname "$0")/..
PRY_PATH=$(which pry)
echo $PRY_PATH

if [ -x $PRY_PATH ]
then
exec bundle exec $PRY_PATH -Ilib -r activerecord-sqlserver-adapter -r console
else
red='\033[0;31m'
NC='\033[0m'
echo "${red}Pry was not found or not executable. Make sure \`which pry\` returns an executable.${NC}"

fi
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,22 @@ def case_sensitive_modifier(node, table_attribute)
Arel::Nodes::Bin.new(node)
end

def case_sensitive_comparison(table, attribute, column, value)
if column.case_sensitive?
table[attribute].eq(value)
else
super
end
end

def case_insensitive_comparison(table, attribute, column, value)
if column.case_sensitive?
super
else
table[attribute].eq(value)
end
end

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

# === SQLServer Specific ======================================== #

def execute_procedure(proc_name, *variables)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def indexes(table_name, name = nil)
def columns(table_name, _name = nil)
return [] if table_name.blank?
column_definitions(table_name).map do |ci|
sqlserver_options = ci.slice :ordinal_position, :is_primary, :is_identity, :default_function, :table_name
sqlserver_options = ci.slice :ordinal_position, :is_primary, :is_identity, :default_function, :table_name, :collation
cast_type = lookup_cast_type(ci[:type])
new_column ci[:name], ci[:default_value], cast_type, ci[:type], ci[:null], sqlserver_options
end
Expand Down Expand Up @@ -233,6 +233,7 @@ def column_definitions(table_name)
columns.NUMERIC_SCALE AS numeric_scale,
columns.NUMERIC_PRECISION AS numeric_precision,
columns.DATETIME_PRECISION AS datetime_precision,
columns.COLLATION_NAME AS collation,
columns.ordinal_position,
CASE
WHEN columns.DATA_TYPE IN ('nchar','nvarchar','char','varchar') THEN columns.CHARACTER_MAXIMUM_LENGTH
Expand Down
8 changes: 8 additions & 0 deletions lib/active_record/connection_adapters/sqlserver_column.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ def is_real?
@sql_type =~ /real/i
end

def collation
@sqlserver_options[:collation]
end

def case_sensitive?
collation && !collation.match(/_CI/)
end

end
end
end
3 changes: 3 additions & 0 deletions lib/console.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Pry.config.prompt = lambda do |context, nesting, pry|
"[sqlserver] #{context} > "
end