File tree Expand file tree Collapse file tree 1 file changed +15
-5
lines changed
Expand file tree Collapse file tree 1 file changed +15
-5
lines changed Original file line number Diff line number Diff line change @@ -23,29 +23,39 @@ def get_table_name(sql, qualified = nil)
2323
2424 # protected
2525
26+ def unquote_keyword ( keyword )
27+ if /\A (\[ |")(.*)/m . match ( keyword )
28+ delim , rest = $1, $2
29+ if delim == '[' && rest =~ /]\z / || delim == '"' && rest =~ /"\z /
30+ return rest . chop
31+ end
32+ end
33+ keyword
34+ end
35+
2636 def unquote_table_name ( table_name )
27- unquote_column_name ( table_name )
37+ unquote_keyword ( table_name )
2838 end
2939
3040 def unquote_column_name ( column_name )
31- column_name . to_s . tr ( '[]' , '' )
41+ unquote_keyword ( column_name )
3242 end
3343
3444 def unquote_string ( string )
3545 string . to_s . gsub ( "''" , "'" )
3646 end
3747
3848 def unqualify_table_name ( table_name )
39- table_name . to_s . split ( '.' ) . last . tr ( '[]' , '' )
49+ unquote_keyword ( table_name . to_s . split ( '.' ) . last )
4050 end
4151
4252 def unqualify_table_schema ( table_name )
43- table_name . to_s . split ( '.' ) [ -2 ] . gsub ( /[ \[ \] ]/ , '' ) rescue nil
53+ unquote_keyword ( table_name . to_s . split ( '.' ) [ -2 ] ) rescue nil
4454 end
4555
4656 def unqualify_db_name ( table_name )
4757 table_names = table_name . to_s . split ( '.' )
48- table_names . length == 3 ? table_names . first . tr ( '[]' , '' ) : nil
58+ table_names . length == 3 ? unquote_keyword ( table_names . first ) : nil
4959 end
5060
5161 end
You can’t perform that action at this time.
0 commit comments