CONPY-205: Added error constants

Error code constants are now defined in constants/ERR.
The file ERR.py is generated by helper/create_errconst.py
script, please don't edit it.
This commit is contained in:
Georg Richter
2022-05-25 18:54:11 +02:00
parent 30c8f33b08
commit f23e4e9b83
5 changed files with 1262 additions and 2 deletions

24
helper/create_errconst.py Normal file
View File

@ -0,0 +1,24 @@
import requests
ignore_definitions= ["ERR_ERROR_FIRST", "ER_ERROR_LAST", "CR_MIN_ERROR", "CR_MAX_ERROR",
"CER_MIN_ERROR", "CER_MAX_ERROR", "CR_MYSQL_LAST_ERROR", "CR_MARIADB_LAST_ERROR"]
files= ["https://raw.githubusercontent.com/mariadb-corporation/mariadb-connector-c/3.3/include/mysqld_error.h",
"https://raw.githubusercontent.com/mariadb-corporation/mariadb-connector-c/3.3/include/errmsg.h"]
error_definitions= []
for i in range(0, len(files)):
errors= requests.get(files[i], allow_redirects=True)
error_definitions+= errors.content.decode("utf8").split("\n")
print("# Autogenerated file. Please do not edit!\n\n")
for i in range(0, len(error_definitions)):
x= error_definitions[i].split(" ")
if len(x) == 3 and x[0] == "#define" and x[1] not in ignore_definitions and x[1][:9] != "ER_UNUSED":
try:
if int(x[2]) > 0:
print("%s = %s" % (x[1], x[2]))
except:
pass

1227
mariadb/constants/ERR.py Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1 +1 @@
__all__ = ["CLIENT", "CURSOR", "FIELD_TYPE", "FIELD_FLAG", "INDICATOR", 'STATUS'] __all__ = ["CLIENT", "CURSOR", "FIELD_TYPE", "FIELD_FLAG", "INDICATOR", 'STATUS', 'ERR']

View File

@ -98,6 +98,6 @@ setup(name='mariadb',
py_modules=['mariadb.__init__', 'mariadb.constants.CLIENT', 'mariadb.constants.CURSOR', py_modules=['mariadb.__init__', 'mariadb.constants.CLIENT', 'mariadb.constants.CURSOR',
'mariadb.constants.STATUS', 'mariadb.constants.TPC_STATE', 'mariadb.constants.INFO', 'mariadb.constants.STATUS', 'mariadb.constants.TPC_STATE', 'mariadb.constants.INFO',
'mariadb.field', 'mariadb.connections', 'mariadb.connectionpool', 'mariadb.dbapi20', 'mariadb.field', 'mariadb.connections', 'mariadb.connectionpool', 'mariadb.dbapi20',
'mariadb.cursors', 'mariadb.release_info', 'mariadb.cursors', 'mariadb.release_info', 'mariadb.constants.ERR',
'mariadb.constants.FIELD_TYPE', 'mariadb.constants.FIELD_FLAG', 'mariadb.constants.INDICATOR'], 'mariadb.constants.FIELD_TYPE', 'mariadb.constants.FIELD_FLAG', 'mariadb.constants.INDICATOR'],
) )

View File

@ -1278,6 +1278,15 @@ class TestCursor(unittest.TestCase):
cursor.close() cursor.close()
def test_conpy203(self):
conn= create_connection()
cursor= conn.cursor()
try:
cursor.execute("SELECT")
except mariadb.ProgrammingError as err:
self.assertEqual(err.errno, ERR.ER_PARSE_ERROR)
def test_conpy91(self): def test_conpy91(self):
with create_connection() as connection: with create_connection() as connection:
with connection.cursor() as cursor: with connection.cursor() as cursor: