Preventing Duplicate data from saving in to Database from a repeatable area

shahabpk 17 Oct, 2019
I created a Chronoform with the repeatable area to save data into a table. I want to prevent duplicate data from saving into the database. So what I did is
1. created a loop event loop_event6 under Submit event
2. Inside loop_event6 body , created a read_data action read_data12 with field matching conditions using WHERE and Return First matching record. ( it returns the record in debug)
3. Under the not found section read_data12, I put the save data action save_data7

But when I do a trial test, even though the messages are correctly says duplicate found , It still saves the data in to Table.

Please help!
Preventing Duplicate data from saving in to Database from a repeatable area image 1



Debug info is attached below
https://imgbbb.com/image/LraoJ7
healyhatman 17 Oct, 2019
And what's in the "found" branch?
shahabpk 17 Oct, 2019
In the found branch I put just an error message saying Data already exits in table!

It works correctly when I enter only one row in repeater. When I tested it with more than one row including one existing record, It saves the data to DB but shows the message from found branch
healyhatman 17 Oct, 2019
What the data source for the save data, and have you turned OFF auto save fields?
shahabpk 18 Oct, 2019
Data Source is repeater data named "group"
Auto Save fields is off
Preventing Duplicate data from saving in to Database from a repeatable area image 2


And if the View section is of any importance, it is attached below.


Preventing Duplicate data from saving in to Database from a repeatable area image 3
shahabpk 19 Oct, 2019
Is this approach to prevent already saved records from saving again is correct? Or is there any inbuilt feature available in Chronoform?
Fredolino 05 Mar, 2020
Hi there,

i have exactly the same problem in CF 6.
Have you been able to solve this with the duplicate message in the meantime?
A duplicate message comes:
1062 Duplicate entry '899-1527-o. A.-Imago 'for key' FundArtGeschlechtStadiumIdx '
and no duplicate entries are saved.

The duplicate message relates to these indexes.

Preventing Duplicate data from saving in to Database from a repeatable area image 4
Fredolino 09 Mar, 2020
Hi,
So I tried to solve the problem for a few days now.
But it has to be a BUG in CF.
My settings in the backend are correct, but this MYSQL error message with "duplicate …" always comes, even though no duplicate data record is saved in the database.

Does somebody has any idea?

F.
healyhatman 09 Mar, 2020
So you either have the read data with a save data in the FOUND branch set to "update", and MAKE SURE YOU ACTUALLY PUT AN UPDATE CONDITION IN, and then in the not found branch you have it set to Insert

OR you can set it to insert - on duplicate update, but you need to be passing in the id and if you're relying on the data source instead of manually overriding all the columns you want then your field names and your database table column names all have to exactly match.

And you shouldn't turn on Auto Manage Table unless you want your table columns automatically decided by CF instead of creating your table yourself.
Fredolino 09 Mar, 2020
But where should the mistake be here?

Preventing Duplicate data from saving in to Database from a repeatable area image 5
healyhatman 09 Mar, 2020
Pretty sure stop means if this value is empty go to the error branch
Fredolino 10 Mar, 2020
Hi,

I tested different versions with "notfound" and "fail". But it is unsuccessful.

The 1st duplicate check with read_data48 (Duplikatsprüfung Fundortdaten) works.
But in the loop with read_data100 the duplicate check apparently does not work (Duplikatsprüfung Arten) although the duplicate check is the same.

I also switched off all actions and deactivated the save data for various tests. I don't know why the data is not saved in the loop.
healyhatman 10 Mar, 2020
Put a debugger, and then another debugger with the name of the loop (so should be just loop_event31.row) and then a stop after the read data inside the loop and have a look at the data available on the debug screen that gets printed.
Fredolino 10 Mar, 2020
Hi,

I tested it with the "stopper" and "debugger" at various points in the loop.
The debugger doesn't give me an answer. But the "stopper" showed me the following situation. Example:

1. Testposition  with stopper
I select from the dropdown in the repeater:
1. aruncella
2. aureatella
3. aruncella
Only 1x aureatella is saved. This result is not correct.

2. Testposition with stopper
I select from the dropdown in the repeater:
1. aruncella
2. aureatella
3. aruncella
It saves 1x aureatella and 1x aruncella.

The result is correct! But!
In this case, the MySQL error message comes first from the database (Duplicate ...).
If I click away this error message, I can see that the data has been saved correctly.

I have no idea what else I can do...
Fredolino 13 Mar, 2020
Hi,

I don't find the problem. And I can't use the debugger here.

