Science, asked by anjalijoshi5924, 1 year ago

How to process error messages using MySQL Proxy in lua script?

Answers

Answered by Samarthattituded
1
Answer}

It only logs errors and not warnings. Originally it manages an 'error flag' which is set to true if the client's query returns an error. I changed that in order to log every query for which SHOW WARNINGS returns something (Errors, Warnings or Notes).

It inserted errors log lines into a table. It could be nice but can be quite confusing for the client, because inserting the log line clears the messages shown by 'show warnings' query. There's probably a way to fix that, opening a new session or connexion... but I choosed to log events into a simple text file. Secondarily, the insert query in the original script can generate a syntax error because of the simple quotes ' possibly contained in the error message or original query.

There is a point at which we must be careful when logging all warnings : all queries don't clear the warnings/notes queue. So SHOW WARNINGScan return a resultset generated by a previous query after a non-warning-generating query. To fix that, I use a dirty method : after detecting a query, I inject a bad query for which I know it will generate an error message; after what I ignore this error message. It's a way to "clear" warnings and notes...
follow for more answers
Similar questions