Repository navigation
Expand file tree
/
Copy pathinsertdata.go
More file actions
49 lines (40 loc) · 1.41 KB
/
Copy pathinsertdata.go
File metadata and controls
49 lines (40 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package parse
import (
"errors"
"slices"
"github.com/JunNishimura/GoSQL/query"
)
// ErrFieldValueCountMismatch is returned for an insert whose value list and
// field list have different lengths.
//
// It is separate from ErrBadSyntax because the statement is grammatical: each
// list is well formed on its own. The problem is that the lists do not match.
// Values are assigned to fields by position, so a value without a field, or a
// field without a value, cannot be written.
var ErrFieldValueCountMismatch = errors.New("field and value counts differ")
var _ UpdateCommand = InsertData{}
// InsertData is the content of an insert statement: a record to write to a
// table, with each value assigned to the field at the same position.
//
// The fields and values are returned as copies, like the fields and tables of
// QueryData.
type InsertData struct {
tableName string
fields []string
vals []query.Constant
}
func (InsertData) isUpdateCommand() {}
// TableName returns the table that the record is written to.
func (d InsertData) TableName() string {
return d.tableName
}
// Fields returns the fields that the values are written to, in the order
// written.
func (d InsertData) Fields() []string {
return slices.Clone(d.fields)
}
// Values returns the values to write. Each value belongs to the field at the
// same position in Fields.
func (d InsertData) Values() []query.Constant {
return slices.Clone(d.vals)
}