Similar questions have been asked multiple times but I have gone through them and couldn't find a solution.
I am trying to import a simple CSV file containing around 500 orders into my database table. And I am using transactions as shown below.
$dbAdapter->beginTransaction();
$file = new SplFileObject($fileName, 'r');
while(!$file->eof()){
try{
$order = $file->fgetcsv();
if(!$this->orderExists($order)){
$this->saveOrder($order);
}
} catch (Exception $ex) {
$dbAdapter->rollBack();
throw new Om_Model_Exception($ex->getMessage());
}
}
$dbAdapter->commit();
This works fine. But the same CSV file can have duplicate orders and I need to skip them. To do that before inserting the order I am checking the database table to see if the order exists but this always returns false because the transaction is still running.
So my question is, is there a way to check for inserted records before the transaction is committed? (May be MySQL stores data in to a temporary table and I can query that).
I can solve this by storing orders into an array and checking the array for duplicates but this seems like a waste of lot of memory. And might not work properly if the order file is large.
Thanks for your help.