def parse_sql_from_string()

in route.py [0:0]


def parse_sql_from_string(input_string):
    input_string = input_string.replace('\n', ' ').replace('\t','')
    rs = ''
    if '```sql' in input_string:
        try:
            sql_pattern = r'```sql(.*?)```'
            all_sqls = []
            for match in re.finditer(sql_pattern, input_string, re.DOTALL):
                all_sqls.append(match.group(1).strip())
            if all_sqls: 
                rs = all_sqls[-1]  
                if 'SELECT' not in rs and len(all_sqls)>1:
                    rs = all_sqls[-2]    
        except: 
            None
    if 'select' in input_string.lower() and rs=='':
        rs = input_string[input_string.find('SELECT'):]
    if ';' in rs:  # end
        rs = rs[:input_string.find(';')+1]
    if rs == '':
        rs = 'SELECT xx FROM xx'
    return replace_multiple_spaces(rs).replace('```','')