@@ -546,6 +546,12 @@ func NewDMLUpdateQueryBuilder(databaseName, tableName string, tableColumns, shar
546
546
if uniqueKeyColumns .Len () == 0 {
547
547
return nil , fmt .Errorf ("no unique key columns found in NewDMLUpdateQueryBuilder" )
548
548
}
549
+ // If unique key contains virtual columns, those column won't be in sharedColumns
550
+ // which only contains non-virtual columns
551
+ nonVirtualUniqueKeyColumns := uniqueKeyColumns .FilterBy (func (column Column ) bool { return ! column .IsVirtual })
552
+ if ! nonVirtualUniqueKeyColumns .IsSubsetOf (sharedColumns ) {
553
+ return nil , fmt .Errorf ("unique key columns is not a subset of shared columns in NewDMLUpdateQueryBuilder" )
554
+ }
549
555
databaseName = EscapeName (databaseName )
550
556
tableName = EscapeName (tableName )
551
557
setClause , err := BuildSetPreparedClause (mappedSharedColumns )
@@ -580,11 +586,6 @@ func NewDMLUpdateQueryBuilder(databaseName, tableName string, tableColumns, shar
580
586
// BuildQuery builds the arguments array for a DML event UPDATE query.
581
587
// It returns the query string, the shared arguments array, and the unique key arguments array.
582
588
func (b * DMLUpdateQueryBuilder ) BuildQuery (valueArgs , whereArgs []interface {}) (string , []interface {}, []interface {}, error ) {
583
- // TODO: move this check back to `NewDMLUpdateQueryBuilder()`, needs fix on generated columns.
584
- if ! b .uniqueKeyColumns .IsSubsetOf (b .sharedColumns ) {
585
- return "" , nil , nil , fmt .Errorf ("unique key columns is not a subset of shared columns in DMLUpdateQueryBuilder" )
586
- }
587
-
588
589
sharedArgs := make ([]interface {}, 0 , b .sharedColumns .Len ())
589
590
for _ , column := range b .sharedColumns .Columns () {
590
591
tableOrdinal := b .tableColumns .Ordinals [column .Name ]
0 commit comments