[error] add SQLSTATE values to exceptions and factor out constant queries in the metadata class