Skip to content

Commit

Permalink
Temporarily moving back checks on column lists to `DMLUpdateQueryBuil…
Browse files Browse the repository at this point in the history
…der.BuildQuery()`
  • Loading branch information
danieljoos committed Oct 23, 2024
1 parent 412346e commit 0c4db0e
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions go/sql/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -638,18 +638,6 @@ type DMLUpdateQueryBuilder struct {
}

func NewDMLUpdateQueryBuilder(databaseName, tableName string, tableColumns, sharedColumns, mappedSharedColumns, uniqueKeyColumns *ColumnList) (*DMLUpdateQueryBuilder, error) {
if !sharedColumns.IsSubsetOf(tableColumns) {
return nil, fmt.Errorf("shared columns is not a subset of table columns in NewDMLUpdateQueryBuilder")
}
if !uniqueKeyColumns.IsSubsetOf(sharedColumns) {
return nil, fmt.Errorf("unique key columns is not a subset of shared columns in NewDMLUpdateQueryBuilder")
}
if sharedColumns.Len() == 0 {
return nil, fmt.Errorf("no shared columns found in NewDMLUpdateQueryBuilder")
}
if uniqueKeyColumns.Len() == 0 {
return nil, fmt.Errorf("no unique key columns found in NewDMLUpdateQueryBuilder")
}
databaseName = EscapeName(databaseName)
tableName = EscapeName(tableName)
setClause, err := BuildSetPreparedClause(mappedSharedColumns)
Expand Down Expand Up @@ -682,6 +670,20 @@ func NewDMLUpdateQueryBuilder(databaseName, tableName string, tableColumns, shar
}

func (b *DMLUpdateQueryBuilder) BuildQuery(valueArgs, whereArgs []interface{}) (string, []interface{}, []interface{}, error) {
// TODO: move these checks to `NewDMLUpdateQueryBuilder()`, needs fix on generated columns.
if !b.sharedColumns.IsSubsetOf(b.tableColumns) {
return "", nil, nil, fmt.Errorf("shared columns is not a subset of table columns in NewDMLUpdateQueryBuilder")
}
if !b.uniqueKeyColumns.IsSubsetOf(b.sharedColumns) {
return "", nil, nil, fmt.Errorf("unique key columns is not a subset of shared columns in NewDMLUpdateQueryBuilder")
}
if b.sharedColumns.Len() == 0 {
return "", nil, nil, fmt.Errorf("no shared columns found in NewDMLUpdateQueryBuilder")
}
if b.uniqueKeyColumns.Len() == 0 {
return "", nil, nil, fmt.Errorf("no unique key columns found in NewDMLUpdateQueryBuilder")
}

sharedArgs := make([]interface{}, 0, b.sharedColumns.Len())
for _, column := range b.sharedColumns.Columns() {
tableOrdinal := b.tableColumns.Ordinals[column.Name]
Expand Down

0 comments on commit 0c4db0e

Please sign in to comment.