以任何方式解析mysql查询以提取选择字符串,连接字符串,where子句字符串等

时间:2014-01-02 08:04:05

标签: mysql sql regex string string-parsing

我有很多像下面这样的查询。有没有办法解析这个查询并提取子查询及其选择字符串,连接字符串,条件字符串

 select count(1) count from (
        SELECT count(party.id) as count
        FROM party

        LEFT OUTER JOIN party_identifier on party.id = party_identifier.party_id
        LEFT OUTER JOIN blood_type on blood_type.id = party.blood_type_id
        LEFT OUTER JOIN education_level on education_level.id = party.education_level_id
        LEFT OUTER JOIN religion on religion.id = party.religion_id
        LEFT OUTER JOIN living_arrangement on living_arrangement.id = party.living_arrangement_id
      LEFT OUTER JOIN patient_patient_search patient_patient_search on patient_patient_search.patient_id = party.id



      WHERE  party.type = "Patient" AND party.record_status_id = 1 AND party_identifier.source_note = 'simplifyMD Patient ID'

       AND   (  patient_patient_search.patient_search_id in (1.0) ) and   ((1 and nullif(party.birth_date,'0000-00-00') is not null)) 
       AND   ((1 and party.ethnicity_id is not null))   
       AND   (  party.preferred_language_id is not null and  1 )   
       GRPOUP BY party.id) 
  as count

输出如

query[1] => {:select=>"count(1)",:from=>"party",
             :sub_query=>{:select=>"count(party.id)",:joins=>['party_identifier on party.id = party_identifier.party_id','blood_type on blood_type.id = party.blood_type_id',......],
             :where=>"party.type = "Patient" AND party.record_status_id = 1....."}
            }

0 个答案:

没有答案