mirror of
https://github.com/dolthub/dolt.git
synced 2026-03-17 23:56:33 -05:00
@@ -102,8 +102,8 @@ func (db *Database) GetTableInsensitive(ctx context.Context, tblName string) (sq
|
||||
return nil, false, nil
|
||||
}
|
||||
|
||||
if db.tables[exactName] != nil {
|
||||
return db.tables[exactName], true, nil
|
||||
if table, ok := db.tables[exactName]; ok {
|
||||
return table, true, nil
|
||||
}
|
||||
|
||||
tbl, ok, err := db.root.GetTable(ctx, exactName)
|
||||
@@ -120,8 +120,9 @@ func (db *Database) GetTableInsensitive(ctx context.Context, tblName string) (sq
|
||||
return nil, false, err
|
||||
}
|
||||
|
||||
db.tables[exactName] = &DoltTable{name: exactName, table: tbl, sch: sch, db: db}
|
||||
return db.tables[exactName], true, nil
|
||||
table := &DoltTable{name: exactName, table: tbl, sch: sch, db: db}
|
||||
db.tables[exactName] = table
|
||||
return table, true, nil
|
||||
}
|
||||
|
||||
func (db *Database) GetTableNames(ctx context.Context) ([]string, error) {
|
||||
|
||||
@@ -143,7 +143,7 @@ func drainIter(iter sql.RowIter) error {
|
||||
_, err := iter.Next()
|
||||
if err == io.EOF {
|
||||
return returnedErr
|
||||
} else if returnedErr != nil {
|
||||
} else if err != nil {
|
||||
returnedErr = err
|
||||
}
|
||||
}
|
||||
@@ -213,6 +213,7 @@ func TestSqlBatchInsertErrors(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
assert.NoError(t, drainIter(rowIter))
|
||||
|
||||
// This generates an error at insert time because of the bad type for the uuid column
|
||||
_, _, err = engine.Query(sql.NewEmptyContext(), `insert into people values
|
||||
(2, "Milhouse", "VanHouten", false, 1, 5.1, true, 677)`)
|
||||
assert.Error(t, err)
|
||||
|
||||
@@ -145,7 +145,7 @@ func drainIter(iter sql.RowIter) error {
|
||||
_, err := iter.Next()
|
||||
if err == io.EOF {
|
||||
return returnedErr
|
||||
} else if returnedErr != nil {
|
||||
} else if err != nil {
|
||||
returnedErr = err
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,7 +73,11 @@ func (te *tableEditor) Insert(ctx *sql.Context, sqlRow sql.Row) error {
|
||||
// If we've already inserted this key as part of this insert operation, that's an error. Inserting a row that already
|
||||
// exists in the table will be handled in Close().
|
||||
if _, ok := te.addedKeys[hash]; ok {
|
||||
return fmt.Errorf(ErrDuplicatePrimaryKeyFmt, types.EncodedValue(ctx, key))
|
||||
value, err := types.EncodedValue(ctx, key)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return fmt.Errorf(ErrDuplicatePrimaryKeyFmt, value)
|
||||
}
|
||||
te.insertedKeys[hash] = key
|
||||
te.addedKeys[hash] = key
|
||||
@@ -198,7 +202,11 @@ func (te *tableEditor) flush(ctx context.Context) error {
|
||||
return errhand.BuildDError("failed to read table").AddCause(err).Build()
|
||||
}
|
||||
if rowExists {
|
||||
return fmt.Errorf("duplicate primary key given: (%v)", types.EncodedValue(ctx, addedKey))
|
||||
value, err := types.EncodedValue(ctx, addedKey)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return fmt.Errorf(ErrDuplicatePrimaryKeyFmt, value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user