Page 1 of 3

How the search field work.

Posted: Wed Aug 21, 2019 10:06 am
by nub74
Hi to all,
I need to understand how the search field works
because in some forms it filters the data while in others it simply highlights them without filtering.
I have a form with 30 pages and it would be better if I filtered the data I am looking for
instead of highlighting them to avoid fooling all the pages.
Thank you.

Re: How the search field work.

Posted: Wed Aug 21, 2019 11:37 am
by kev1n
nub74 wrote: because in some forms it filters the data while in others it simply highlights them without filtering.
.
Enter this command in the developer console, after you have performed the search:

nuCurrentProperties().browse_sql

Then you'll see the sql query and check if the syntax is correct (e.g. by executing the statement in phpMyAdmin)

Re: How the search field work.

Posted: Wed Aug 21, 2019 2:39 pm
by nub74
Hello Kev1n,
Thanks for your quick response. I performed the check as you suggested,
and in fact the combination of the conditions set by me and those added by the search code
does not allow to filter the data correctly. If I delete a simple condition 'OR' the filter is applied correctly.
The problem is that I need that condition so that the form returns the right values;
how can this be solved?
Thank you.

Re: How the search field work.

Posted: Wed Aug 21, 2019 5:55 pm
by kev1n
Can you show us the SQL as shown in the dev console?

Re: How the search field work.

Posted: Wed Aug 21, 2019 6:16 pm
by nub74
Here is the sql:

SELECT id_riga,commessa,sus_name,task,note,ore,data
FROM registro_task LEFT JOIN tasks ON registro_task.id_task = tasks.id_task LEFT JOIN zzzzsys_user ON registro_task.id_operatore = zzzzsys_user.zzzzsys_user_id LEFT JOIN commesse ON registro_task.id_commessa = commesse.commessa LEFT JOIN livelli_view ON registro_task.id_operatore = livelli_view.id_operatore
WHERE tasks.id_reparto = (SELECT reparti.id_reparto FROM reparti LEFT JOIN operatori ON reparti.id_reparto = operatori.id_reparto WHERE operatori.id_nub = '5d3578bad8ecfe0') AND (livelli_view.livello < (SELECT livelli_view.livello FROM livelli_view LEFT JOIN registro_task ON livelli_view.id_operatore = registro_task.id_operatore WHERE ((registro_task.id_operatore = '5d3578bad8ecfe0')) AND ( (CONVERT(commessa USING utf8) LIKE "%1185%" OR CONVERT(sus_name USING utf8) LIKE "%1185%" OR CONVERT(task USING utf8) LIKE "%1185%" OR CONVERT(note USING utf8) LIKE "%1185%" OR CONVERT(ore USING utf8) LIKE "%1185%" OR CONVERT(data USING utf8) LIKE "%1185%") )
GROUP BY livelli_view.livello )) OR (registro_task.id_operatore='5d3578bad8ecfe0')

By deleting "OR (registro_task.id_operatore='5d3578bad8ecfe0')" the filter work fine.

Re: How the search field work.

Posted: Thu Aug 22, 2019 12:23 am
by admin
nub74,

If you have a WHERE clause in your SQL for a Form

you need to make sure it is surrounded by brackets because when filtering,

nuBuilder adds extra SQL.


Steven

Re: How the search field work.

Posted: Thu Aug 22, 2019 8:16 am
by nub74
Hi Steven,
I have already tried with the brackets but the result is the same.

Re: How the search field work.

Posted: Thu Aug 22, 2019 8:38 am
by nub74
Allow me to amend the last post:
the result changes but that OR condition adds more records to the search results anyway
but I need that condition.

Re: How the search field work.

Posted: Thu Aug 22, 2019 1:20 pm
by kev1n
Can you also post the SQL you entered in the form's browse sql?

Re: How the search field work.

Posted: Thu Aug 22, 2019 4:36 pm
by nub74
Hi Kev1n,
here is my sql:

SELECT
registro_task.*,
tasks.codice,
zzzzsys_user.sus_name,
commesse.commessa

FROM
registro_task
LEFT JOIN tasks ON registro_task.id_task = tasks.id_task
LEFT JOIN zzzzsys_user ON registro_task.id_operatore = zzzzsys_user.zzzzsys_user_id
LEFT JOIN commesse ON registro_task.id_commessa = commesse.commessa
LEFT JOIN livelli_view ON registro_task.id_operatore = livelli_view.id_operatore

WHERE
(
tasks.id_reparto = (SELECT reparti.id_reparto
FROM reparti
LEFT JOIN operatori ON reparti.id_reparto = operatori.id_reparto
WHERE
(operatori.id_nub = '#USER_ID#'))
AND
(livelli_view.livello < (SELECT livelli_view.livello
FROM livelli_view
LEFT JOIN registro_task ON livelli_view.id_operatore = registro_task.id_operatore
WHERE
((registro_task.id_operatore = '#USER_ID#')) GROUP BY livelli_view.livello ))
OR
(registro_task.id_operatore='#USER_ID#')
)