Details
-
Bug
-
Status: Closed (View Workflow)
-
Major
-
Resolution: Fixed
-
1.0.11
-
None
Description
the following test runs an INSERT..RETURNING that retrieves a value from a related "sequence" table. on mariadb-connector, it crashes with mariadb.InterfaceError: Lost connection to MySQL server during query. The same tests succeeds with most other major MySQL drivers, mysqlclient, pymysql (this is for SQLAlchemy). The test case below runs first on mysqlclient as a demo and then on mariadb-connector where it crashes.
import mariadb
|
import MySQLdb
|
|
|
def run_test(conn, p):
|
cursor = conn.cursor()
|
|
cursor.execute("DROP TABLE IF EXISTS t2")
|
cursor.execute("DROP TABLE IF EXISTS t1")
|
|
cursor.execute(
|
"""
|
CREATE TABLE t2 (
|
nextid INTEGER
|
)ENGINE=MyISAM
|
"""
|
)
|
|
cursor.execute(
|
"""
|
CREATE TABLE t1 (
|
id INTEGER NOT NULL,
|
data VARCHAR(30),
|
PRIMARY KEY (id)
|
)ENGINE=MyISAM
|
"""
|
)
|
|
cursor.execute(f"""INSERT INTO t2 (nextid) VALUES ({p})""", (1,))
|
|
cursor.execute(
|
f"""
|
INSERT INTO t1 (id, data) VALUES
|
((SELECT max(t2.nextid) AS max_1 FROM t2), {p}) RETURNING t1.id""",
|
("hi",),
|
)
|
rows = cursor.fetchall()
|
cursor.close()
|
|
conn.close()
|
|
print(f"Connection {conn} succeeded")
|
|
|
mysqldb_conn = MySQLdb.connect(
|
user="scott", password="tiger", host="localhost", db="test"
|
)
|
mariadb_conn = mariadb.connect(
|
user="scott", password="tiger", host="localhost", db="test"
|
)
|
|
|
run_test(mysqldb_conn, "%s")
|
run_test(mariadb_conn, "?")
|
output:
Connection <_mysql.connection closed at 0xc00b40> succeeded
|
Traceback (most recent call last):
|
File "/home/classic/dev/sqlalchemy/test3.py", line 54, in <module>
|
run_test(mariadb_conn, "?")
|
File "/home/classic/dev/sqlalchemy/test3.py", line 31, in run_test
|
cursor.execute(
|
mariadb.InterfaceError: Lost connection to MySQL server during query
|
Attachments
Issue Links
- causes
-
MDEV-28740 crash in INSERT RETURNING subquery in prepared statements
- Closed