I used 2 "stoppers".
The stopper "stopper_success_message" shows me a success message, but only saves me one record.
However, 2 data records out of a total of 3 data records must be saved in the repeater / loop.
The result is wrong.

The stopper "stopper_duplicate_key" shows me the System / Mysql-Duplicate error message.
But 2 of the 3 data records are still saved.
The result is correct.

Where is the mistake? Or does this duplicate check not work in chronoforms / loop?Preventing Duplicate data from saving in to Database from a repeatable area image 6
healyhatman 13 Mar, 2020
Of course it only saves one man, the stopper STOPS the execution that's the point, to see if the data in the debug is correct.
Fredolino 14 Mar, 2020
I only have the 2 stoppers in view.
If I remove the stopper "stopper_success_message", the function stops at the 2nd stopper (stopper_duplicate_key)
This is where this duplicate entry ... error message comes from the database. But the storage in the database is correct.
I can not find a place to intercept the error message and at the same time to save the data correctly. How does that work?



Array
(
    [chronoform] => beobachtungen
    [event] => submit
    [datum] => 2020-03-13
    [datum_2] => 2020-03-13
    [Data25] => Array
        (
            [beo_id] => 46
        )

    [Fund] => Array
        (
            [beobachtung] => Am Licht
            [teilnehmer] => 
        )

    [Data26] => Array
        (
            [beobachter] => Fred Ockruck
        )

    [group] => Array
        (
            [1] => Array
                (
                    [art_id] => 2697
                    [anzahl] => 1
                    [haufigkeit] => o. A.
                    [stadium] => Imago
                    [geschlecht] => o. A.
                    [bestimmung] => Ohne Angabe
                    [bemerkung] => 
                    [photo] => 
                    [datenweitergabe] => 1
                )

            [2] => Array
                (
                    [art_id] => 3038
                    [anzahl] => 1
                    [haufigkeit] => o. A.
                    [stadium] => Imago
                    [geschlecht] => o. A.
                    [bestimmung] => Ohne Angabe
                    [bemerkung] => 
                    [photo] => 
                    [datenweitergabe] => 1
                )

            [3] => Array
                (
                    [art_id] => 2697
                    [anzahl] => 1
                    [haufigkeit] => o. A.
                    [stadium] => Imago
                    [geschlecht] => o. A.
                    [bestimmung] => Ohne Angabe
                    [bemerkung] => 
                    [photo] => 
                    [datenweitergabe] => 1
                )

        )

    [button13] => 
    [joomla_remember_me_400fb1be758b35dd0d28327aa8b83b1d] => oqSQoWhVRJrIfvbe.GIoNJsKtV1EJdFOEdsS7
    [99b2d8d194748b816f5a52b3f980c167] => 48e2aab3071c010ff04a8ae0030b2518
    [84a67b6ec4a2db8ac9e867546b14d6f3] => 7f8da095b0debdfe3d06b3012720ce85
    [joomla_user_state] => logged_in
    [Itemid] => 112
    [option] => com_content
    [view] => article
    [id] => 1
    [beobachtungen] => 
)
Array
(
    [read_data48] => Array
        (
            [log] => Array
                (
                    [0] => SELECT `beobachtung`.`beof_id` AS `beobachtung.beof_id` FROM `mtb_beobachtung` AS `beobachtung` WHERE `beobachtung`.`user_id` = '909' AND `beobachtung`.`beo_id` = '46' AND `beobachtung`.`datum` = '2020-03-13' AND `beobachtung`.`datum_2` = '2020-03-13' AND `beobachtung`.`beobachtung` = 'Am Licht' AND `beobachtung`.`teilnehmer` = '';
                )

            [var] => 
        )

    [upload12] => Array
        (
            [path] => /www/htdocs/v096152/__test1/components/com_chronoforms6/chronoforms/uploads/
            [photo] => Array
                (
                    [extensions] => Array
                        (
                            [0] => jpg
                            [1] => jpeg
                        )

                    [info] => File is not present.
                )

            [group.[n].photo] => Array
                (
                    [extensions] => Array
                        (
                            [0] => jpg
                            [1] => jpeg
                        )

                )

            [group.1.photo] => Array
                (
                    [saved] => 0
                )

            [var] => Array
                (
                    [group] => Array
                        (
                            [1] => Array
                                (
                                    [photo] => Array
                                        (
                                        )

                                )

                        )

                )

        )

    [save_data30] => Array
        (
            [data] => Array
                (
                    [beobachtung] => Am Licht
                    [teilnehmer] => 
                    [created] => 2020-03-14 00:29:56
                    [user_id] => 909
                    [modified] => 2020-03-14 00:29:56
                    [beo_id] => 46
                    [datum] => 2020-03-13
                    [datum_2] => 2020-03-13
                )

            [_success] => Data saved successfully
            [log] => Array
                (
                    [0] => INSERT INTO `mtb_beobachtung` (`beobachtung`, `teilnehmer`, `created`, `user_id`, `modified`, `beo_id`, `datum`, `datum_2`)  values  ('Am Licht', '', '2020-03-14 00:29:56', '909', '2020-03-14 00:29:56', '46', '2020-03-13', '2020-03-13');
                )

            [var] => Array
                (
                    [beobachtung] => Am Licht
                    [teilnehmer] => 
                    [created] => 2020-03-14 00:29:56
                    [user_id] => 909
                    [modified] => 2020-03-14 00:29:56
                    [beo_id] => 46
                    [datum] => 2020-03-13
                    [datum_2] => 2020-03-13
                    [beof_id] => 1049
                )

        )

    [Check Photo (set no_image)] => Array
        (
            [finished] => 1
            [var] => 
        )

    [read_data100] => Array
        (
            [log] => Array
                (
                    [0] => SELECT `Data100`.`beo_art_id` AS `Data100.beo_art_id` FROM `mtb_beobachtung_art` AS `Data100` WHERE `Data100`.`beof_id` = '1049' AND `Data100`.`stadium` = 'Imago' AND `Data100`.`geschlecht` = 'o. A.' AND `Data100`.`art_id` = '2697';
                )

            [var] => 
        )

    [save_data44] => Array
        (
            [data] => Array
                (
                    [art_id] => 2697
                    [anzahl] => 1
                    [haufigkeit] => o. A.
                    [stadium] => Imago
                    [geschlecht] => o. A.
                    [bestimmung] => Ohne Angabe
                    [bemerkung] => 
                    [photo] => no_image.png
                    [datenweitergabe] => 1
                    [created] => 2020-03-14 00:29:56
                    [beof_id] => 1049
                )

            [_success] => Data saved successfully
            [log] => Array
                (
                    [0] => INSERT INTO `mtb_beobachtung_art` (`art_id`, `anzahl`, `haufigkeit`, `stadium`, `geschlecht`, `bestimmung`, `bemerkung`, `photo`, `datenweitergabe`, `created`, `beof_id`)  values  ('2697', '1', 'o. A.', 'Imago', 'o. A.', 'Ohne Angabe', '', 'no_image.png', '1', '2020-03-14 00:29:56', '1049');
                )

            [var] => Array
                (
                    [art_id] => 2697
                    [anzahl] => 1
                    [haufigkeit] => o. A.
                    [stadium] => Imago
                    [geschlecht] => o. A.
                    [bestimmung] => Ohne Angabe
                    [bemerkung] => 
                    [photo] => no_image.png
                    [datenweitergabe] => 1
                    [created] => 2020-03-14 00:29:56
                    [beof_id] => 1049
                    [beo_art_id] => 1691
                )

        )

)
Fredolino 14 Mar, 2020
Does the problem with the duplicate error message have something to do with the use of "Event loader"?

If I set an event loader in the save_data30 in the success behind the loop event and in the loop event in the body behind the save_data44, the results change depending on the event loader content.

It is also saved correctly when I update the MySQL Duplicate error message page once in the browser.
Because I then come directly to the error message page I have used.
healyhatman 14 Mar, 2020
You must be saving a duplicate id. Try clear the data source of the inner save data and use the overrides instead, if you can't figure out what you're doing wrong using the stoppers and debugs
Fredolino 15 Mar, 2020
I have no idea how to do that. Save the ID twice.

I get this message:
1062 Duplicate entry '1178-2697-o. A.-Imago 'for key' FundArtGeschlechtStadiumIdx '
But the correct data is saved.

The one that was selected twice in the repeater / loop is also saved correctly only once at the same time.
1178-2697-o. A.-Imago belong in the columns of the table "mtb_beobachtung_art"
1178 is saved correctly in the "beof_id" column
2697 is saved correctly in the "art_id" column

The "art_id" "3038" is not at the top of the "Duplicate entry ...". But it is also saved together in the database.
"o. A." and "Imago" are also saved correctly in the columns "stadium" and "geschlecht".

Anyway, I don't have a plan anymore ….
This topic is locked and no more replies can be posted.