core: Fix PostgreSQL realname/avatarurl handling
authorShane Synan <digitalcircuit36939@gmail.com>
Fri, 11 May 2018 06:37:55 +0000 (01:37 -0500)
committerManuel Nickschas <sputnick@quassel-irc.org>
Wed, 23 May 2018 22:33:28 +0000 (00:33 +0200)
commitb8d7e647bca45cba82db5fa38c58f336aefe5768
treec488a7d43b0f5e6fdb67350adffc55ea917eb469
parent092e6b212637ffbf68800584b7c1f32d1931b602
core: Fix PostgreSQL realname/avatarurl handling

In insert_message, when selecting a senderid coalesce "realname" and
"avatarurl".  This fixes inserting redundant senders due to NULL
values, e.g. messages from the server during connect.

Test case: start up core, client.  Connect, check PostgreSQL database
"sender" table.  Disconnect, reconnect.  There shouldn't be new NULL
senders in the table (e.g. sender set, but NULL realname).

NOTE: The realname/avatarurl columns can be NULL values.  Due to
this, we need to coalesce them to '' in order to use the same queries
rather than "column = some value" and "column IS NULL".  Both column
and the input parameter need coalesced in case one or the other is
NULL.  As there's minimal functional difference in protocol handling
between '' and NULL, we consider them the same.

(This could be squashed down if preferred, I just wanted to document
 what was needed to fix this for PostgreSQL, and to simplify figuring
 out what to change should a better solution arise.)
src/core/SQL/PostgreSQL/select_senderid.sql