blackbeam / rust-mysql-simple

Mysql client library implemented in rust.
Apache License 2.0
658 stars 144 forks source link

Get the actual warning messages from the database #313

Closed ahmedriza closed 2 years ago

ahmedriza commented 2 years ago

We can get the number of warnings from https://docs.rs/mysql/22.1.0/mysql/struct.Conn.html#method.warnings. Is there a way to get the actual warning messages?

The background is that I am using https://docs.rs/mysql/22.1.0/mysql/struct.LocalInfileHandler.html and when the file load fails for some reason (e.g. it couldn't parse the file properly), the database will issue warnings without raising errors and it will be very useful to see what they are in order to diagnose what went wrong.

blackbeam commented 2 years ago

Hi. Have you tried to look into the info (Conn.info_str) or into the output of a SHOW WARNINGS?

ahmedriza commented 2 years ago

Thanks @blackbeam for the pointers.

Ah, realised that I'm actually using mysql_async. Nevertheless, issuing a SHOW WARNINGS afterwards does produce the relevant warnings. So, I guess I could just call SHOW WARNINGS, if the number of warnings is non-zero on the connection.

Since I'm holding on to connection from the Pool, I guess that it is safe to issue the second SHOW WARNINGS query, and no other query would have been executed on that connection in between.

blackbeam commented 2 years ago

Since I'm holding on to connection from the Pool, I guess that it is safe to issue the second SHOW WARNINGS query, and no other query would have been executed on that connection in between.

Yeah, this is safe. You should be careful only in the case when queries are executed directly on a pool (via the Query trait)

ahmedriza commented 2 years ago

Cheers @blackbeam