Permalink
Browse files

Check defaults/constraints limits. Fixes #195.

	modified:   all_test.go
	modified:   storage.go
  • Loading branch information...
cznic committed Feb 28, 2018
1 parent 3f53e14 commit eccf3e9caa43fab70d7ddfdee5c3fb73fc76c2a1
Showing with 32 additions and 0 deletions.
  1. +24 −0 all_test.go
  2. +8 −0 storage.go
View
@@ -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)
}
}
View
@@ -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

0 comments on commit eccf3e9

Please sign in to comment.