Permalink
Browse files

improve detection of valid table names on oracle

  • Loading branch information...
Simon Chiang
Simon Chiang committed Aug 9, 2011
1 parent d1f75d1 commit b039f1b3f781cd60a9c60d469c7fff1b744f9cb0
Showing with 5 additions and 4 deletions.
  1. +5 −4 activerecord/lib/active_record/relation.rb
@@ -472,12 +472,13 @@ def references_eager_loaded_tables?
(tables_in_string(to_sql) - joined_tables).any?
end
+ NONQUOTED_OBJECT_NAME = /[A-Za-z][A-z0-9$#]{0,29}/
+ NONQUOTED_DATABASE_LINK = /[A-Za-z][A-z0-9$#\.@]{0,127}/
+ TABLES_IN_STRING = /((?:#{NONQUOTED_OBJECT_NAME}\.)?#{NONQUOTED_OBJECT_NAME}(?:@#{NONQUOTED_DATABASE_LINK})?)\..?/
+
def tables_in_string(string)
return [] if string.blank?
- # always convert table names to downcase as in Oracle quoted table names are in uppercase
- # ignore raw_sql_ that is used by Oracle adapter as alias for limit/offset subqueries
- string.scan(/([a-zA-Z_][.\w]+).?\./).flatten.map{ |s| s.downcase }.uniq - ['raw_sql_']
+ string.scan(TABLES_IN_STRING).flatten.map {|str| str.downcase }.uniq - ['raw_sql_']
end
-
end
end

0 comments on commit b039f1b

Please sign in to comment.