diff options
| author | 2025-03-09 17:47:56 +0100 | |
|---|---|---|
| committer | 2025-12-01 22:08:04 +0100 | |
| commit | b1af8fd87760b34e3ff2fd3bda38f211815a0473 (patch) | |
| tree | 9317fad1a7ec298d7a8d2678e4e422953bbc6f33 /vendor/github.com/ncruces/go-sqlite3/util | |
| parent | [chore] update URLs to forked source (diff) | |
| download | gotosocial-b1af8fd87760b34e3ff2fd3bda38f211815a0473.tar.xz | |
[chore] remove vendor
Diffstat (limited to 'vendor/github.com/ncruces/go-sqlite3/util')
8 files changed, 0 insertions, 641 deletions
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 f2e33c0b2..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 s&(s-1) == 0 && 512 <= s && s <= 65536 -} 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 0d7c8810c..000000000 --- a/vendor/github.com/ncruces/go-sqlite3/util/sql3util/wasm/sql3parse_table.wasm +++ /dev/null diff --git a/vendor/github.com/ncruces/go-sqlite3/util/vfsutil/slice.go b/vendor/github.com/ncruces/go-sqlite3/util/vfsutil/slice.go deleted file mode 100644 index b0fbe993c..000000000 --- a/vendor/github.com/ncruces/go-sqlite3/util/vfsutil/slice.go +++ /dev/null @@ -1,102 +0,0 @@ -package vfsutil - -import ( - "io" - - "github.com/ncruces/go-sqlite3" - "github.com/ncruces/go-sqlite3/vfs" -) - -// SliceFile implements [vfs.File] with a byte slice. -// It is suitable for temporary files (such as [vfs.OPEN_TEMP_JOURNAL]), -// but not concurrency safe. -type SliceFile []byte - -var ( - // Ensure these interfaces are implemented: - _ vfs.FileSizeHint = &SliceFile{} -) - -// ReadAt implements [io.ReaderAt]. -func (f *SliceFile) ReadAt(b []byte, off int64) (n int, err error) { - if d := *f; off < int64(len(d)) { - n = copy(b, d[off:]) - } - if n < len(b) { - err = io.EOF - } - return -} - -// WriteAt implements [io.WriterAt]. -func (f *SliceFile) WriteAt(b []byte, off int64) (n int, err error) { - d := *f - if off > int64(len(d)) { - d = append(d, make([]byte, off-int64(len(d)))...) - } - d = append(d[:off], b...) - if len(d) > len(*f) { - *f = d - } - return len(b), nil -} - -// Size implements [vfs.File]. -func (f *SliceFile) Size() (int64, error) { - return int64(len(*f)), nil -} - -// Truncate implements [vfs.File]. -func (f *SliceFile) Truncate(size int64) error { - if d := *f; size < int64(len(d)) { - *f = d[:size] - } - return nil -} - -// SizeHint implements [vfs.FileSizeHint]. -func (f *SliceFile) SizeHint(size int64) error { - if d := *f; size > int64(len(d)) { - *f = append(d, make([]byte, size-int64(len(d)))...) - } - return nil -} - -// Close implements [io.Closer]. -func (*SliceFile) Close() error { return nil } - -// Sync implements [vfs.File]. -func (*SliceFile) Sync(flags vfs.SyncFlag) error { return nil } - -// Lock implements [vfs.File]. -func (*SliceFile) Lock(lock vfs.LockLevel) error { - // notest // not concurrency safe - return sqlite3.IOERR_LOCK -} - -// Unlock implements [vfs.File]. -func (*SliceFile) Unlock(lock vfs.LockLevel) error { - // notest // not concurrency safe - return sqlite3.IOERR_UNLOCK -} - -// CheckReservedLock implements [vfs.File]. -func (*SliceFile) CheckReservedLock() (bool, error) { - // notest // not concurrency safe - return false, sqlite3.IOERR_CHECKRESERVEDLOCK -} - -// SectorSize implements [vfs.File]. -func (*SliceFile) SectorSize() int { - // notest // safe default - return 0 -} - -// DeviceCharacteristics implements [vfs.File]. -func (*SliceFile) DeviceCharacteristics() vfs.DeviceCharacteristic { - return vfs.IOCAP_ATOMIC | - vfs.IOCAP_SEQUENTIAL | - vfs.IOCAP_SAFE_APPEND | - vfs.IOCAP_POWERSAFE_OVERWRITE | - vfs.IOCAP_SUBPAGE_READ -} diff --git a/vendor/github.com/ncruces/go-sqlite3/util/vfsutil/wrap.go b/vendor/github.com/ncruces/go-sqlite3/util/vfsutil/wrap.go deleted file mode 100644 index ad96547fa..000000000 --- a/vendor/github.com/ncruces/go-sqlite3/util/vfsutil/wrap.go +++ /dev/null @@ -1,185 +0,0 @@ -// Package vfsutil implements virtual filesystem utilities. -package vfsutil - -import ( - "github.com/ncruces/go-sqlite3" - "github.com/ncruces/go-sqlite3/vfs" -) - -// UnwrapFile unwraps a [vfs.File], -// possibly implementing [vfs.FileUnwrap], -// to a concrete type. -func UnwrapFile[T vfs.File](f vfs.File) (_ T, _ bool) { - for { - switch t := f.(type) { - default: - return - case T: - return t, true - case vfs.FileUnwrap: - f = t.Unwrap() - } - } -} - -// WrapOpen helps wrap [vfs.VFS]. -func WrapOpen(f vfs.VFS, name string, flags vfs.OpenFlag) (file vfs.File, _ vfs.OpenFlag, err error) { - if f, ok := f.(vfs.VFSFilename); name == "" && ok { - return f.OpenFilename(nil, flags) - } - return f.Open(name, flags) -} - -// WrapOpenFilename helps wrap [vfs.VFSFilename]. -func WrapOpenFilename(f vfs.VFS, name *vfs.Filename, flags vfs.OpenFlag) (file vfs.File, _ vfs.OpenFlag, err error) { - if f, ok := f.(vfs.VFSFilename); ok { - return f.OpenFilename(name, flags) - } - return f.Open(name.String(), flags) -} - -// WrapLockState helps wrap [vfs.FileLockState]. -func WrapLockState(f vfs.File) vfs.LockLevel { - if f, ok := f.(vfs.FileLockState); ok { - return f.LockState() - } - return vfs.LOCK_EXCLUSIVE + 1 // UNKNOWN_LOCK -} - -// WrapPersistWAL helps wrap [vfs.FilePersistWAL]. -func WrapPersistWAL(f vfs.File) bool { - if f, ok := f.(vfs.FilePersistWAL); ok { - return f.PersistWAL() - } - return false -} - -// WrapSetPersistWAL helps wrap [vfs.FilePersistWAL]. -func WrapSetPersistWAL(f vfs.File, keepWAL bool) { - if f, ok := f.(vfs.FilePersistWAL); ok { - f.SetPersistWAL(keepWAL) - } -} - -// WrapPowersafeOverwrite helps wrap [vfs.FilePowersafeOverwrite]. -func WrapPowersafeOverwrite(f vfs.File) bool { - if f, ok := f.(vfs.FilePowersafeOverwrite); ok { - return f.PowersafeOverwrite() - } - return false -} - -// WrapSetPowersafeOverwrite helps wrap [vfs.FilePowersafeOverwrite]. -func WrapSetPowersafeOverwrite(f vfs.File, psow bool) { - if f, ok := f.(vfs.FilePowersafeOverwrite); ok { - f.SetPowersafeOverwrite(psow) - } -} - -// WrapChunkSize helps wrap [vfs.FileChunkSize]. -func WrapChunkSize(f vfs.File, size int) { - if f, ok := f.(vfs.FileChunkSize); ok { - f.ChunkSize(size) - } -} - -// WrapSizeHint helps wrap [vfs.FileSizeHint]. -func WrapSizeHint(f vfs.File, size int64) error { - if f, ok := f.(vfs.FileSizeHint); ok { - return f.SizeHint(size) - } - return sqlite3.NOTFOUND -} - -// WrapHasMoved helps wrap [vfs.FileHasMoved]. -func WrapHasMoved(f vfs.File) (bool, error) { - if f, ok := f.(vfs.FileHasMoved); ok { - return f.HasMoved() - } - return false, sqlite3.NOTFOUND -} - -// WrapOverwrite helps wrap [vfs.FileOverwrite]. -func WrapOverwrite(f vfs.File) error { - if f, ok := f.(vfs.FileOverwrite); ok { - return f.Overwrite() - } - return sqlite3.NOTFOUND -} - -// WrapSyncSuper helps wrap [vfs.FileSync]. -func WrapSyncSuper(f vfs.File, super string) error { - if f, ok := f.(vfs.FileSync); ok { - return f.SyncSuper(super) - } - return sqlite3.NOTFOUND -} - -// WrapCommitPhaseTwo helps wrap [vfs.FileCommitPhaseTwo]. -func WrapCommitPhaseTwo(f vfs.File) error { - if f, ok := f.(vfs.FileCommitPhaseTwo); ok { - return f.CommitPhaseTwo() - } - return sqlite3.NOTFOUND -} - -// WrapBeginAtomicWrite helps wrap [vfs.FileBatchAtomicWrite]. -func WrapBeginAtomicWrite(f vfs.File) error { - if f, ok := f.(vfs.FileBatchAtomicWrite); ok { - return f.BeginAtomicWrite() - } - return sqlite3.NOTFOUND -} - -// WrapCommitAtomicWrite helps wrap [vfs.FileBatchAtomicWrite]. -func WrapCommitAtomicWrite(f vfs.File) error { - if f, ok := f.(vfs.FileBatchAtomicWrite); ok { - return f.CommitAtomicWrite() - } - return sqlite3.NOTFOUND -} - -// WrapRollbackAtomicWrite helps wrap [vfs.FileBatchAtomicWrite]. -func WrapRollbackAtomicWrite(f vfs.File) error { - if f, ok := f.(vfs.FileBatchAtomicWrite); ok { - return f.RollbackAtomicWrite() - } - return sqlite3.NOTFOUND -} - -// WrapCheckpointStart helps wrap [vfs.FileCheckpoint]. -func WrapCheckpointStart(f vfs.File) { - if f, ok := f.(vfs.FileCheckpoint); ok { - f.CheckpointStart() - } -} - -// WrapCheckpointDone helps wrap [vfs.FileCheckpoint]. -func WrapCheckpointDone(f vfs.File) { - if f, ok := f.(vfs.FileCheckpoint); ok { - f.CheckpointDone() - } -} - -// WrapPragma helps wrap [vfs.FilePragma]. -func WrapPragma(f vfs.File, name, value string) (string, error) { - if f, ok := f.(vfs.FilePragma); ok { - return f.Pragma(name, value) - } - return "", sqlite3.NOTFOUND -} - -// WrapBusyHandler helps wrap [vfs.FilePragma]. -func WrapBusyHandler(f vfs.File, handler func() bool) { - if f, ok := f.(vfs.FileBusyHandler); ok { - f.BusyHandler(handler) - } -} - -// WrapSharedMemory helps wrap [vfs.FileSharedMemory]. -func WrapSharedMemory(f vfs.File) vfs.SharedMemory { - if f, ok := f.(vfs.FileSharedMemory); ok { - return f.SharedMemory() - } - return nil -} |
