Spanner: Add trivial sequence number generator. (#101777)
* Add trivial sequence number generator.
This commit is contained in:
@@ -345,20 +345,25 @@ func (session *Session) innerInsert(bean any) (int64, error) {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
//// XXX: hack to handle autoincrement in spanner
|
||||
//if len(table.AutoIncrement) > 0 && session.engine.dialect.DBType() == "spanner" {
|
||||
// var found bool
|
||||
// for _, col := range colNames {
|
||||
// if col == table.AutoIncrement {
|
||||
// found = true
|
||||
// break
|
||||
// }
|
||||
// }
|
||||
// if !found {
|
||||
// colNames = append(colNames, table.AutoIncrement)
|
||||
// args = append(args, rand.Int63n(9e15))
|
||||
// }
|
||||
//}
|
||||
// If engine has a sequence number generator, use it to produce values for auto-increment columns.
|
||||
if len(table.AutoIncrement) > 0 && session.engine.sequenceGenerator != nil {
|
||||
var found bool
|
||||
for _, col := range colNames {
|
||||
if col == table.AutoIncrement {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
seq, err := session.engine.sequenceGenerator.Next(session.ctx, table.Name, table.AutoIncrement)
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("failed to generate next value for auto_increment columns: %v", err)
|
||||
}
|
||||
|
||||
colNames = append(colNames, table.AutoIncrement)
|
||||
args = append(args, seq)
|
||||
}
|
||||
}
|
||||
|
||||
exprs := session.statement.exprColumns
|
||||
colPlaces := strings.Repeat("?, ", len(colNames))
|
||||
|
||||
Reference in New Issue
Block a user