示例#1
0
def run_cli_with(options):

    if create_config_dir_for_first_use():
        display_telemetry_message()

    display_version_message(options)
    display_integrated_auth_message_for_non_windows(options)

    configure_and_update_options(options)

    mssqlcli = MssqlCli(options)
    mssqlcli.connect_to_database()
    mssqlcli.run()
示例#2
0
def run_cli_with(options):

    if create_config_dir_for_first_use():
        display_telemetry_message()

    display_version_message(options)

    configure_and_update_options(options)

    # Importing MssqlCli creates a config dir by default.
    # Moved import here so we can create the config dir for first use prior.
    from mssqlcli.mssql_cli import MssqlCli

    mssqlcli = MssqlCli(options)
    mssqlcli.connect_to_database()

    telemetry_session.set_server_information(mssqlcli.mssqlcliclient_main)
    mssqlcli.run()
示例#3
0
def run_cli_with(options):

    if create_config_dir_for_first_use():
        display_telemetry_message()

    display_version_message(options)

    configure_and_update_options(options)

    # Importing MssqlCli creates a config dir by default.
    # Moved import here so we can create the config dir for first use prior.
    # pylint: disable=import-outside-toplevel
    from mssqlcli.mssql_cli import MssqlCli

    # set interactive mode to false if -Q or -i is specified
    if options.query or options.input_file:
        options.interactive_mode = False

    mssqlcli = MssqlCli(options)
    try:
        mssqlcli.connect_to_database()
        telemetry_session.set_server_information(mssqlcli.mssqlcliclient_main)

        if mssqlcli.interactive_mode:
            mssqlcli.run()
        else:
            text = options.query
            if options.input_file:
                # get query text from input file
                try:
                    if six.PY2:
                        with io.open(options.input_file, 'r',
                                     encoding='utf-8') as f:
                            text = f.read()
                    else:
                        with open(options.input_file, 'r',
                                  encoding='utf-8') as f:
                            text = f.read()
                except OSError as e:
                    click.secho(str(e), err=True, fg='red')
                    sys.exit(1)
            mssqlcli.execute_query(text)
    finally:
        mssqlcli.shutdown()