Skip to content

Commit 2d42ed7

Browse files
committed
reconnect() method
1 parent e2dbe66 commit 2d42ed7

File tree

6 files changed

+24
-10
lines changed

6 files changed

+24
-10
lines changed

firebirdsql/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def __cmp__(self, other):
9696

9797
def connect(*args, **kwargs):
9898
conn = Connection(*args, **kwargs)
99-
conn._initialize_socket()
99+
conn._initialize()
100100
return conn
101101

102102

firebirdsql/aio/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44

55
async def connect(**kwargs):
66
conn = AsyncConnection(**kwargs)
7-
await conn._initialize_socket()
7+
await conn._initialize()
88
return conn

firebirdsql/aio/fbcore.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -884,7 +884,12 @@ def __init__(self, *args, **kwargs):
884884
super().__init__(*args, **kwargs)
885885
self.last_usage = self.loop.time()
886886

887-
async def _initialize_socket(self):
887+
async def _initialize(self):
888+
self.last_event_id = 0
889+
self._autocommit = False
890+
self._transaction = None
891+
self._cursors = {}
892+
888893
self.sock = AsyncSocketStream(self.hostname, self.port, self.loop, self.timeout, self.cloexec)
889894

890895
self._op_connect(self.auth_plugin_name, self.wire_crypt)
@@ -897,7 +902,7 @@ async def _initialize_socket(self):
897902
self._op_attach(self.timezone)
898903
(h, oid, buf) = await self._async_op_response()
899904
self.db_handle = h
900-
DEBUG_OUTPUT("AsyncConnection::_initialize_socket()", self.db_handle)
905+
DEBUG_OUTPUT("AsyncConnection::_initialize()", self.db_handle)
901906

902907
async def __aenter__(self):
903908
return self
@@ -910,6 +915,10 @@ async def __aexit__(self, exc, value, traceback):
910915
await self.commit()
911916
await self.close()
912917

918+
async def reconnect(self):
919+
self.close()
920+
await self._initialize()
921+
913922
async def set_autocommit(self, is_autocommit):
914923
if self._autocommit != is_autocommit and self._transaction is not None:
915924
await self.rollback()

firebirdsql/aio/pool.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ async def _fill_free_pool(self, override_min):
166166
self._acquiring += 1
167167
try:
168168
conn = AsyncConnection(loop=self._loop, **self._conn_kwargs)
169-
await conn._initialize_socket()
169+
await conn._initialize()
170170
# raise exception if pool is closing
171171
self._free.append(conn)
172172
self._cond.notify()
@@ -179,7 +179,7 @@ async def _fill_free_pool(self, override_min):
179179
self._acquiring += 1
180180
try:
181181
conn = AsyncConnection(loop=self._loop, **self._conn_kwargs)
182-
await conn._initialize_socket()
182+
await conn._initialize()
183183
# raise exception if pool is closing
184184
self._free.append(conn)
185185
self._cond.notify()

firebirdsql/fbcore.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -974,13 +974,14 @@ def __init__(
974974
self.isolation_level = int(isolation_level)
975975
self.use_unicode = use_unicode
976976
self.timezone = timezone
977-
self.last_event_id = 0
978977

978+
979+
def _initialize(self):
980+
self.last_event_id = 0
979981
self._autocommit = False
980982
self._transaction = None
981983
self._cursors = {}
982984

983-
def _initialize_socket(self):
984985
self.sock = SocketStream(self.hostname, self.port, self.timeout, self.cloexec)
985986

986987
self._op_connect(self.auth_plugin_name, self.wire_crypt)
@@ -998,7 +999,7 @@ def _initialize_socket(self):
998999
self._op_attach(self.timezone)
9991000
(h, oid, buf) = self._op_response()
10001001
self.db_handle = h
1001-
DEBUG_OUTPUT("Connection::_initialize_socket()", self.db_handle)
1002+
DEBUG_OUTPUT("Connection::_initialize()", self.db_handle)
10021003

10031004
def __enter__(self):
10041005
return self
@@ -1011,6 +1012,10 @@ def __exit__(self, exc, value, traceback):
10111012
self.commit()
10121013
self.close()
10131014

1015+
def reconnect(self):
1016+
self.close()
1017+
self._initalize()
1018+
10141019
def set_isolation_level(self, isolation_level):
10151020
self.isolation_level = int(isolation_level)
10161021

firebirdsql/services.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,5 +374,5 @@ def getStatistics(
374374
def connect(**kwargs):
375375
kwargs['is_services'] = True
376376
services = Services(**kwargs)
377-
services._initialize_socket()
377+
services._initialize()
378378
return services

0 commit comments

Comments
 (0)