diff options
Diffstat (limited to 'vendor/github.com/ncruces/go-sqlite3/util')
10 files changed, 0 insertions, 520 deletions
diff --git a/vendor/github.com/ncruces/go-sqlite3/util/osutil/open.go b/vendor/github.com/ncruces/go-sqlite3/util/osutil/open.go deleted file mode 100644 index 0242ad032..000000000 --- a/vendor/github.com/ncruces/go-sqlite3/util/osutil/open.go +++ /dev/null @@ -1,16 +0,0 @@ -//go:build !windows - -package osutil - -import ( - "io/fs" - "os" -) - -// OpenFile behaves the same as [os.OpenFile], -// except on Windows it sets [syscall.FILE_SHARE_DELETE]. -// -// See: https://go.dev/issue/32088#issuecomment-502850674 -func OpenFile(name string, flag int, perm fs.FileMode) (*os.File, error) { - return os.OpenFile(name, flag, perm) -} diff --git a/vendor/github.com/ncruces/go-sqlite3/util/osutil/open_windows.go b/vendor/github.com/ncruces/go-sqlite3/util/osutil/open_windows.go deleted file mode 100644 index febaf846e..000000000 --- a/vendor/github.com/ncruces/go-sqlite3/util/osutil/open_windows.go +++ /dev/null @@ -1,115 +0,0 @@ -package osutil - -import ( - "io/fs" - "os" - . "syscall" - "unsafe" -) - -// OpenFile behaves the same as [os.OpenFile], -// except on Windows it sets [syscall.FILE_SHARE_DELETE]. -// -// See: https://go.dev/issue/32088#issuecomment-502850674 -func OpenFile(name string, flag int, perm fs.FileMode) (*os.File, error) { - if name == "" { - return nil, &os.PathError{Op: "open", Path: name, Err: ENOENT} - } - r, e := syscallOpen(name, flag|O_CLOEXEC, uint32(perm.Perm())) - if e != nil { - return nil, &os.PathError{Op: "open", Path: name, Err: e} - } - return os.NewFile(uintptr(r), name), nil -} - -// syscallOpen is a copy of [syscall.Open] -// that uses [syscall.FILE_SHARE_DELETE]. -// -// https://go.dev/src/syscall/syscall_windows.go -func syscallOpen(path string, mode int, perm uint32) (fd Handle, err error) { - if len(path) == 0 { - return InvalidHandle, ERROR_FILE_NOT_FOUND - } - pathp, err := UTF16PtrFromString(path) - if err != nil { - return InvalidHandle, err - } - var access uint32 - switch mode & (O_RDONLY | O_WRONLY | O_RDWR) { - case O_RDONLY: - access = GENERIC_READ - case O_WRONLY: - access = GENERIC_WRITE - case O_RDWR: - access = GENERIC_READ | GENERIC_WRITE - } - if mode&O_CREAT != 0 { - access |= GENERIC_WRITE - } - if mode&O_APPEND != 0 { - access &^= GENERIC_WRITE - access |= FILE_APPEND_DATA - } - sharemode := uint32(FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE) - var sa *SecurityAttributes - if mode&O_CLOEXEC == 0 { - sa = makeInheritSa() - } - var createmode uint32 - switch { - case mode&(O_CREAT|O_EXCL) == (O_CREAT | O_EXCL): - createmode = CREATE_NEW - case mode&(O_CREAT|O_TRUNC) == (O_CREAT | O_TRUNC): - createmode = CREATE_ALWAYS - case mode&O_CREAT == O_CREAT: - createmode = OPEN_ALWAYS - case mode&O_TRUNC == O_TRUNC: - createmode = TRUNCATE_EXISTING - default: - createmode = OPEN_EXISTING - } - var attrs uint32 = FILE_ATTRIBUTE_NORMAL - if perm&S_IWRITE == 0 { - attrs = FILE_ATTRIBUTE_READONLY - if createmode == CREATE_ALWAYS { - const _ERROR_BAD_NETPATH = Errno(53) - // We have been asked to create a read-only file. - // If the file already exists, the semantics of - // the Unix open system call is to preserve the - // existing permissions. If we pass CREATE_ALWAYS - // and FILE_ATTRIBUTE_READONLY to CreateFile, - // and the file already exists, CreateFile will - // change the file permissions. - // Avoid that to preserve the Unix semantics. - h, e := CreateFile(pathp, access, sharemode, sa, TRUNCATE_EXISTING, FILE_ATTRIBUTE_NORMAL, 0) - switch e { - case ERROR_FILE_NOT_FOUND, _ERROR_BAD_NETPATH, ERROR_PATH_NOT_FOUND: - // File does not exist. These are the same - // errors as Errno.Is checks for ErrNotExist. - // Carry on to create the file. - default: - // Success or some different error. - return h, e - } - } - } - if createmode == OPEN_EXISTING && access == GENERIC_READ { - // Necessary for opening directory handles. - attrs |= FILE_FLAG_BACKUP_SEMANTICS - } - if mode&O_SYNC != 0 { - const _FILE_FLAG_WRITE_THROUGH = 0x80000000 - attrs |= _FILE_FLAG_WRITE_THROUGH - } - if mode&O_NONBLOCK != 0 { - attrs |= FILE_FLAG_OVERLAPPED - } - return CreateFile(pathp, access, sharemode, sa, createmode, attrs, 0) -} - -func makeInheritSa() *SecurityAttributes { - var sa SecurityAttributes - sa.Length = uint32(unsafe.Sizeof(sa)) - sa.InheritHandle = 1 - return &sa -} diff --git a/vendor/github.com/ncruces/go-sqlite3/util/osutil/osfs.go b/vendor/github.com/ncruces/go-sqlite3/util/osutil/osfs.go deleted file mode 100644 index 2e1195934..000000000 --- a/vendor/github.com/ncruces/go-sqlite3/util/osutil/osfs.go +++ /dev/null @@ -1,33 +0,0 @@ -package osutil - -import ( - "io/fs" - "os" -) - -// FS implements [fs.FS], [fs.StatFS], and [fs.ReadFileFS] -// using package [os]. -// -// This filesystem does not respect [fs.ValidPath] rules, -// and fails [testing/fstest.TestFS]! -// -// Still, it can be a useful tool to unify implementations -// that can access either the [os] filesystem or an [fs.FS]. -// It's OK to use this to open files, but you should avoid -// opening directories, resolving paths, or walking the file system. -type FS struct{} - -// Open implements [fs.FS]. -func (FS) Open(name string) (fs.File, error) { - return OpenFile(name, os.O_RDONLY, 0) -} - -// ReadFileFS implements [fs.StatFS]. -func (FS) Stat(name string) (fs.FileInfo, error) { - return os.Stat(name) -} - -// ReadFile implements [fs.ReadFileFS]. -func (FS) ReadFile(name string) ([]byte, error) { - return os.ReadFile(name) -} diff --git a/vendor/github.com/ncruces/go-sqlite3/util/osutil/osutil.go b/vendor/github.com/ncruces/go-sqlite3/util/osutil/osutil.go deleted file mode 100644 index 83444e906..000000000 --- a/vendor/github.com/ncruces/go-sqlite3/util/osutil/osutil.go +++ /dev/null @@ -1,2 +0,0 @@ -// Package osutil implements operating system utilities. -package osutil diff --git a/vendor/github.com/ncruces/go-sqlite3/util/sql3util/README.md b/vendor/github.com/ncruces/go-sqlite3/util/sql3util/README.md deleted file mode 100644 index 9f47f5a9f..000000000 --- a/vendor/github.com/ncruces/go-sqlite3/util/sql3util/README.md +++ /dev/null @@ -1,9 +0,0 @@ -# SQLite utility functions - -This package implements assorted SQLite utilities -useful to extension writers. - -It also wraps a [parser](https://github.com/marcobambini/sqlite-createtable-parser) -for the [`CREATE`](https://sqlite.org/lang_createtable.html) and -[`ALTER TABLE`](https://sqlite.org/lang_altertable.html) commands, -created by [Marco Bambini](https://github.com/marcobambini).
\ No newline at end of file diff --git a/vendor/github.com/ncruces/go-sqlite3/util/sql3util/arg.go b/vendor/github.com/ncruces/go-sqlite3/util/sql3util/arg.go deleted file mode 100644 index 3e8c728b0..000000000 --- a/vendor/github.com/ncruces/go-sqlite3/util/sql3util/arg.go +++ /dev/null @@ -1,65 +0,0 @@ -package sql3util - -import "strings" - -// NamedArg splits an named arg into a key and value, -// around an equals sign. -// Spaces are trimmed around both key and value. -func NamedArg(arg string) (key, val string) { - key, val, _ = strings.Cut(arg, "=") - key = strings.TrimSpace(key) - val = strings.TrimSpace(val) - return -} - -// Unquote unquotes a string. -// -// https://sqlite.org/lang_keywords.html -func Unquote(val string) string { - if len(val) < 2 { - return val - } - fst := val[0] - lst := val[len(val)-1] - rst := val[1 : len(val)-1] - if fst == '[' && lst == ']' { - return rst - } - if fst != lst { - return val - } - var old, new string - switch fst { - default: - return val - case '`': - old, new = "``", "`" - case '"': - old, new = `""`, `"` - case '\'': - old, new = `''`, `'` - } - return strings.ReplaceAll(rst, old, new) -} - -// ParseBool parses a boolean. -// -// https://sqlite.org/pragma.html#syntax -func ParseBool(s string) (b, ok bool) { - if len(s) == 0 { - return false, false - } - if s[0] == '0' { - return false, true - } - if '1' <= s[0] && s[0] <= '9' { - return true, true - } - switch strings.ToLower(s) { - case "true", "yes", "on": - return true, true - case "false", "no", "off": - return false, true - } - return false, false -} diff --git a/vendor/github.com/ncruces/go-sqlite3/util/sql3util/const.go b/vendor/github.com/ncruces/go-sqlite3/util/sql3util/const.go deleted file mode 100644 index 10e8af35a..000000000 --- a/vendor/github.com/ncruces/go-sqlite3/util/sql3util/const.go +++ /dev/null @@ -1,61 +0,0 @@ -package sql3util - -const ( - _NONE = iota - _MEMORY - _SYNTAX - _UNSUPPORTEDSQL -) - -type ConflictClause uint32 - -const ( - CONFLICT_NONE ConflictClause = iota - CONFLICT_ROLLBACK - CONFLICT_ABORT - CONFLICT_FAIL - CONFLICT_IGNORE - CONFLICT_REPLACE -) - -type OrderClause uint32 - -const ( - ORDER_NONE OrderClause = iota - ORDER_ASC - ORDER_DESC -) - -type FKAction uint32 - -const ( - FKACTION_NONE FKAction = iota - FKACTION_SETNULL - FKACTION_SETDEFAULT - FKACTION_CASCADE - FKACTION_RESTRICT - FKACTION_NOACTION -) - -type FKDefType uint32 - -const ( - DEFTYPE_NONE FKDefType = iota - DEFTYPE_DEFERRABLE - DEFTYPE_DEFERRABLE_INITIALLY_DEFERRED - DEFTYPE_DEFERRABLE_INITIALLY_IMMEDIATE - DEFTYPE_NOTDEFERRABLE - DEFTYPE_NOTDEFERRABLE_INITIALLY_DEFERRED - DEFTYPE_NOTDEFERRABLE_INITIALLY_IMMEDIATE -) - -type StatementType uint32 - -const ( - CREATE_UNKNOWN StatementType = iota - CREATE_TABLE - ALTER_RENAME_TABLE - ALTER_RENAME_COLUMN - ALTER_ADD_COLUMN - ALTER_DROP_COLUMN -) diff --git a/vendor/github.com/ncruces/go-sqlite3/util/sql3util/parse.go b/vendor/github.com/ncruces/go-sqlite3/util/sql3util/parse.go deleted file mode 100644 index 7dd76ceb1..000000000 --- a/vendor/github.com/ncruces/go-sqlite3/util/sql3util/parse.go +++ /dev/null @@ -1,210 +0,0 @@ -package sql3util - -import ( - "context" - _ "embed" - "sync" - - "github.com/tetratelabs/wazero" - "github.com/tetratelabs/wazero/api" - - "github.com/ncruces/go-sqlite3/internal/util" -) - -const ( - errp = 4 - sqlp = 8 -) - -var ( - //go:embed wasm/sql3parse_table.wasm - binary []byte - once sync.Once - runtime wazero.Runtime - compiled wazero.CompiledModule -) - -// ParseTable parses a [CREATE] or [ALTER TABLE] command. -// -// [CREATE]: https://sqlite.org/lang_createtable.html -// [ALTER TABLE]: https://sqlite.org/lang_altertable.html -func ParseTable(sql string) (_ *Table, err error) { - once.Do(func() { - ctx := context.Background() - cfg := wazero.NewRuntimeConfigInterpreter() - runtime = wazero.NewRuntimeWithConfig(ctx, cfg) - compiled, err = runtime.CompileModule(ctx, binary) - }) - if err != nil { - return nil, err - } - - ctx := context.Background() - mod, err := runtime.InstantiateModule(ctx, compiled, wazero.NewModuleConfig().WithName("")) - if err != nil { - return nil, err - } - defer mod.Close(ctx) - - if buf, ok := mod.Memory().Read(sqlp, uint32(len(sql))); ok { - copy(buf, sql) - } - - stack := [...]util.Stk_t{sqlp, util.Stk_t(len(sql)), errp} - err = mod.ExportedFunction("sql3parse_table").CallWithStack(ctx, stack[:]) - if err != nil { - return nil, err - } - - c, _ := mod.Memory().ReadUint32Le(errp) - switch c { - case _MEMORY: - panic(util.OOMErr) - case _SYNTAX: - return nil, util.ErrorString("sql3parse: invalid syntax") - case _UNSUPPORTEDSQL: - return nil, util.ErrorString("sql3parse: unsupported SQL") - } - - var tab Table - tab.load(mod, uint32(stack[0]), sql) - return &tab, nil -} - -// Table holds metadata about a table. -type Table struct { - Name string - Schema string - Comment string - IsTemporary bool - IsIfNotExists bool - IsWithoutRowID bool - IsStrict bool - Columns []Column - Type StatementType - CurrentName string - NewName string -} - -func (t *Table) load(mod api.Module, ptr uint32, sql string) { - t.Name = loadString(mod, ptr+0, sql) - t.Schema = loadString(mod, ptr+8, sql) - t.Comment = loadString(mod, ptr+16, sql) - - t.IsTemporary = loadBool(mod, ptr+24) - t.IsIfNotExists = loadBool(mod, ptr+25) - t.IsWithoutRowID = loadBool(mod, ptr+26) - t.IsStrict = loadBool(mod, ptr+27) - - t.Columns = loadSlice(mod, ptr+28, func(ptr uint32, ret *Column) { - p, _ := mod.Memory().ReadUint32Le(ptr) - ret.load(mod, p, sql) - }) - - t.Type = loadEnum[StatementType](mod, ptr+44) - t.CurrentName = loadString(mod, ptr+48, sql) - t.NewName = loadString(mod, ptr+56, sql) -} - -// Column holds metadata about a column. -type Column struct { - Name string - Type string - Length string - ConstraintName string - Comment string - IsPrimaryKey bool - IsAutoIncrement bool - IsNotNull bool - IsUnique bool - PKOrder OrderClause - PKConflictClause ConflictClause - NotNullConflictClause ConflictClause - UniqueConflictClause ConflictClause - CheckExpr string - DefaultExpr string - CollateName string - ForeignKeyClause *ForeignKey -} - -func (c *Column) load(mod api.Module, ptr uint32, sql string) { - c.Name = loadString(mod, ptr+0, sql) - c.Type = loadString(mod, ptr+8, sql) - c.Length = loadString(mod, ptr+16, sql) - c.ConstraintName = loadString(mod, ptr+24, sql) - c.Comment = loadString(mod, ptr+32, sql) - - c.IsPrimaryKey = loadBool(mod, ptr+40) - c.IsAutoIncrement = loadBool(mod, ptr+41) - c.IsNotNull = loadBool(mod, ptr+42) - c.IsUnique = loadBool(mod, ptr+43) - - c.PKOrder = loadEnum[OrderClause](mod, ptr+44) - c.PKConflictClause = loadEnum[ConflictClause](mod, ptr+48) - c.NotNullConflictClause = loadEnum[ConflictClause](mod, ptr+52) - c.UniqueConflictClause = loadEnum[ConflictClause](mod, ptr+56) - - c.CheckExpr = loadString(mod, ptr+60, sql) - c.DefaultExpr = loadString(mod, ptr+68, sql) - c.CollateName = loadString(mod, ptr+76, sql) - - if ptr, _ := mod.Memory().ReadUint32Le(ptr + 84); ptr != 0 { - c.ForeignKeyClause = &ForeignKey{} - c.ForeignKeyClause.load(mod, ptr, sql) - } -} - -type ForeignKey struct { - Table string - Columns []string - OnDelete FKAction - OnUpdate FKAction - Match string - Deferrable FKDefType -} - -func (f *ForeignKey) load(mod api.Module, ptr uint32, sql string) { - f.Table = loadString(mod, ptr+0, sql) - - f.Columns = loadSlice(mod, ptr+8, func(ptr uint32, ret *string) { - *ret = loadString(mod, ptr, sql) - }) - - f.OnDelete = loadEnum[FKAction](mod, ptr+16) - f.OnUpdate = loadEnum[FKAction](mod, ptr+20) - f.Match = loadString(mod, ptr+24, sql) - f.Deferrable = loadEnum[FKDefType](mod, ptr+32) -} - -func loadString(mod api.Module, ptr uint32, sql string) string { - off, _ := mod.Memory().ReadUint32Le(ptr + 0) - if off == 0 { - return "" - } - len, _ := mod.Memory().ReadUint32Le(ptr + 4) - return sql[off-sqlp : off+len-sqlp] -} - -func loadSlice[T any](mod api.Module, ptr uint32, fn func(uint32, *T)) []T { - ref, _ := mod.Memory().ReadUint32Le(ptr + 4) - if ref == 0 { - return nil - } - len, _ := mod.Memory().ReadUint32Le(ptr + 0) - ret := make([]T, len) - for i := range ret { - fn(ref, &ret[i]) - ref += 4 - } - return ret -} - -func loadEnum[T ~uint32](mod api.Module, ptr uint32) T { - val, _ := mod.Memory().ReadUint32Le(ptr) - return T(val) -} - -func loadBool(mod api.Module, ptr uint32) bool { - val, _ := mod.Memory().ReadByte(ptr) - return val != 0 -} diff --git a/vendor/github.com/ncruces/go-sqlite3/util/sql3util/sql3util.go b/vendor/github.com/ncruces/go-sqlite3/util/sql3util/sql3util.go deleted file mode 100644 index 6be61927d..000000000 --- a/vendor/github.com/ncruces/go-sqlite3/util/sql3util/sql3util.go +++ /dev/null @@ -1,9 +0,0 @@ -// Package sql3util implements SQLite utilities. -package sql3util - -// ValidPageSize returns true if s is a valid page size. -// -// https://sqlite.org/fileformat.html#pages -func ValidPageSize(s int) bool { - return 512 <= s && s <= 65536 && s&(s-1) == 0 -} diff --git a/vendor/github.com/ncruces/go-sqlite3/util/sql3util/wasm/sql3parse_table.wasm b/vendor/github.com/ncruces/go-sqlite3/util/sql3util/wasm/sql3parse_table.wasm Binary files differdeleted file mode 100644 index 4d3357ea1..000000000 --- a/vendor/github.com/ncruces/go-sqlite3/util/sql3util/wasm/sql3parse_table.wasm +++ /dev/null |