Commit eccf3e9c authored by cznic's avatar cznic

Check defaults/constraints limits. Fixes #195.

	modified:   all_test.go
	modified:   storage.go
parent 3f53e147
......@@ -3925,3 +3925,27 @@ func TestBlobCompare(t *testing.T) {
testBlobSize(t, size)
}
}
// https://github.com/cznic/ql/issues/195
func TestIssue195(t *testing.T) {
db, err := OpenMem()
if err != nil {
t.Fatal(err)
}
ctx := 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)
}
}
......@@ -213,6 +213,10 @@ func (t *table) checkConstraintsAndDefaults(ctx *execCtx, row []interface{}, m m
// 2.
for i, c := range cols {
if i >= len(t.defaults) {
break
}
val := row[c.index]
expr := t.defaults[i]
if val != nil || expr == nil {
......@@ -239,6 +243,10 @@ func (t *table) checkConstraintsAndDefaults(ctx *execCtx, row []interface{}, m m
// 4.
for i, c := range cols {
if i >= len(t.constraints) {
break
}
constraint := t.constraints[i]
if constraint == nil {
continue
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment