how do you insert multiple rows in a loop using doctrine 2 - zend-framework

i want to insert multiple rows in a loop using doctrine 2..
i usually insert 1 record using this:
$Entity->setData($posted);
$this->_doctrine->persist($Entity);
$this->_doctrine->flush();

Simply persist all your objects and then call flush() after the loop.
$entityDataArray = array(); // let's assume this is an array containing data for each entity
foreach ($entityDataArray AS $entityData) {
$entity = new \Entity();
$entity->setData($entityData);
$this->_doctrine->persist($entity);
}
$this->_doctrine->flush();
If you're inserting a large number of objects you will want to batch insert (see http://www.doctrine-project.org/docs/orm/2.0/en/reference/batch-processing.html)

Inside your loop, you should be able to simply:
$entity1->setData($data1);
$this->_doctrine->persist($entity1);
$entity2->setData($data2);
$this->_doctrine->persist($entity2);
$this->_doctrine->flush();

Related

Is there a way to work with records that you marked in table on X++?

I want to work with table records that is selected (Marked), Example - I have 10 records in table and i mark 5 of them. Expected - when i work with selected records, it should look only on that 5 records, not whole 10.
So far i have this code that selects all records:
while select Table
where table.JournalId == table.JournalId
Is there a way to make it select only marked records, not everything?
That select is writen in class. I need to get those marked records into that class where that select is writen...
You need to pass the formdatasource object into the class that is selecting the records, and then use the MultiSelectionHelper to loop through the selected records on the formdatasource.
In the example below, the object salesTableFormDataSource needs to be passed in from the form to the class you are using. Obviously replace that with whatever your datasource/table needs are.
MultiSelectionHelper selection = MultiSelectionHelper::construct();
selection.parmDatasource(salesTableFormDataSource);
SalesTable salesTable = selection.getFirst();
while (salesTable)
{
//do something with your table buffer.
salesTable = selection.getNext();
}

Filter TYPO3 results in repository

When querying the repository using a criteria, it returns an object with multiple result sets. Each result set is an object mapped to the model. So one can get the preferred result set using ->offsetGet(). How can I get the preferred result set(s) using a parameter value instead?
Example:
A table has three fields uid, guide_option and fact. Table contains multiple records and is mapped to its model. Query fetches data using field guide_option and returns several rows:
$query = $this->createQuery();
$constraints = [$query->equals('guide_option', $guideOption)];
$query->matching($query->logicalAnd($constraints));
$resultsets = $query->execute();
#filter by offset
$offset = $resultsets->offsetGet(0);
#filter by fact
$set = ???
How does one filter by field fact?

Get First row/id & Last row/id of total inserted result set, instead of only last id/row. SQL,PHP,Codeigniter

function storeReachout($reachoutInfo)
{
$result = $this->db->insert('tbl_youtube',$reachoutInfo);
// $Frow = $result->first_row('array');
// $Lrow = $result->last_row('array');
// $data = aray($result,$Frow,$Lrow);
// $result_id = $this->db->insert_id();
return $result;
}
Above is the code to insert data in DB, if I inserted like 30 records I want to know the first inserted row/id and last row/id. This way I can get a lower limit of ID and upper limit of ID so after I can send emails to in-between IDS.
After posting I found a way to get the first & last inserted ID, I made a foreach loop in my controller to insert each record in a loop and return last_id from my model function and save that last_id in an array in my controller every time the loop iterate it stores a record in DB and gets the last_id and save that last_id in an array. When the loop completes its iteration we will get all the saved IDS from DB in my Array.

Multiple DB update query using Laravel 5

I'm new in Laravel and I'm trying to update mysql table's multiple rows using one query. I need to update for example 100 rows like this:
$q = \DB::table('exmaple')
->where('exampleID', $array)
->update(array('Viewed' => 1));
$array is array with ID-s.
I have try also to implode array to string, then execute query, but with no result. Can anyone help?
Does this work for you:
$q = \DB::table('example')
->whereIn('exampleID', $array)
->update(array('Viewed' => 1));
whereIn() accepts an array as a second parameter so all IDs in this array will be affected by the query.

Track updated columns postgresql trigger?

I am using postgreSQL and I have tables on which I use triggers to get notified of changes on tables.
Now, I have a usecase where when an update on a table is done, I want to notify only the updated columns of my table. So if my table has 10 columns and only 5 get updated I need to notify only of 5 updated columns.
One approach would be use OLD and NEW on every column and compare. This would lead to a separate function for each table.
Is there any functionality in postgreSQL pertianing to such a case?
You can create triggers in pl/tcl or pl/perl.
Both produce all the information about the context of the table that triggers the function in a bunch of variables, and OLD and NEW are associative arrays, so you have a lot of freedom to do whatever you like. Eg:
CREATE OR REPLACE FUNCTION valid_id() RETURNS trigger AS $$
my ($new, $old) = ($_TD->{new}, $_TD->{old});
my (#allflds) = keys %$new;
my (#changed) = grep { $new->{$_} ne %$old->{$_} } #allflds;
my (%difold, %difnew);
%difold = map { _$ => $old->{_$} } #changed;
%difnew = map { _$ => $new->{_$} } #changed;
... notify the values in %difold and %difnew as you need ...
$$ LANGUAGE plperl;