Home > Software design >  How to have specific information in mariadb.Error [Python]
How to have specific information in mariadb.Error [Python]

Time:11-04

I'm trying to have some specific information on a mariadb.Error. After the execution of an INSERT, with executemany(), I want to have, every time, the information about the problematical line. But I received two different types of errors.

For example when I have an error about a wrong data type, I have something like:

Invalid parameter type at row 2, column 4 

When I have an error about a constraint not respected, I have something like:

Cannot add or update a child row: a foreign key constraint fails

But on the second case, I would like to have something like :

Cannot add or update a child row: a foreign key constraint fails at row X, column Y

Is it possible ? Can I configure mariadb.Error to have, always, the row/column detail ?

CodePudding user response:

No, this is not possible.

The first error (Invalid parameter type at row 2, column 4) is generated by the MariaDB python driver: Before sending the execution request and data to the server, the driver checks if all columns have the same datatype, if not he will raise the exception above.

Afterwards, the driver sends a COM_STMT_BULK_EXECUTE command followed by all data to the server. The second error message (a foreign key constraint fails) was generated by the server, since the specified data violated one or more constraints. Unfortunately, the server doesn't give any hint which value in which row caused this error, so the driver can only raise this exception.

I agree, that this would be a useful feature and have submitted an issue (MDEV-29945) to the MariaDB bug tracking system.

  • Related