mirror of https://github.com/jackc/pgx.git
Add more error fields to PgError
parent
784d12cbbc
commit
5bb7f64dac
21
conn.go
21
conn.go
|
@ -812,6 +812,18 @@ func (c *Conn) rxErrorResponse(r *msgReader) (err PgError) {
|
|||
err.Detail = r.readCString()
|
||||
case 'H':
|
||||
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':
|
||||
err.SchemaName = r.readCString()
|
||||
case 't':
|
||||
|
@ -822,6 +834,15 @@ func (c *Conn) rxErrorResponse(r *msgReader) (err PgError) {
|
|||
err.DataTypeName = r.readCString()
|
||||
case 'n':
|
||||
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
|
||||
if err.Severity == "FATAL" {
|
||||
c.die(err)
|
||||
|
|
27
messages.go
27
messages.go
|
@ -66,16 +66,23 @@ type FieldDescription struct {
|
|||
// 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
|
||||
Detail string
|
||||
Hint string
|
||||
SchemaName string
|
||||
TableName string
|
||||
ColumnName string
|
||||
DataTypeName string
|
||||
ConstraintName string
|
||||
Severity string
|
||||
Code string
|
||||
Message string
|
||||
Detail string
|
||||
Hint string
|
||||
Position int32
|
||||
InternalPosition int32
|
||||
InternalQuery string
|
||||
Where string
|
||||
SchemaName string
|
||||
TableName string
|
||||
ColumnName string
|
||||
DataTypeName string
|
||||
ConstraintName string
|
||||
File string
|
||||
Line int32
|
||||
Routine string
|
||||
}
|
||||
|
||||
func (self PgError) Error() string {
|
||||
|
|
Loading…
Reference in New Issue