Skip to content

Commit

Permalink
Fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
ncruces committed Jun 19, 2024
1 parent 5c1c0f0 commit e226609
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 33 deletions.
14 changes: 9 additions & 5 deletions ext/bloom/bloom.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ func create(db *sqlite3.Conn, _, schema, table string, arg ...string) (_ *bloom,
return nil, err
}

id := db.LastInsertRowID()
defer db.SetLastInsertRowID(id)

err = db.Exec(fmt.Sprintf(
`INSERT INTO %s.%s (rowid, data, p, n, m, k)
VALUES (1, zeroblob(%d), %f, %d, %d, %d)`,
Expand Down Expand Up @@ -163,13 +166,14 @@ func (b *bloom) BestIndex(idx *sqlite3.IndexInfo) error {
if cst.Usable && cst.Column == 1 &&
cst.Op == sqlite3.INDEX_CONSTRAINT_EQ {
idx.ConstraintUsage[n].ArgvIndex = 1
idx.OrderByConsumed = true
idx.EstimatedRows = 1
idx.EstimatedCost = float64(b.hashes)
idx.IdxFlags = sqlite3.INDEX_SCAN_UNIQUE
return nil
}
}
idx.OrderByConsumed = true
idx.EstimatedRows = 1
idx.EstimatedCost = float64(b.hashes)
idx.IdxFlags = sqlite3.INDEX_SCAN_UNIQUE
return nil
return sqlite3.CONSTRAINT
}

func (b *bloom) Update(arg ...sqlite3.Value) (rowid int64, err error) {
Expand Down
6 changes: 5 additions & 1 deletion ext/csv/csv.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,11 @@ func RegisterFS(db *sqlite3.Conn, fsys fs.FS) {
}
schema = getSchema(header, columns, row)
} else {
table.typs = getColumnAffinities(schema)
defer func() {
if err == nil {
table.typs, err = getColumnAffinities(schema)
}
}()
}

err = db.DeclareVTab(schema)
Expand Down
6 changes: 3 additions & 3 deletions ext/csv/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ const (
real affinity = 4
)

func getColumnAffinities(schema string) []affinity {
func getColumnAffinities(schema string) ([]affinity, error) {
tab, err := vtabutil.Parse(schema)
if err != nil {
return nil
return nil, err
}
defer tab.Close()

Expand All @@ -29,7 +29,7 @@ func getColumnAffinities(schema string) []affinity {
col := tab.Column(i)
types[i] = getAffinity(col.Type())
}
return types
return types, nil
}

func getAffinity(declType string) affinity {
Expand Down
35 changes: 11 additions & 24 deletions util/vtabutil/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ import (
)

const (
_NONE = iota
_MEMORY
_SYNTAX
_UNSUPPORTEDSQL

code = 4
base = 8
)
Expand Down Expand Up @@ -56,11 +61,13 @@ func Parse(sql string) (*Table, error) {
}

c, _ := mod.Memory().ReadUint32Le(code)
if c == uint32(_MEMORY) {
switch c {
case _MEMORY:
panic(util.OOMErr)
}
if c != uint32(_NONE) {
return nil, ecode(c)
case _SYNTAX:
return nil, util.ErrorString("sql3parse: invalid syntax")
case _UNSUPPORTEDSQL:
return nil, util.ErrorString("sql3parse: unsupported SQL")
}
if r[0] == 0 {
return nil, nil
Expand Down Expand Up @@ -123,23 +130,3 @@ func (c Column) Type() string {
len, _ := c.tab.mod.Memory().ReadUint32Le(uint32(r[0]) + 4)
return c.tab.sql[off-base : off+len-base]
}

type ecode uint32

const (
_NONE ecode = iota
_MEMORY
_SYNTAX
_UNSUPPORTEDSQL
)

func (e ecode) Error() string {
switch e {
case _SYNTAX:
return "sql3parse: invalid syntax"
case _UNSUPPORTEDSQL:
return "sql3parse: unsupported SQL"
default:
panic(util.AssertErr())
}
}

0 comments on commit e226609

Please sign in to comment.