Add support for SQLSTATE

This commit adds the backend code to get the mysql SQLSTATE error code (to be used when displaying errors).