| 20 | |
| 21 | |
| 22 | class MssqlCliClient: |
| 23 | # pylint: disable=too-many-instance-attributes |
| 24 | |
| 25 | def __init__(self, mssqlcli_options, sql_tools_client, owner_uri=None, **kwargs): |
| 26 | |
| 27 | self.server_name = mssqlcli_options.server |
| 28 | if ',' in mssqlcli_options.server: |
| 29 | self.prompt_host, self.prompt_port = self.server_name.split(',') |
| 30 | else: |
| 31 | self.prompt_host = mssqlcli_options.server |
| 32 | self.prompt_port = 1433 |
| 33 | |
| 34 | self.user_name = mssqlcli_options.username |
| 35 | self.password = mssqlcli_options.password |
| 36 | self.authentication_type = u'Integrated' if mssqlcli_options.integrated_auth \ |
| 37 | else u'SqlLogin' |
| 38 | self.database = mssqlcli_options.database |
| 39 | self.connected_database = None |
| 40 | self.encrypt = mssqlcli_options.encrypt |
| 41 | self.trust_server_certificate = mssqlcli_options.trust_server_certificate |
| 42 | self.connection_timeout = mssqlcli_options.connection_timeout |
| 43 | self.application_intent = mssqlcli_options.application_intent |
| 44 | self.multi_subnet_failover = mssqlcli_options.multi_subnet_failover |
| 45 | self.packet_size = mssqlcli_options.packet_size |
| 46 | |
| 47 | self.owner_uri = owner_uri if owner_uri else generate_owner_uri() |
| 48 | self.sql_tools_client = sql_tools_client |
| 49 | self.is_connected = False |
| 50 | self.server_version = None |
| 51 | self.server_edition = None |
| 52 | self.is_cloud = False |
| 53 | |
| 54 | self.extra_params = kwargs |
| 55 | |
| 56 | logger.info(u'Initialized MssqlCliClient with owner Uri %s', self.owner_uri) |
| 57 | |
| 58 | def get_base_connection_params(self): |
| 59 | return { |
| 60 | u'ServerName': self.server_name, |
| 61 | u'DatabaseName': self.connected_database if self.connected_database \ |
| 62 | else self.database, |
| 63 | u'UserName': self.user_name, |
| 64 | u'Password': self.password, |
| 65 | u'AuthenticationType': self.authentication_type, |
| 66 | u'OwnerUri': self.owner_uri |
| 67 | } |
| 68 | |
| 69 | def add_optional_connection_params(self, base_connection_params): |
| 70 | if self.encrypt: |
| 71 | base_connection_params[u'Encrypt'] = self.encrypt |
| 72 | if self.trust_server_certificate: |
| 73 | base_connection_params[u'TrustServerCertificate'] = self.trust_server_certificate |
| 74 | if self.connection_timeout: |
| 75 | base_connection_params[u'ConnectTimeout'] = self.connection_timeout |
| 76 | if self.application_intent: |
| 77 | base_connection_params[u'ApplicationIntent'] = self.application_intent |
| 78 | if self.multi_subnet_failover: |
| 79 | base_connection_params[u'MultiSubnetFailover'] = self.multi_subnet_failover |