Skip to content

Commit bb7fdd1

Browse files
committed
- Fix connection.autocommit. (#21)
- Fix `_clear_result`. (#22)
1 parent e36943c commit bb7fdd1

File tree

4 files changed

+21
-5
lines changed

4 files changed

+21
-5
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
### 0.2.3
66

77
- Fix `escape_sequence`. (#20)
8+
- Fix `connection.autocommit`. (#21)
9+
- Fix `_clear_result`. (#22)
810

911
### 0.2.2
1012

asyncmy/connection.pyx

+3-3
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@ class Connection:
636636
await result.read()
637637
self._result = result
638638
self._affected_rows = result.affected_rows
639-
if result.server_status is not None:
639+
if result.server_status != 0:
640640
self.server_status = result.server_status
641641

642642
def insert_id(self):
@@ -704,7 +704,7 @@ class Connection:
704704

705705
if self._ssl_context:
706706
# capablities, max packet, charset
707-
data = IIB.pack( self._client_flag, 16777216, 33)
707+
data = IIB.pack(self._client_flag, 16777216, 33)
708708
data += b'\x00' * (32 - len(data))
709709

710710
self.write_packet(data)
@@ -1141,7 +1141,7 @@ cdef class MySQLResult:
11411141
self.affected_rows = len(rows)
11421142
self.rows = tuple(rows)
11431143

1144-
def _read_row_from_packet(self, packet):
1144+
cpdef _read_row_from_packet(self, packet: MysqlPacket):
11451145
row = []
11461146
for encoding, converter in self.converters:
11471147
try:

asyncmy/cursors.pyx

+2-2
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ cdef class Cursor:
306306
self._executed = q
307307
return args
308308

309-
cpdef fetchone(self):
309+
cpdef fetchone(self):
310310
"""Fetch the next row."""
311311
self._check_executed()
312312
fut = self._loop.create_future()
@@ -366,7 +366,7 @@ cdef class Cursor:
366366
await self._do_get_result()
367367
return self.rowcount
368368

369-
cdef _clear_result(self):
369+
cpdef _clear_result(self):
370370
self.rownumber = 0
371371
self._result = None
372372
self.rowcount = 0

tests/test_autocommit.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import pytest
2+
3+
4+
@pytest.mark.asyncio
5+
async def test_autocommit(connection):
6+
await connection.autocommit(True)
7+
cursor = connection.cursor()
8+
await cursor.execute("SELECT @@autocommit;")
9+
assert await cursor.fetchone() == (1,)
10+
await cursor.close()
11+
await connection.autocommit(False)
12+
cursor = connection.cursor()
13+
await cursor.execute("SELECT @@autocommit;")
14+
assert await cursor.fetchone() == (0,)

0 commit comments

Comments
 (0)