MCPcopy
hub / github.com/github/gh-ost / BuildQuery

Method BuildQuery

go/sql/builder.go:897–908  ·  view source on GitHub ↗

BuildQuery builds the arguments array for a DML event INSERT query. It returns the query string and the shared arguments array. Returns an error if the number of arguments differs from the number of table columns.

(args []interface{})

Source from the content-addressed store, hash-verified

895// It returns the query string and the shared arguments array.
896// Returns an error if the number of arguments differs from the number of table columns.
897func (b *DMLInsertQueryBuilder) BuildQuery(args []interface{}) (string, []interface{}, error) {
898 if len(args) != b.tableColumns.Len() {
899 return "", nil, fmt.Errorf("args count differs from table column count in BuildDMLInsertQuery")
900 }
901 sharedArgs := make([]interface{}, 0, b.sharedColumns.Len())
902 for _, column := range b.sharedColumns.Columns() {
903 tableOrdinal := b.tableColumns.Ordinals[column.Name]
904 arg := column.convertArg(args[tableOrdinal])
905 sharedArgs = append(sharedArgs, arg)
906 }
907 return b.preparedStatement, sharedArgs, nil
908}
909
910// DMLUpdateQueryBuilder can build UPDATE queries for DML events.
911// It holds the prepared query statement so it doesn't need to be recreated every time.

Callers 2

TestBuildDMLInsertQueryFunction · 0.95

Calls 4

ColumnsMethod · 0.80
convertArgMethod · 0.80
ErrorfMethod · 0.65
LenMethod · 0.45

Tested by 2

TestBuildDMLInsertQueryFunction · 0.76