Skip to content

Commit

Permalink
Internal improvement for Autocommit (#468)
Browse files Browse the repository at this point in the history
  • Loading branch information
sitingren authored Oct 25, 2022
1 parent c7c68ce commit b66ad1a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
8 changes: 3 additions & 5 deletions vertica_python/vertica/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,10 +327,6 @@ def __init__(self, options=None):
self.options['host'], self.options['port']))
self.startup_connection()

# Initially, for a new session, autocommit is off
if self.options['autocommit']:
self.autocommit = True

self._logger.info('Connection is ready')

#############################################
Expand Down Expand Up @@ -385,6 +381,7 @@ def cursor(self, cursor_type=None):
@property
def autocommit(self):
"""Read the connection's AUTOCOMMIT setting from cache"""
# For a new session, autocommit is off by default
return self.parameters.get('auto_commit', 'off') == 'on'

@autocommit.setter
Expand Down Expand Up @@ -805,9 +802,10 @@ def startup_connection(self):
session_label = self.options['session_label']
os_user_name = DEFAULT_USER if DEFAULT_USER else ''
password = self.options['password']
autocommit = self.options['autocommit']
binary_transfer = self.options['binary_transfer']

self.write(messages.Startup(user, database, session_label, os_user_name, binary_transfer))
self.write(messages.Startup(user, database, session_label, os_user_name, autocommit, binary_transfer))

while True:
message = self.read_message()
Expand Down
3 changes: 2 additions & 1 deletion vertica_python/vertica/messages/frontend_messages/startup.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
class Startup(BulkFrontendMessage):
message_id = None

def __init__(self, user, database, session_label, os_user_name, binary_transfer):
def __init__(self, user, database, session_label, os_user_name, autocommit, binary_transfer):
BulkFrontendMessage.__init__(self)

try:
Expand All @@ -79,6 +79,7 @@ def __init__(self, user, database, session_label, os_user_name, binary_transfer)
b'client_os': os_platform,
b'client_os_user_name': os_user_name,
b'client_pid': pid,
b'autocommit': 'on' if autocommit else 'off',
b'binary_data_protocol': '1' if binary_transfer else '0', # Defaults to text format '0'
}

Expand Down

0 comments on commit b66ad1a

Please sign in to comment.