Extract more error information

pull/37/head
Jack Christensen 2014-09-15 14:52:32 -05:00
parent 92cbc6566d
commit a5f082fa03
2 changed files with 27 additions and 3 deletions

14
conn.go
View File

@ -676,6 +676,20 @@ func (c *Conn) rxErrorResponse(r *msgReader) (err PgError) {
err.Code = r.readCString()
case 'M':
err.Message = r.readCString()
case 'D':
err.Detail = r.readCString()
case 'H':
err.Hint = r.readCString()
case 's':
err.SchemaName = r.readCString()
case 't':
err.TableName = r.readCString()
case 'c':
err.ColumnName = r.readCString()
case 'd':
err.DataTypeName = r.readCString()
case 'n':
err.ConstraintName = r.readCString()
case 0: // End of error message
if err.Severity == "FATAL" {
c.die(err)

View File

@ -60,10 +60,20 @@ type FieldDescription struct {
FormatCode int16
}
// PgError represents an error reported by the PostgreSQL server. See
// http://www.postgresql.org/docs/9.3/static/protocol-error-fields.html for
// detailed field description.
type PgError struct {
Severity string
Code string
Message string
Severity string
Code string
Message string
Detail string
Hint string
SchemaName string
TableName string
ColumnName string
DataTypeName string
ConstraintName string
}
func (self PgError) Error() string {