コード例 #1
0
def create_mssql_cli_client(options=None,
                            owner_uri=None,
                            connect=True,
                            sql_tools_client=None,
                            **additional_params):
    """
    Retrieve a mssqlcliclient connection.
    :param options: options
    :param owner_uri: string
    :param connect: boolean
    :param sql_tools_client: SqlToolsClient
    :param additional_params: kwargs
    :return: MssqlCliClient
    """
    try:
        sql_tools_client = sql_tools_client if sql_tools_client else sqltoolsclient.SqlToolsClient(
        )
        mssql_cli_options = options if options else create_mssql_cli_options()

        mssql_cli_client = mssqlcliclient.MssqlCliClient(mssql_cli_options,
                                                         sql_tools_client,
                                                         owner_uri=owner_uri,
                                                         **additional_params)

        if connect:
            mssql_cli_client.connect_to_database()
        return mssql_cli_client
    except Exception as e:
        print('Connection failed')
        raise e
コード例 #2
0
    def test_mssqlcliclient_request_response(self):
        """
        Test mssqlcliclient pipeline for sending request and receiving response works.
        """
        def get_test_baseline(file_name):
            """
            Helper method to get baseline file.
            """
            return os.path.abspath(
                os.path.join(os.path.abspath(__file__), u'..', u'..',
                             u'mssqlcli', u'jsonrpc', u'contracts', u'tests',
                             u'baselines', file_name))

        with open(get_test_baseline(
                u'select_from_humanresources_department_adventureworks2014.txt'
        ),
                  u'r+b',
                  buffering=0) as response_file:
            request_stream = io.BytesIO()
            self.sql_tools_client = sqltoolsclient.SqlToolsClient(
                input_stream=request_stream, output_stream=response_file)

            # The sleep is required because py.test and logging have an issue with closing the FileHandle
            # in a non-thread safe way
            # issue24262
            sleep(0.5)

        self.client = mssqlcliclient.MssqlCliClient(
            self.sql_tools_client,
            u'bro-hb',
            u'*',
            u'*',
            authentication_type=u'Integrated',
            database=u'AdventureWorks2014',
            owner_uri=u'connectionservicetest',
            extra_bool_param=True,
            extra_string_param=u'stringparam',
            extra_int_param=5)
        self.client.sql_tools_client.shutdown()
コード例 #3
0
def create_mssql_cli_client(owner_uri=None, connect=True):
    """
    Retrieve a mssqlcliclient connection.
    :param owner_uri: string
    :param connect: boolean
    :param server_name: string
    :param database_name: string
    :return: MssqlCliClient
    """
    try:
        server_name = os.environ['MSSQL_CLI_SERVER']
        database_name = os.environ['MSSQL_CLI_DATABASE']
        user_name = os.environ['MSSQL_CLI_USER']
        password = os.environ['MSSQL_CLI_PASSWORD']

        if not server_name or not database_name or not user_name or not password:
            raise Exception(
                'Environment variables for running tests not found.')

        sql_tools_client = sqltoolsclient.SqlToolsClient()
        mssql_cli_client = mssqlcliclient.MssqlCliClient(
            sql_tools_client,
            server_name,
            user_name,
            password,
            database=database_name,
            owner_uri=owner_uri,
            extra_bool_param=True,
            extra_string_param=u'stringparam',
            extra_int_param=5)
        if connect:
            mssql_cli_client.connect()
        return mssql_cli_client
    except Exception as e:
        print('Connection failed')
        raise e