|
37 | 37 | PARAMETER_CLIENT_STORE_TEMPORARY_CREDENTIAL, |
38 | 38 | PARAMETER_CLIENT_PREFETCH_THREADS, |
39 | 39 | ) |
40 | | -from .cursor import SnowflakeCursor |
| 40 | +from .cursor import SnowflakeCursor, LOG_MAX_QUERY_LENGTH |
41 | 41 | from .errorcode import (ER_CONNECTION_IS_CLOSED, |
42 | 42 | ER_NO_ACCOUNT_NAME, ER_OLD_PYTHON, ER_NO_USER, |
43 | 43 | ER_NO_PASSWORD, ER_INVALID_VALUE, |
@@ -131,7 +131,8 @@ def DefaultConverterClass(): |
131 | 131 | u'timezone': None, # snowflake |
132 | 132 | u'consent_cache_id_token': True, # snowflake |
133 | 133 | u'service_name': None, # snowflake, |
134 | | - u'support_negative_year': True # snowflake |
| 134 | + u'support_negative_year': True, # snowflake |
| 135 | + u'log_max_query_length': LOG_MAX_QUERY_LENGTH, # snowflake |
135 | 136 | } |
136 | 137 |
|
137 | 138 | APPLICATION_RE = re.compile(r'[\w\d_]+') |
@@ -427,6 +428,10 @@ def service_name(self): |
427 | 428 | def service_name(self, value): |
428 | 429 | self._service_name = value |
429 | 430 |
|
| 431 | + @property |
| 432 | + def log_max_query_length(self): |
| 433 | + return self._log_max_query_length |
| 434 | + |
430 | 435 | def connect(self, **kwargs): |
431 | 436 | u""" |
432 | 437 | Connects to the database |
@@ -585,24 +590,30 @@ def __open_connection(self): |
585 | 590 | self.port) |
586 | 591 |
|
587 | 592 | if 'SF_OCSP_RESPONSE_CACHE_SERVER_URL' in os.environ: |
588 | | - logger.debug(u"Custom OCSP Cache Server URL found in environment - %s", os.environ['SF_OCSP_RESPONSE_CACHE_SERVER_URL']) |
| 593 | + logger.debug( |
| 594 | + u"Custom OCSP Cache Server URL found in environment - %s", |
| 595 | + os.environ['SF_OCSP_RESPONSE_CACHE_SERVER_URL']) |
589 | 596 |
|
590 | 597 | if self.host.endswith(u".privatelink.snowflakecomputing.com"): |
591 | 598 | ocsp_cache_server = \ |
592 | 599 | u'http://ocsp{}/ocsp_response_cache.json'.format( |
593 | 600 | self.host[self.host.index('.'):]) |
594 | 601 | if 'SF_OCSP_RESPONSE_CACHE_SERVER_URL' not in os.environ: |
595 | | - os.environ['SF_OCSP_RESPONSE_CACHE_SERVER_URL'] = ocsp_cache_server |
| 602 | + os.environ[ |
| 603 | + 'SF_OCSP_RESPONSE_CACHE_SERVER_URL'] = ocsp_cache_server |
596 | 604 | else: |
597 | | - if not os.environ['SF_OCSP_RESPONSE_CACHE_SERVER_URL'].\ |
| 605 | + if not os.environ['SF_OCSP_RESPONSE_CACHE_SERVER_URL']. \ |
598 | 606 | startswith("http://"): |
599 | | - ocsp_cache_server = "http://{0}/{1}".format(os.environ['SF_OCSP_RESPONSE_CACHE_SERVER_URL'], |
600 | | - "ocsp_response_cache.json") |
| 607 | + ocsp_cache_server = "http://{0}/{1}".format( |
| 608 | + os.environ['SF_OCSP_RESPONSE_CACHE_SERVER_URL'], |
| 609 | + "ocsp_response_cache.json") |
601 | 610 | else: |
602 | | - ocsp_cache_server = "{0}/{1}".format(os.environ['SF_OCSP_RESPONSE_CACHE_SERVER_URL'], |
603 | | - "ocsp_response_cache.json") |
| 611 | + ocsp_cache_server = "{0}/{1}".format( |
| 612 | + os.environ['SF_OCSP_RESPONSE_CACHE_SERVER_URL'], |
| 613 | + "ocsp_response_cache.json") |
604 | 614 |
|
605 | | - os.environ['SF_OCSP_RESPONSE_CACHE_SERVER_URL'] = ocsp_cache_server |
| 615 | + os.environ[ |
| 616 | + 'SF_OCSP_RESPONSE_CACHE_SERVER_URL'] = ocsp_cache_server |
606 | 617 | logger.debug(u"OCSP Cache Server is updated: %s", ocsp_cache_server) |
607 | 618 | else: |
608 | 619 | if 'SF_OCSP_RESPONSE_CACHE_SERVER_URL' in os.environ: |
@@ -783,9 +794,7 @@ def cmd_query(self, sql, sequence_counter, request_id, |
783 | 794 | if logger.getEffectiveLevel() <= logging.DEBUG: |
784 | 795 | logger.debug( |
785 | 796 | u'sql=[%s], sequence_id=[%s], is_file_transfer=[%s]', |
786 | | - u' '.join( |
787 | | - line.strip() for line in |
788 | | - data[u'sqlText'].split(u'\n')), |
| 797 | + self._format_query_for_log(data[u'sqlText']), |
789 | 798 | data[u'sequenceId'], |
790 | 799 | is_file_transfer |
791 | 800 | ) |
@@ -1091,6 +1100,11 @@ def _set_parameters(self, ret, session_parameters): |
1091 | 1100 | elif PARAMETER_CLIENT_PREFETCH_THREADS == name: |
1092 | 1101 | self.client_prefetch_threads = value |
1093 | 1102 |
|
| 1103 | + def _format_query_for_log(self, query): |
| 1104 | + ret = u' '.join(line.strip() for line in query.split(u'\n')) |
| 1105 | + return (ret if len(ret) < self.log_max_query_length |
| 1106 | + else ret[0:self.log_max_query_length] + '...') |
| 1107 | + |
1094 | 1108 | def __enter__(self): |
1095 | 1109 | u""" |
1096 | 1110 | context manager |
|
0 commit comments