~emersion/soju

bc83d3a3ba81f3e8c010c83160832bbf6b6bffff — Hubert Hirtz 14 days ago 4dce5a9
Use NULL-tolerant comparison for DeliveryReceipts

Since NULL = NULL is always FALSE, this query needs to use IS instead.
This should fix the flood of DeliveryReceipts in the DB.

See https://www.sqlite.org/lang_expr.html

> The IS and IS NOT operators work like = and != except when one or both
> of the operands are NULL. In this case, if both operands are NULL,
> then the IS operator evaluates to 1 (true) and the IS NOT operator
> evaluates to 0 (false). If one operand is NULL and the other is not,
> then the IS operator evaluates to 0 (false) and the IS NOT operator is
> 1 (true). It is not possible for an IS or IS NOT expression to
> evaluate to NULL.
1 files changed, 1 insertions(+), 1 deletions(-)

M db_sqlite.go
M db_sqlite.go => db_sqlite.go +1 -1
@@ 542,7 542,7 @@ func (db *SqliteDB) StoreClientDeliveryReceipts(networkID int64, client string, 
	}
	defer tx.Rollback()

	_, err = tx.Exec("DELETE FROM DeliveryReceipt WHERE network = ? AND client = ?",
	_, err = tx.Exec("DELETE FROM DeliveryReceipt WHERE network = ? AND client IS ?",
		networkID, toNullString(client))
	if err != nil {
		return err