Esempio n. 1
0
def format_file(infile, outdir, local_config):
    """
        SQLファイル(infile)をフォーマットして指定フォルダ[outdir]に出力する
    """
    try:
        sql = __read_file(infile)
    except:
        print(infile)
        print(traceback.format_exc())

    error = False

    try:
        out_sql = uroborosqlfmt.format_sql(sql, local_config)
    except SqlFormatterException as ex:
        exs = __decode(str(ex))
        trace = __decode(traceback.format_exc())
        out_sql = sql + "\n/*" + exs + "\n" + trace + "\n*/"
        error = True
    except:
        trace = __decode(traceback.format_exc())
        out_sql = sql + "\n/*" + trace + "\n*/"
        error = True

    if not error:
        file_name = os.path.basename(infile)
        out_path = os.path.join(outdir, file_name)
    else:
        out_path = os.path.join(outdir, "formaterror_" + file_name)
    out_dir = os.path.dirname(out_path)
    if not os.path.exists(out_dir):
        os.makedirs(out_dir)
    __write_file(out_path, out_sql)
 def run_format(self, edit, raw_text, config, region_a, region_b):
     formatted_text = uroborosqlfmt.format_sql(raw_text, config)
     self.view.run_command(
         "uroborosql_format_replace", {
             "region_a": region_a,
             "region_b": region_b,
             "formatted_text": formatted_text
         })
Esempio n. 3
0
def sample():
    sql = u"""
select column1 as column1, --column1
column2 as column2 --column1
,long_column_3 as long_long_column_3 --column3
from foo_table --table
where column1 = 'sample' --column1
and long_column_3 is not null
"""

    formatted = uroborosqlfmt.format_sql(sql)

    print(formatted)
Esempio n. 4
0
def format_dir(indir, outdir, local_config):
    """
        [indir]フォルダ内のSQLファイルをフォーマットして指定フォルダ[outdir]に出力する
    """
    if indir.endswith("/") or indir.endswith("\\"):
        indir = indir[:-1]
    if outdir.endswith("/") or outdir.endswith("\\"):
        outdir = outdir[:-1]

    for file_name, full_path in find_all_sql_files(indir):
        try:
            sql = __read_file(full_path)
        except:
            print(full_path)
            print(traceback.format_exc())
            continue
        error = False
        try:
            out_sql = uroborosqlfmt.format_sql(sql, local_config)
        except SqlFormatterException as ex:
            exs = __decode(str(ex))
            trace = __decode(traceback.format_exc())
            out_sql = sql + "\n/*" + exs + "\n" + trace + "\n*/"
            error = True
        except:
            trace = __decode(traceback.format_exc())
            out_sql = sql + "\n/*" + trace + "\n*/"
            error = True

        if not error:
            out_path = os.path.join(outdir, file_name)
        else:
            out_path = os.path.join(outdir, "formaterror_" + file_name)
        out_dir = os.path.dirname(out_path)
        if not os.path.exists(out_dir):
            os.makedirs(out_dir)
        __write_file(out_path, out_sql)
def do_format(text):
    op, op_tab = get_ops()
    text = uroborosqlfmt.format_sql(text, op)
    if op_tab["spaces"]:
        text = text.replace('\t', ' ' * op_tab["size"])
    return text
def format_sql(text):
    formated = uroborosqlfmt.format_sql(text)
    #     print(formated)
    #     print(repr(formated))

    return formated
def format_sql(text, config):
    return uroborosqlfmt.format_sql(text, config)
def format_sql(text):
    formated = uroborosqlfmt.format_sql(text, LocalConfig())

    return formated