2
0

Add more error fields to PgError

This commit is contained in:
Jack Christensen
2015-05-01 18:06:17 -05:00
parent 784d12cbbc
commit 5bb7f64dac
2 changed files with 38 additions and 10 deletions
+21
View File
@@ -812,6 +812,18 @@ func (c *Conn) rxErrorResponse(r *msgReader) (err PgError) {
err.Detail = r.readCString() err.Detail = r.readCString()
case 'H': case 'H':
err.Hint = r.readCString() err.Hint = r.readCString()
case 'P':
s := r.readCString()
n, _ := strconv.ParseInt(s, 10, 32)
err.Position = int32(n)
case 'p':
s := r.readCString()
n, _ := strconv.ParseInt(s, 10, 32)
err.InternalPosition = int32(n)
case 'q':
err.InternalQuery = r.readCString()
case 'W':
err.Where = r.readCString()
case 's': case 's':
err.SchemaName = r.readCString() err.SchemaName = r.readCString()
case 't': case 't':
@@ -822,6 +834,15 @@ func (c *Conn) rxErrorResponse(r *msgReader) (err PgError) {
err.DataTypeName = r.readCString() err.DataTypeName = r.readCString()
case 'n': case 'n':
err.ConstraintName = r.readCString() err.ConstraintName = r.readCString()
case 'F':
err.File = r.readCString()
case 'L':
s := r.readCString()
n, _ := strconv.ParseInt(s, 10, 32)
err.Line = int32(n)
case 'R':
err.Routine = r.readCString()
case 0: // End of error message case 0: // End of error message
if err.Severity == "FATAL" { if err.Severity == "FATAL" {
c.die(err) c.die(err)
+17 -10
View File
@@ -66,16 +66,23 @@ type FieldDescription struct {
// http://www.postgresql.org/docs/9.3/static/protocol-error-fields.html for // http://www.postgresql.org/docs/9.3/static/protocol-error-fields.html for
// detailed field description. // detailed field description.
type PgError struct { type PgError struct {
Severity string Severity string
Code string Code string
Message string Message string
Detail string Detail string
Hint string Hint string
SchemaName string Position int32
TableName string InternalPosition int32
ColumnName string InternalQuery string
DataTypeName string Where string
ConstraintName string SchemaName string
TableName string
ColumnName string
DataTypeName string
ConstraintName string
File string
Line int32
Routine string
} }
func (self PgError) Error() string { func (self PgError) Error() string {