Skip to content

Commit aecca5c

Browse files
committed
Warn of possible permission problems if "EXEC sp_helptext..." does not work view. Fixes #73.
1 parent 444da38 commit aecca5c

File tree

4 files changed

+16
-4
lines changed

4 files changed

+16
-4
lines changed

CHANGELOG

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11

2-
* 3.0.13 *
2+
* 3.0.15 *
3+
4+
* Warn of possible permission problems if "EXEC sp_helptext..." does not work view. Fixes #73.
5+
6+
7+
* 3.0.13/3.0.14 *
38

49
* Allow TinyTDS/DBLIB mode to pass down :host/:port config options.
510

activerecord-sqlserver-adapter.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Gem::Specification.new do |s|
33
s.platform = Gem::Platform::RUBY
44
s.name = "activerecord-sqlserver-adapter"
5-
s.version = "3.0.14"
5+
s.version = "3.0.15"
66
s.summary = "SQL Server 2005 and 2008 Adapter For ActiveRecord."
77
s.description = "SQL Server 2005 and 2008 Adapter For ActiveRecord"
88

lib/active_record/connection_adapters/sqlserver/schema_statements.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,13 @@ def view_information(table_name)
306306
if view_info
307307
view_info = view_info.with_indifferent_access
308308
if view_info[:VIEW_DEFINITION].blank? || view_info[:VIEW_DEFINITION].length == 4000
309-
view_info[:VIEW_DEFINITION] = info_schema_query { select_values("EXEC sp_helptext #{quote_table_name(table_name)}").join }
309+
view_info[:VIEW_DEFINITION] = info_schema_query do
310+
begin
311+
select_values("EXEC sp_helptext #{quote_table_name(table_name)}").join
312+
rescue
313+
warn "No view definition found, possible permissions problem.\nPlease run GRANT VIEW DEFINITION TO your_user;"
314+
end
315+
end
310316
end
311317
end
312318
view_info
@@ -320,6 +326,7 @@ def table_name_or_views_table_name(table_name)
320326

321327
def views_real_column_name(table_name,column_name)
322328
view_definition = view_information(table_name)[:VIEW_DEFINITION]
329+
323330
match_data = view_definition.match(/([\w-]*)\s+as\s+#{column_name}/im)
324331
match_data ? match_data[1] : column_name
325332
end

lib/active_record/connection_adapters/sqlserver_adapter.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ class SQLServerAdapter < AbstractAdapter
164164
include Sqlserver::Errors
165165

166166
ADAPTER_NAME = 'SQLServer'.freeze
167-
VERSION = '3.0.14'.freeze
167+
VERSION = '3.0.15'.freeze
168168
DATABASE_VERSION_REGEXP = /Microsoft SQL Server\s+"?(\d{4}|\w+)"?/
169169
SUPPORTED_VERSIONS = [2005,2008,2010,2011].freeze
170170

0 commit comments

Comments
 (0)