Skip to content

Commit

Permalink
fix TTC error receive code 11 during response read as a result of uni…
Browse files Browse the repository at this point in the history
…que constraint with insert-returning
  • Loading branch information
sijms committed Mar 17, 2024
1 parent b04862c commit 495e7c6
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 21 deletions.
7 changes: 7 additions & 0 deletions v2/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -1277,6 +1277,13 @@ func (stmt *Stmt) ExecContext(ctx context.Context, args []driver.NamedValue) (dr
stmt.arrayBindCount = 0
result, err := stmt._exec(args)
if errors.Is(err, network.ErrConnReset) {
if stmt._hasReturnClause {
dataSet := &DataSet{}
err = stmt.read(dataSet)
if !errors.Is(err, network.ErrConnReset) {
return nil, err
}
}
err = stmt.connection.read()
session := stmt.connection.session
if session.Summary != nil {
Expand Down
57 changes: 37 additions & 20 deletions v2/parameter_encode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func TestEncodeValue(t *testing.T) {
// test number
par := &ParameterInfo{Direction: Input}
var err error
err = par.encodeValue(nil, -1, conn)
err = par.encodeValue(-1, conn)
if err != nil {
t.Error(err)
return
Expand All @@ -83,8 +83,8 @@ func TestEncodeValue(t *testing.T) {
t.Error(err)
return
}

err = par.encodeValue(5, -1, conn)
par.Value = 5
err = par.encodeValue(-1, conn)
if err != nil {
t.Error(err)
return
Expand All @@ -101,7 +101,8 @@ func TestEncodeValue(t *testing.T) {
return
}

err = par.encodeValue(10.9, -1, conn)
par.Value = 10.9
err = par.encodeValue(-1, conn)
if err != nil {
t.Error(err)
return
Expand All @@ -118,8 +119,9 @@ func TestEncodeValue(t *testing.T) {
return
}

par.Value = true
// test bool = true
err = par.encodeValue(true, -1, conn)
err = par.encodeValue(-1, conn)
if err != nil {
t.Error(err)
return
Expand All @@ -136,8 +138,9 @@ func TestEncodeValue(t *testing.T) {
return
}

par.Value = false
// test bool = true
err = par.encodeValue(false, -1, conn)
err = par.encodeValue(-1, conn)
if err != nil {
t.Error(err)
return
Expand All @@ -154,8 +157,9 @@ func TestEncodeValue(t *testing.T) {
return
}

par.Value = sql.NullBool{false, true}
// NullBool = false
err = par.encodeValue(sql.NullBool{false, true}, -1, conn)
err = par.encodeValue(-1, conn)
if err != nil {
t.Error(err)
return
Expand All @@ -172,8 +176,9 @@ func TestEncodeValue(t *testing.T) {
return
}

par.Value = sql.NullBool{true, false}
// NullBool = null
err = par.encodeValue(sql.NullBool{true, false}, -1, conn)
err = par.encodeValue(-1, conn)
if err != nil {
t.Error(err)
return
Expand All @@ -188,8 +193,9 @@ func TestEncodeValue(t *testing.T) {
return
}

par.Value = sql.NullInt32{25, true}
// NullInt32
err = par.encodeValue(sql.NullInt32{25, true}, -1, conn)
err = par.encodeValue(-1, conn)
if err != nil {
t.Error(err)
return
Expand All @@ -206,7 +212,8 @@ func TestEncodeValue(t *testing.T) {
return
}

err = par.encodeValue(sql.NullInt32{25, false}, -1, conn)
par.Value = sql.NullInt32{25, false}
err = par.encodeValue(-1, conn)
if err != nil {
t.Error(err)
return
Expand All @@ -222,7 +229,8 @@ func TestEncodeValue(t *testing.T) {
}

stringVal := "this is a test"
err = par.encodeValue(stringVal, -1, conn)
par.Value = stringVal
err = par.encodeValue(-1, conn)
if err != nil {
t.Error(err)
return
Expand All @@ -243,7 +251,8 @@ func TestEncodeValue(t *testing.T) {
return
}

err = par.encodeValue(sql.NullString{stringVal, false}, -1, conn)
par.Value = sql.NullString{stringVal, false}
err = par.encodeValue(-1, conn)
if err != nil {
t.Error(err)
return
Expand All @@ -261,7 +270,8 @@ func TestEncodeValue(t *testing.T) {
return
}

err = par.encodeValue(NVarChar(stringVal), -1, conn)
par.Value = NVarChar(stringVal)
err = par.encodeValue(-1, conn)
if err != nil {
t.Error(err)
return
Expand All @@ -282,7 +292,8 @@ func TestEncodeValue(t *testing.T) {
return
}

err = par.encodeValue(NullNVarChar{NVarChar(stringVal), false}, -1, conn)
par.Value = NullNVarChar{NVarChar(stringVal), false}
err = par.encodeValue(-1, conn)
if err != nil {
t.Error(err)
return
Expand All @@ -301,7 +312,8 @@ func TestEncodeValue(t *testing.T) {
}

timeVal := time.Date(2023, 5, 28, 23, 38, 11, 500, time.Local)
err = par.encodeValue(timeVal, -1, conn)
par.Value = timeVal
err = par.encodeValue(-1, conn)
if err != nil {
t.Error(err)
return
Expand All @@ -320,7 +332,8 @@ func TestEncodeValue(t *testing.T) {
return
}

err = par.encodeValue(sql.NullTime{time.Now(), false}, -1, conn)
par.Value = sql.NullTime{timeVal, false}
err = par.encodeValue(-1, conn)
if err != nil {
t.Error(err)
return
Expand All @@ -335,7 +348,8 @@ func TestEncodeValue(t *testing.T) {
return
}

err = par.encodeValue(TimeStamp(timeVal), -1, conn)
par.Value = TimeStamp(timeVal)
err = par.encodeValue(-1, conn)
if err != nil {
t.Error(err)
return
Expand All @@ -354,7 +368,8 @@ func TestEncodeValue(t *testing.T) {
return
}

err = par.encodeValue(NullTimeStamp{TimeStamp(time.Now()), false}, -1, conn)
par.Value = NullTimeStamp{TimeStamp(time.Now()), false}
err = par.encodeValue(-1, conn)
if err != nil {
t.Error(err)
return
Expand All @@ -369,7 +384,8 @@ func TestEncodeValue(t *testing.T) {
return
}

err = par.encodeValue(TimeStampTZ(timeVal), -1, conn)
par.Value = TimeStampTZ(timeVal)
err = par.encodeValue(-1, conn)
if err != nil {
t.Error(err)
return
Expand All @@ -388,7 +404,8 @@ func TestEncodeValue(t *testing.T) {
return
}

err = par.encodeValue(NullTimeStampTZ{TimeStampTZ(time.Now()), false}, -1, conn)
par.Value = NullTimeStampTZ{TimeStampTZ(time.Now()), false}
err = par.encodeValue(-1, conn)
if err != nil {
t.Error(err)
return
Expand Down
2 changes: 1 addition & 1 deletion v2/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -1424,7 +1424,7 @@ func parseInputField(structValue reflect.Value, name, _type string, fieldIndex i
tempPar.Value = nil
return
}
typeErr := fmt.Errorf("error passing field %s as type %s", fieldValue.Type().Name, _type)
typeErr := fmt.Errorf("error passing field %s as type %s", fieldValue.Type().Name(), _type)
switch _type {
case "number":
//var fieldVal float64
Expand Down

0 comments on commit 495e7c6

Please sign in to comment.