File tree Expand file tree Collapse file tree 1 file changed +12
-7
lines changed
lib/active_record/connection_adapters/sqlserver Expand file tree Collapse file tree 1 file changed +12
-7
lines changed Original file line number Diff line number Diff line change @@ -531,17 +531,22 @@ def remove_indexes(table_name, column_name)
531531
532532 # === SQLServer Specific (Misc Helpers) ========================= #
533533
534+ # Parses just the table name from the SQL. Table name does not include database/schema/etc.
534535 def get_table_name ( sql )
535- tn = if sql =~ /^\s *(INSERT|EXEC sp_executesql N'INSERT)(\s +INTO)?\s +([^\( \s ]+)\s *|^\s *update\s +([^\( \s ]+)\s */i
536- Regexp . last_match [ 3 ] || Regexp . last_match [ 4 ]
537- elsif sql =~ /FROM\s +([^\( \s ]+)\s */i
538- Regexp . last_match [ 1 ]
539- else
540- nil
541- end
536+ tn = get_raw_table_name ( sql )
542537 SQLServer ::Utils . extract_identifiers ( tn ) . object
543538 end
544539
540+ # Parses the raw table name that is used in the SQL. Table name could include database/schema/etc.
541+ def get_raw_table_name ( sql )
542+ case sql
543+ when /^\s *(INSERT|EXEC sp_executesql N'INSERT)(\s +INTO)?\s +([^\( \s ]+)\s *|^\s *update\s +([^\( \s ]+)\s */i
544+ Regexp . last_match [ 3 ] || Regexp . last_match [ 4 ]
545+ when /FROM\s +([^\( \s ]+)\s */i
546+ Regexp . last_match [ 1 ]
547+ end
548+ end
549+
545550 def default_constraint_name ( table_name , column_name )
546551 "DF_#{ table_name } _#{ column_name } "
547552 end
You can’t perform that action at this time.
0 commit comments