github.com/dolthub/dolt/go@v0.40.5-0.20240520175717-68db7794bea6/libraries/doltcore/sqle/sqlutil/static_errors.go (about) 1 // Copyright 2020 Dolthub, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package sqlutil 16 17 import ( 18 "github.com/dolthub/go-mysql-server/sql" 19 ) 20 21 type StaticErrorTable struct { 22 sql.Table 23 err error 24 } 25 26 func (t *StaticErrorTable) Partitions(_ *sql.Context) (sql.PartitionIter, error) { 27 return nil, t.err 28 } 29 30 func (t *StaticErrorTable) PartitionRows(_ *sql.Context, _ sql.Partition) (sql.RowIter, error) { 31 return nil, t.err 32 } 33 34 func (t *StaticErrorTable) LookupPartitions(_ *sql.Context, _ sql.IndexLookup) (sql.PartitionIter, error) { 35 return nil, t.err 36 } 37 38 func NewStaticErrorTable(orig sql.Table, err error) sql.Table { 39 return &StaticErrorTable{orig, err} 40 } 41 42 type StaticErrorRowIter struct { 43 err error 44 } 45 46 func NewStaticErrorRowIter(err error) sql.RowIter { 47 return &StaticErrorRowIter{err} 48 } 49 50 func (i *StaticErrorRowIter) Next(*sql.Context) (sql.Row, error) { 51 return nil, i.err 52 } 53 54 func (i *StaticErrorRowIter) Close(*sql.Context) error { 55 // Or i.err? 56 return nil 57 } 58 59 type StaticErrorEditor struct { 60 err error 61 } 62 63 var _ sql.ForeignKeyEditor = (*StaticErrorEditor)(nil) 64 65 func NewStaticErrorEditor(err error) *StaticErrorEditor { 66 return &StaticErrorEditor{err} 67 } 68 69 func (e *StaticErrorEditor) Insert(*sql.Context, sql.Row) error { 70 return e.err 71 } 72 73 func (e *StaticErrorEditor) Delete(*sql.Context, sql.Row) error { 74 return e.err 75 } 76 77 func (e *StaticErrorEditor) Update(*sql.Context, sql.Row, sql.Row) error { 78 return e.err 79 } 80 81 func (e *StaticErrorEditor) SetAutoIncrementValue(*sql.Context, uint64) error { 82 return e.err 83 } 84 85 func (e *StaticErrorEditor) AcquireAutoIncrementLock(ctx *sql.Context) (func(), error) { 86 return func() {}, nil 87 } 88 89 func (e *StaticErrorEditor) StatementBegin(ctx *sql.Context) {} 90 91 func (e *StaticErrorEditor) DiscardChanges(ctx *sql.Context, errorEncountered error) error { 92 return nil 93 } 94 95 func (e *StaticErrorEditor) StatementComplete(ctx *sql.Context) error { 96 return nil 97 } 98 99 func (e *StaticErrorEditor) WithIndexLookup(lookup sql.IndexLookup) sql.Table { 100 return &StaticErrorTable{nil, e.err} 101 } 102 103 func (e *StaticErrorEditor) Close(*sql.Context) error { 104 // Or e.err? 105 return nil 106 } 107 108 func (e *StaticErrorEditor) IndexedAccess(lookup sql.IndexLookup) sql.IndexedTable { 109 return &StaticErrorTable{nil, e.err} 110 } 111 112 func (e *StaticErrorEditor) PreciseMatch() bool { 113 return true 114 } 115 116 func (e *StaticErrorEditor) GetIndexes(ctx *sql.Context) ([]sql.Index, error) { 117 return nil, nil 118 }