spanner-annotationsimpls-fixes (#102622)
* Fix DELETE statements. * Reset sequence generator when truncating tables. * Quote "at", since it's a keyword in Spanner.
This commit is contained in:
@@ -19,6 +19,10 @@ func newSequenceGenerator(db *sql.DB) *sequenceGenerator {
|
||||
}
|
||||
}
|
||||
|
||||
func (sg *sequenceGenerator) Reset() {
|
||||
// Nothing to do. This generator always uses state from DB.
|
||||
}
|
||||
|
||||
func (sg *sequenceGenerator) Next(ctx context.Context, table, column string) (int64, error) {
|
||||
// Current implementation fetches new value for each Next call.
|
||||
key := fmt.Sprintf("%s:%s", table, column)
|
||||
|
||||
@@ -18,6 +18,13 @@ func newInMemSequenceGenerator() *inMemSequenceGenerator {
|
||||
}
|
||||
}
|
||||
|
||||
func (g *inMemSequenceGenerator) Reset() {
|
||||
g.sequencesMu.Lock()
|
||||
defer g.sequencesMu.Unlock()
|
||||
|
||||
g.nextValues = make(map[string]int)
|
||||
}
|
||||
|
||||
func (g *inMemSequenceGenerator) Next(_ context.Context, table, column string) (int64, error) {
|
||||
if table == "migration_log" {
|
||||
// Don't use sequential IDs for migration log entries, as we don't clean up migration_log table between tests,
|
||||
|
||||
@@ -127,8 +127,15 @@ func NewEngine(driverName string, dataSourceName string) (*Engine, error) {
|
||||
return engine, nil
|
||||
}
|
||||
|
||||
func (engine *Engine) ResetSequenceGenerator() {
|
||||
if engine.sequenceGenerator != nil {
|
||||
engine.sequenceGenerator.Reset()
|
||||
}
|
||||
}
|
||||
|
||||
type SequenceGenerator interface {
|
||||
Next(ctx context.Context, table, column string) (int64, error)
|
||||
Reset()
|
||||
}
|
||||
|
||||
type DialectExt interface {
|
||||
|
||||
Reference in New Issue
Block a user