Item9971: Query searches see the constant '' as the value zero making it impossible to test for empty value

pencil
Priority: Urgent
Current State: Closed
Released In: 1.1.2
Target Release: patch
Applies To: Engine
Component:
Branches:
Reported By: KennethLavrsen
Waiting For:
Last Change By: KennethLavrsen
This search %SEARCH{"Newfield= ''" type="query" format="$formfield(Newfield)"}% shold find topics with an empty formfield called Newfield.

It does not

But if I put a 0 as value in Newfield, then the search for '' will find it.

So it seems like the query code interprets the '' as zero instead of the empty string.

It is quite common to search for empty fields. Or rather to search for non-empty

Like %SEARCH{"Newfield = ''" type="query" format="$formfield(Newfield)"}%

Right now you have to do some silly workaround looking for "Newfield ~ '*?*'"

We need to fix this in 1.1.2

-- KennethLavrsen - 07 Nov 2010

Fixed the code and the one unit test which was testing this "feature". (Agreed with CDot that the test was OK when he wrote it, but it doesn't make any sense now). Closing the bug.

-- OlivierRaginel - 08 Nov 2010

The problem has been solved for form fields but not for meta fields.

%SEARCH{"form.name=''" type="query" format="| $topic |"}%

will not return topics that have no form as it used to.

-- ChipTondreau - 24 Nov 2010

Chip the way it worked before was a bug. The '' was transformed to a zero. And that is wrong. It has nothing to do with meta or formfields.

When you search for form.name = '' you actually search for a form with a name that is ''. That is rubbish I know but the principle of the test is that it will only return true when the item you search for exists and match the value.

Instead you need to search for either of these.

%SEARCH{"form.name = undefined" type="query" format="| $topic |"}%

%SEARCH{"NOT form.name" type="query" format="| $topic |"}%

First uses the documented 'undefined' variable. And the 2nd variation takes advantage that the form.name is undefined when it is not there and then we negate it with NOT.

Let us try it here (with limit = 10)

Searched: form.name = undefined
AC
ADDTOZONE
AJA
AT
AU
AbusePlugin
AccessControl
AccessStatsPlugin
AcronymDefinitionsPlugin
ActionTrackerPlugin
Number of topics: 10

-- KennethLavrsen - 25 Nov 2010
 

ItemTemplate edit

Summary Query searches see the constant '' as the value zero making it impossible to test for empty value
ReportedBy KennethLavrsen
Codebase
SVN Range
AppliesTo Engine
Component
Priority Urgent
CurrentState Closed
WaitingFor
Checkins distro:86f2c2c5c824 distro:6a360db2af20 distro:e32de23c6969 distro:2a51523af2b4 distro:c85c68bc4f8b distro:9af4c384a8d0 distro:d1b9f791dd2e distro:c7e3067e9c34
TargetRelease patch
ReleasedIn 1.1.2
Topic revision: r13 - 25 Nov 2010, KennethLavrsen - This page was cached on 23 Mar 2019 - 10:03.

The copyright of the content on this website is held by the contributing authors, except where stated elsewhere. See Copyright Statement. Creative Commons License    Legal Imprint    Privacy Policy