Read Data - Function in Where conditions

ieraora 06 Feb, 2022
Hello, I try to add this Where Conditions in read data, without success.
id_tag = COALESCE({data:filtro_immagini},id_tag)

Where I wrong, I must to use another way?

Thank you for reply
Colnem 07 Feb, 2022
Hi

What is COALESCE? Pure text? A javascript function? a php function? Are data:filtro_immagini and id_tag defined before you try this?

If data:filtro_immagini and id_tag defined before, you try to read database with id_tag='COALESCE('+value_f_data:filtro_immagini+','+value_of_id_tag+')'
For example, if data:filtro_immagini='abcd' and id_tag=12, you try to read records where id_tag = 'COALESCE(abcd,12)' like a pure string.
GreyHead 07 Feb, 2022
Hi ieaora,

Please try turning on the form Debugger - that should show you the MySQL query that is being created so that you can see where the error is.

Bob

PS for COALESCE see here
ieraora 07 Feb, 2022
Read Data - Function in Where conditions image 1

[read_immagini] => Array
        (
            [result] => Data not found!
            [log] => Array
                (
                    [0] => SELECT `Foto`.`cf_id` AS `Foto.cf_id`, `Foto`.`allegato` AS `Foto.allegato`, `Foto`.`g_id` AS `Foto.g_id`, `Foto`.`p_description` AS `Foto.p_description`, `Foto`.`id_tag` AS `Foto.id_tag`, `Foto`.`g_tag` AS `Foto.g_tag`, `Foto`.`p_cu` AS `Foto.p_cu`, `Foto`.`p_lotto` AS `Foto.p_lotto`, `Foto`.`id_listino` AS `Foto.id_listino`, `Foto`.`created` AS `Foto.created`, `Foto`.`modified` AS `Foto.modified`, `Foto`.`file_copertina` AS `Foto.file_copertina`, `Foto`.`p_tipo_galleria` AS `Foto.p_tipo_galleria`, `Foto`.`p_status_galleria` AS `Foto.p_status_galleria`, `Foto`.`g_solo_vetrina` AS `Foto.g_solo_vetrina`, `Foto`.`p_status` AS `Foto.p_status`, `Foto`.`p_tipo_formato` AS `Foto.p_tipo_formato`, `Foto`.`id_formati-off` AS `Foto.id_formati-off`, `Foto`.`p_id` AS `Foto.p_id`, `Foto`.`amazonaws_root` AS `Foto.amazonaws_root`, `Foto`.`p_exif_model_camera` AS `Foto.p_exif_model_camera`, `Foto`.`p_exif_copyright` AS `Foto.p_exif_copyright`, `Foto`.`p_exif_artist` AS `Foto.p_exif_artist`, `Foto`.`p_exif_datetime_scat` AS `Foto.p_exif_datetime_scat`, `Foto`.`p_exif_keywords` AS `Foto.p_exif_keywords`, `Foto`.`cestino` AS `Foto.cestino`, `Sottogalleria`.`id_sottogalleria` AS `Sottogalleria.id_sottogalleria`, `Sottogalleria`.`nome_sottogalleria` AS `Sottogalleria.nome_sottogalleria`, `Sottogalleria`.`sottogall_pub_priv` AS `Sottogalleria.sottogall_pub_priv`, `Sottogalleria`.`sottogall_passw` AS `Sottogalleria.sottogall_passw`, `Sottogalleria`.`sottogall_attiv_sosp` AS `Sottogalleria.sottogall_attiv_sosp`, `Sottogalleria`.`sottogall_solo_vetrina` AS `Sottogalleria.sottogall_solo_vetrina`, `Sottogalleria`.`sottogall_temp` AS `Sottogalleria.sottogall_temp`, `Sottogalleria`.`sottogall_data_inizio` AS `Sottogalleria.sottogall_data_inizio`, `Sottogalleria`.`sottogall_data_fine` AS `Sottogalleria.sottogall_data_fine`, `Sottogalleria`.`id_galleria` AS `Sottogalleria.id_galleria`, `Sottogalleria`.`id_listino` AS `Sottogalleria.id_listino`, `Sottogalleria`.`sottogall_data_ins` AS `Sottogalleria.sottogall_data_ins`, `Sottogalleria`.`timestamp` AS `Sottogalleria.timestamp`, `Sottogalleria`.`cestino` AS `Sottogalleria.cestino` FROM `xijhd_cf_product_data-2` AS `Foto` LEFT JOIN `xijhd_cf_sottogallerie` AS `Sottogalleria` ON `Foto`.`id_tag` = `Sottogalleria`.`id_sottogalleria` WHERE `Foto`.`cestino` = '0' AND `Foto`.`id_tag` = 'COALESCE(179,id_tag)' LIMIT 15;
                )

            [var] => false
        )

I tried also COALESCE({data:filtro_immagini},`Foto`.`id_tag`) without success.
Colnem 07 Feb, 2022
Hi

1) read_immagini is an array. id_tag is a field of a Database Table. In MySQL, a table field can't be equal to an array.

2) What is COALESCE()?

3) What do you search?
ieraora 07 Feb, 2022
Hi Colnem,
https://www.w3schools.com/sql/func_mysql_coalesce.asp

I want select all items if parameter is null.
Colnem 07 Feb, 2022
OK I didn't know this SQL Function.

You can't compare in a Read Data Action a table field with the result of a SQL function. The operator == compare type and value.

I don't see how you set read_immagini. So I suppose that is the result of a Read Data action.
In read_immagini Read Data Action you have a section "Not found". So you can put a Read Data Action for all items in this section. So you read your records like you will if {data:read_immagini} is null.
ieraora 07 Feb, 2022
Answer
Thank you for your replay, At the end I solved with 2 read data and relatives DATA > Run Condition.
I knew there was this way, but I wanted to know if a function could be loaded in where conditions.
Thanks.
You need to login to be able to post a reply.