This commit is contained in:
Iliyan Angelov
2025-12-01 06:50:10 +02:00
parent 91f51bc6fe
commit 62c1fe5951
4682 changed files with 544807 additions and 31208 deletions

View File

@@ -136,7 +136,14 @@ del _map_error, ER
def raise_mysql_exception(data):
errno = struct.unpack("<h", data[1:3])[0]
errval = data[9:].decode("utf-8", "replace")
# https://dev.mysql.com/doc/dev/mysql-server/latest/page_protocol_basic_err_packet.html
# Error packet has optional sqlstate that is 5 bytes and starts with '#'.
if data[3] == 0x23: # '#'
# sqlstate = data[4:9].decode()
# TODO: Append (sqlstate) in the error message. This will be come in next minor release.
errval = data[9:].decode("utf-8", "replace")
else:
errval = data[3:].decode("utf-8", "replace")
errorclass = error_map.get(errno)
if errorclass is None:
errorclass = InternalError if errno < 1000 else OperationalError