lib/shiba/parsers/mysql_select_fields.rb in shiba-0.9.3 vs lib/shiba/parsers/mysql_select_fields.rb in shiba-0.9.4

- old
+ new

@@ -1,9 +1,10 @@ require 'shiba/parsers/shiba_string_scanner' module Shiba module Parsers + # Extracts table name and columns from queries formatted by 'show warnings'. class MysqlSelectFields def initialize(sql) @sql = sql @sc = ShibaStringScanner.new(@sql) end @@ -64,9 +65,21 @@ return {} end sc.scan(/,/) end + + # resolve table aliases + if sc.scan(/ `.*?`\.`(.*?)` `(.*?)`/) + table = sc[1] + table_alias = sc[2] + + if tables[table_alias] + tables[table] = tables[table_alias] + tables.delete(table_alias) + end + end + tables end end end end