@@ -546,6 +546,12 @@ func NewDMLUpdateQueryBuilder(databaseName, tableName string, tableColumns, shar
546546 if uniqueKeyColumns .Len () == 0 {
547547 return nil , fmt .Errorf ("no unique key columns found in NewDMLUpdateQueryBuilder" )
548548 }
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+ }
549555 databaseName = EscapeName (databaseName )
550556 tableName = EscapeName (tableName )
551557 setClause , err := BuildSetPreparedClause (mappedSharedColumns )
@@ -580,11 +586,6 @@ func NewDMLUpdateQueryBuilder(databaseName, tableName string, tableColumns, shar
580586// BuildQuery builds the arguments array for a DML event UPDATE query.
581587// It returns the query string, the shared arguments array, and the unique key arguments array.
582588func (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-
588589 sharedArgs := make ([]interface {}, 0 , b .sharedColumns .Len ())
589590 for _ , column := range b .sharedColumns .Columns () {
590591 tableOrdinal := b .tableColumns .Ordinals [column .Name ]
0 commit comments