Commit ec407c8f authored by Carsten  Rose's avatar Carsten Rose
Browse files

Extend QIFEMPTY: empty a) date, b) datetime, c) '0' is also treated as empty.

parent aa498e00
Pipeline #2580 passed with stages
in 2 minutes and 47 seconds
......@@ -6916,7 +6916,7 @@ Output::
QIFEMPTY: if empty show token
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
The SQL function QIFEMPTY(input, token) returns 'token' if 'input' is empty else 'input'.
The SQL function QIFEMPTY(input, token) returns 'token' if 'input' is 'empty string' / '0' / '0000-00-00' / '0000-00-00 00:00:00'.
Example::
......
......@@ -71,7 +71,7 @@ END;
###
#
# QIFEMPTY(input, token)
# If 'input' is empty, replaces by 'token'
# If 'input' is empty|0|0000-00-00|0000-00-00 00:00:00, replace by 'token'
#
DROP FUNCTION IF EXISTS QIFEMPTY;
CREATE FUNCTION QIFEMPTY(input TEXT, token TEXT)
......@@ -80,7 +80,9 @@ CREATE FUNCTION QIFEMPTY(input TEXT, token TEXT)
SQL SECURITY INVOKER
BEGIN
DECLARE output TEXT;
SET output = IF(input = '', token, input);
SET output =
IF(ISNULL(input) OR input = '' OR INPUT = '0' OR input = '0000-00-00' OR input = '0000-00-00 00:00:00', token,
input);
RETURN output;
END;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment