PR feedback

Signed-off-by: Zach Musgrave <zach@liquidata.co>
This commit is contained in:
Zach Musgrave
2019-12-05 11:38:45 -08:00
parent c3cae470fe
commit b574e6c20c
4 changed files with 18 additions and 8 deletions

View File

@@ -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) {

View File

@@ -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)

View File

@@ -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
}
}

View File

@@ -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)
}
}
}