Execute failures don't break connection
This commit is contained in:
+7
-7
@@ -142,7 +142,9 @@ func (c *Connection) SelectFunc(sql string, onDataRow func(*DataRowReader) error
|
|||||||
case commandComplete:
|
case commandComplete:
|
||||||
case bindComplete:
|
case bindComplete:
|
||||||
default:
|
default:
|
||||||
err = c.processContextFreeMsg(t, r)
|
if e := c.processContextFreeMsg(t, r); e != nil && err == nil {
|
||||||
|
err = e
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return rxErr
|
return rxErr
|
||||||
@@ -406,9 +408,7 @@ func (c *Connection) Execute(sql string, arguments ...interface{}) (commandTag s
|
|||||||
}
|
}
|
||||||
|
|
||||||
for {
|
for {
|
||||||
var t byte
|
if t, r, rxErr := c.rxMsg(); rxErr == nil {
|
||||||
var r *MessageReader
|
|
||||||
if t, r, err = c.rxMsg(); err == nil {
|
|
||||||
switch t {
|
switch t {
|
||||||
case readyForQuery:
|
case readyForQuery:
|
||||||
return
|
return
|
||||||
@@ -418,12 +418,12 @@ func (c *Connection) Execute(sql string, arguments ...interface{}) (commandTag s
|
|||||||
case commandComplete:
|
case commandComplete:
|
||||||
commandTag = r.ReadString()
|
commandTag = r.ReadString()
|
||||||
default:
|
default:
|
||||||
if err = c.processContextFreeMsg(t, r); err != nil {
|
if e := c.processContextFreeMsg(t, r); e != nil && err == nil {
|
||||||
return
|
err = e
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return
|
return "", rxErr
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -179,7 +179,22 @@ func TestExecute(t *testing.T) {
|
|||||||
if results != "SELECT 1" {
|
if results != "SELECT 1" {
|
||||||
t.Errorf("Unexpected results from Execute: %v", results)
|
t.Errorf("Unexpected results from Execute: %v", results)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestExecuteFailure(t *testing.T) {
|
||||||
|
conn, err := Connect(*defaultConnectionParameters)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Unable to establish connection: %v", err)
|
||||||
|
}
|
||||||
|
defer conn.Close()
|
||||||
|
|
||||||
|
if _, err := conn.Execute("select;"); err == nil {
|
||||||
|
t.Fatal("Expected SQL syntax error")
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := conn.SelectValue("select 1"); err != nil {
|
||||||
|
t.Fatalf("Execute failure appears to have broken connection: %v", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSelectFunc(t *testing.T) {
|
func TestSelectFunc(t *testing.T) {
|
||||||
@@ -204,6 +219,23 @@ func TestSelectFunc(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestSelectFuncFailure(t *testing.T) {
|
||||||
|
conn, err := Connect(*defaultConnectionParameters)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Unable to establish connection: %v", err)
|
||||||
|
}
|
||||||
|
defer conn.Close()
|
||||||
|
|
||||||
|
// using SelectValue as it delegates to SelectFunc and is easier to work with
|
||||||
|
if _, err := conn.SelectValue("select;"); err == nil {
|
||||||
|
t.Fatal("Expected SQL syntax error")
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := conn.SelectValue("select 1"); err != nil {
|
||||||
|
t.Fatalf("SelectFunc failure appears to have broken connection: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestSelectRows(t *testing.T) {
|
func TestSelectRows(t *testing.T) {
|
||||||
conn := getSharedConnection()
|
conn := getSharedConnection()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user