Radicore Forum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » RADICORE development » Transaction Patterns » add5 - Data Area
add5 - Data Area [message #7317] Wed, 17 July 2019 06:59 Go to next message
htManager is currently offline  htManager
Messages: 433
Registered: May 2014
Senior Member
Hi Tony,

I want to use an add5 pattern to insert multiple records into a table. I read in your documentation that I have to generate these records in the _cm_getInitialDataMultiple function. I wanted to see how you did this but I couldn't find the code in the prototype applications.
Can you please tell me where I can find this code?

Best regards,

Juergen
Re: add5 - Data Area [message #7318 is a reply to message #7317] Thu, 18 July 2019 05:29 Go to previous messageGo to next message
AJM is currently offline  AJM
Messages: 2367
Registered: April 2006
Location: Surrey, UK
Senior Member
There is no sample code for every pattern in the prototype applications as the circumstances which merit their use simply do not exist. You should be aware that the _cm_getInitialDataMultiple() method is only called once when the task is started and before the screen is displayed. It has one input argument called $fieldarray which initially contains any foreign key data which links it to the parent entity. This is also used as the output argument, so what you need to do is replace $fieldarray with a collection of as many rows as you like with whatever data you like.
function _cm_getInitialDataMultiple ($fieldarray)
{
    $parent_data = $fieldarray;
    $fieldarray = array();  // clear current data

    while (...)
        // create initial data for first row
        $row = $this->_cm_getInitialData($parent_data);
        $row['field1'] = 'whatever';
        $row['field2'] = 'whatever';
        $fieldarray[] = $row;
    } // while

    return $fieldarray;

} // _cm_getInitialDataMultiple
How many rows you create in $fieldarray is entirely up to you. It may be a fixed number, or it may depend on the contents of another table.


Re: add5 - Data Area [message #7320 is a reply to message #7318] Fri, 19 July 2019 06:42 Go to previous messageGo to next message
htManager is currently offline  htManager
Messages: 433
Registered: May 2014
Senior Member
I can now generate the records which I want to insert. Everything works fine so far. But if I select some records and want to insert them in the child database I get the following error message:

Fatal Error: Uncaught exception from Error, message = Call to a member function array_update_associative() on null, code=0, file=C:\xampp\htdocs\radicore\includes\std.add5.inc, line=140, file = C:\xampp\htdocs\radicore\htm\training_plan_anwesenheit(add5) .php
line = 22
function = require
(# 256)

Error in line 463 of file 'C:\xampp\htdocs\radicore\includes\error.inc'.

PHP_SELF: /radicore/htm/training_plan_anwesenheit(add5).php

What did I forget in my code or what did I wrong?
Re: add5 - Data Area [message #7321 is a reply to message #7320] Fri, 19 July 2019 09:26 Go to previous messageGo to next message
AJM is currently offline  AJM
Messages: 2367
Registered: April 2006
Location: Surrey, UK
Senior Member
I accidentally introduced a mistake in script std.add5.inc where line 140 refers to $dbobject instead of $dbouter. Please update yor version and the problem will disappear.

Re: add5 - Data Area [message #7322 is a reply to message #7321] Fri, 19 July 2019 10:17 Go to previous messageGo to next message
htManager is currently offline  htManager
Messages: 433
Registered: May 2014
Senior Member
Perfect. Works fine now. Thank you.
All records will be inserted in the child database even if selected or not. This means that I have to delete not wanted records before submit as described in FAQ 156?
Re: add5 - Data Area [message #7323 is a reply to message #7322] Sat, 20 July 2019 04:14 Go to previous messageGo to next message
AJM is currently offline  AJM
Messages: 2367
Registered: April 2006
Location: Surrey, UK
Senior Member
You do not create several rows in the screen and then select which ones you wish to add to the database - all available rows which are not marked as deleted will be added. If you wish to add more rows than were initially created in the _cm_getInitialDataMultiple() method, or remove rows that you do not actually wish to add, then FAQ 156 is indeed the answer.

Re: add5 - Data Area [message #7324 is a reply to message #7323] Mon, 22 July 2019 04:13 Go to previous messageGo to next message
htManager is currently offline  htManager
Messages: 433
Registered: May 2014
Senior Member
As you mentioned, I do not need to delete rows in an add5 pattern. If I want to insert an additional single record, I do this with an add2 menu task.
Now my question: I select the records in the _cm_getInitialDataMultiple ($fieldarray) function where I get records from a foreign table via the line "$data = $dbobject->getData ($where);"
I tried to show them in a different order but I failed.
Is there the possibility to use $orderby or is the only possibility to sort the $fieldarray before it will be returned?
Re: add5 - Data Area [message #7325 is a reply to message #7324] Mon, 22 July 2019 04:39 Go to previous messageGo to next message
AJM is currently offline  AJM
Messages: 2367
Registered: April 2006
Location: Surrey, UK
Senior Member
Before you use the line "$data = $dbobject->getData()" you can set the ORDER BY sequence using "$dbobject->sql_orderby = 'whatever'". This is documented in https://www.tonymarston.net/php-mysql/functions-and-variable s.html#notes.getdata

Re: add5 - Data Area [message #7326 is a reply to message #7325] Mon, 22 July 2019 06:06 Go to previous message
htManager is currently offline  htManager
Messages: 433
Registered: May 2014
Senior Member
Perfect. Thank you. Works now how I want.
And I have now seen how to use the different variables.

[Updated on: Mon, 22 July 2019 06:07]

Report message to a moderator

Previous Topic: SQL error generating list2 pattern
Next Topic: Output2 - SQL
Goto Forum:
  


Current Time: Fri Nov 22 22:21:59 EST 2024

Total time taken to generate the page: 0.01449 seconds