SQLite: defer cancel's in select statements (#2717)
Signed-off-by: ItalyPaleAle <43508+ItalyPaleAle@users.noreply.github.com>
This commit is contained in:
parent
297c97ca95
commit
33f9c6ecef
|
@ -255,8 +255,8 @@ func (a *sqliteDBAccess) Get(parentCtx context.Context, req *state.GetRequest) (
|
|||
key = ?
|
||||
AND (expiration_time IS NULL OR expiration_time > CURRENT_TIMESTAMP)`
|
||||
ctx, cancel := context.WithTimeout(parentCtx, a.metadata.timeout)
|
||||
defer cancel()
|
||||
row := a.db.QueryRowContext(ctx, stmt, req.Key)
|
||||
cancel()
|
||||
_, value, etag, err := readRow(row)
|
||||
if err != nil {
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
|
@ -291,8 +291,8 @@ func (a *sqliteDBAccess) BulkGet(parentCtx context.Context, req []state.GetReque
|
|||
key IN (` + inClause + `)
|
||||
AND (expiration_time IS NULL OR expiration_time > CURRENT_TIMESTAMP)`
|
||||
ctx, cancel := context.WithTimeout(parentCtx, a.metadata.timeout)
|
||||
defer cancel()
|
||||
rows, err := a.db.QueryContext(ctx, stmt, params...)
|
||||
cancel()
|
||||
if err != nil {
|
||||
return true, nil, err
|
||||
}
|
||||
|
@ -431,8 +431,8 @@ func (a *sqliteDBAccess) doSet(parentCtx context.Context, db querier, req *state
|
|||
(key, value, is_binary, etag, update_time, expiration_time)
|
||||
VALUES(?, ?, ?, ?, CURRENT_TIMESTAMP, ` + expiration + `)`
|
||||
ctx, cancel := context.WithTimeout(context.Background(), a.metadata.timeout)
|
||||
defer cancel()
|
||||
res, err = db.ExecContext(ctx, stmt, req.Key, requestValue, isBinary, newEtag, req.Key)
|
||||
cancel()
|
||||
} else {
|
||||
stmt = `UPDATE ` + a.metadata.TableName + ` SET
|
||||
value = ?,
|
||||
|
@ -445,8 +445,8 @@ func (a *sqliteDBAccess) doSet(parentCtx context.Context, db querier, req *state
|
|||
AND etag = ?
|
||||
AND (expiration_time IS NULL OR expiration_time > CURRENT_TIMESTAMP)`
|
||||
ctx, cancel := context.WithTimeout(context.Background(), a.metadata.timeout)
|
||||
defer cancel()
|
||||
res, err = db.ExecContext(ctx, stmt, requestValue, newEtag, isBinary, req.Key, *req.ETag)
|
||||
cancel()
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -536,19 +536,17 @@ func (a *sqliteDBAccess) doDelete(parentCtx context.Context, db querier, req *st
|
|||
return fmt.Errorf("missing key in delete operation")
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithTimeout(parentCtx, a.metadata.timeout)
|
||||
defer cancel()
|
||||
var result sql.Result
|
||||
if req.ETag == nil || *req.ETag == "" {
|
||||
// Sprintf is required for table name because sql.DB does not substitute parameters for table names.
|
||||
stmt := "DELETE FROM " + a.metadata.TableName + " WHERE key = ?"
|
||||
ctx, cancel := context.WithTimeout(parentCtx, a.metadata.timeout)
|
||||
result, err = db.ExecContext(ctx, stmt, req.Key)
|
||||
cancel()
|
||||
// Concatenation is required for table name because sql.DB does not substitute parameters for table names.
|
||||
result, err = db.ExecContext(ctx, "DELETE FROM "+a.metadata.TableName+" WHERE key = ?",
|
||||
req.Key)
|
||||
} else {
|
||||
// Sprintf is required for table name because sql.DB does not substitute parameters for table names.
|
||||
stmt := "DELETE FROM " + a.metadata.TableName + " WHERE key = ? AND etag = ?"
|
||||
ctx, cancel := context.WithTimeout(parentCtx, a.metadata.timeout)
|
||||
result, err = db.ExecContext(ctx, stmt, req.Key, *req.ETag)
|
||||
cancel()
|
||||
// Concatenation is required for table name because sql.DB does not substitute parameters for table names.
|
||||
result, err = db.ExecContext(ctx, "DELETE FROM "+a.metadata.TableName+" WHERE key = ? AND etag = ?",
|
||||
req.Key, *req.ETag)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
|
|
|
@ -476,7 +476,7 @@ func ConformanceTests(t *testing.T, props map[string]string, statestore state.St
|
|||
"partitionKey": "myPartition",
|
||||
},
|
||||
})
|
||||
assert.Nil(t, err)
|
||||
require.NoError(t, err)
|
||||
for _, scenario := range scenarios {
|
||||
if scenario.transactionOnly {
|
||||
if scenario.transactionGroup == transactionGroup {
|
||||
|
@ -489,7 +489,7 @@ func ConformanceTests(t *testing.T, props map[string]string, statestore state.St
|
|||
"partitionKey": "myPartition",
|
||||
},
|
||||
})
|
||||
assert.Nil(t, err)
|
||||
require.NoError(t, err)
|
||||
assertEquals(t, scenario.value, res)
|
||||
}
|
||||
|
||||
|
@ -503,7 +503,7 @@ func ConformanceTests(t *testing.T, props map[string]string, statestore state.St
|
|||
"partitionKey": "myPartition",
|
||||
},
|
||||
})
|
||||
assert.Nil(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Nil(t, res.Data)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue