"ALTER TABLE" then "INSERT" yields "panic: runtime error: index out of range [recovered]"
Created by: Mparaiso
Hi, first thank you very much for your great work.
This test panics when trying to insert a record after an ALTER TABLE :
package main_test
import (
"github.com/cznic/ql"
"testing"
)
func TestMain(t *testing.T) {
db, err := ql.OpenMem()
if err != nil {
t.Fatal(err)
}
ctx := ql.NewRWCtx()
_, index, err := db.Run(ctx, `
BEGIN TRANSACTION;
CREATE TABLE users(
firstname string NOT NULL,
lastname string NOT NULL,
createdAt time NOT NULL DEFAULT now(),
);
ALTER TABLE users ADD username string;
INSERT INTO users(username,firstname,lastname) values("john_doe","john","doe");
COMMIT;
`)
if err != nil {
t.Fatal(err, " index :", index)
}
}
go test -tags purego
--- FAIL: TestMain (0.00s)
panic: runtime error: index out of range [recovered]
panic: runtime error: index out of range
goroutine 5 [running]:
testing.tRunner.func1(0xc4201780f0)
/usr/local/go/src/testing/testing.go:711 +0x2d2
panic(0x8053c0, 0xa78340)
/usr/local/go/src/runtime/panic.go:491 +0x283
github.com/cznic/ql.(*table).checkConstraintsAndDefaults(0xc4201784b0, 0xc420184b40, 0xc420184b80, 0x4, 0x4, 0xc420175380, 0x0, 0x0)
/home/ubuntu/workspace/src/github.com/cznic/ql/storage.go:217 +0xa08
github.com/cznic/ql.(*insertIntoStmt).exec(0xc4200845a0, 0xc420184b40, 0xc420175350, 0x0, 0xc420175350, 0x0)
/home/ubuntu/workspace/src/github.com/cznic/ql/stmt.go:1014 +0x4f2
github.com/cznic/ql.(*DB).run1(0xc42017a000, 0xc4200170f0, 0x2ba4e4eca110, 0xc4200845a0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, ...)
/home/ubuntu/workspace/src/github.com/cznic/ql/ql.go:1424 +0x989
github.com/cznic/ql.(*DB).Execute(0xc42017a000, 0xc4200170f0, 0xc42015a280, 0x5, 0x8, 0x0, 0x0, 0x0, 0x0, 0xc420049ed0, ...)
/home/ubuntu/workspace/src/github.com/cznic/ql/ql.go:1259 +0x987
github.com/cznic/ql.(*DB).Run(0xc42017a000, 0xc4200170f0, 0x8889fe, 0x128, 0x0, 0x0, 0x0, 0xff, 0xc420037f40, 0x45ec86, ...)
/home/ubuntu/workspace/src/github.com/cznic/ql/ql.go:1076 +0xe3
github.com/camus/ql_test_test.TestMain(0xc4201780f0)
/home/ubuntu/workspace/src/github.com/camus/ql_test/main_test.go:14 +0xf1
testing.tRunner(0xc4201780f0, 0x88ea80)
/usr/local/go/src/testing/testing.go:746 +0xd0
created by testing.(*T).Run
/usr/local/go/src/testing/testing.go:789 +0x2de
exit status 2
FAIL github.com/camus/ql_test 0.011s
this test was both run on windows and linux with this go env :
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/ubuntu/workspace"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build692928219=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"