PHP 5.5 - using yield with PDO transactions, is it possible? -


i want make use of generators handle on chunks of data database query while using minimum ammount of memory @ same time (one of advantage generators).

the problem i've found while using generators associated piece of code:

if (!empty($this->attributes["queries"])) {     if (!empty($query)) {         if (!empty($this->attributes["queries"][$query])) {             $this->attributes["queries"][$query]->output();         }     } else {         foreach ($this->attributes["queries"] $query) {             $query->output();         }     } } 

optimizations aside, code is:

  1. checks if have allocated sql query
  2. checks if specific sql query given execute (ignore other)
  3. in case specific sql query given , exists, execute output()
  4. if no specific sql query given, traverse sql queries , execute them output()

the problem works flawlessly kind of sql query except used one: select.

the problem lies within piece of code:

if (!empty($query)) {     if (!empty($this->attributes["queries"][$query])) {         if ($this->attributes["queries"][$query]->attributes["type"] === "select") {             if ($output = $this->attributes["link"]->prepare($this->attributes["queries"][$query]->attributes["query"], [\pdo::attr_cursor => \pdo::cursor_fwdonly])) {                 if ($output->execute(!empty($this->attributes["queries"][$query]->attributes["parameters"]) ? $this->attributes["queries"][$query]->attributes["parameters"] : null)) {                     while ($row = $output->fetch(\pdo::fetch_assoc)) {                         yield $row;                     }                 }             }         }     } } 

this method (called input differentiate output method executes other function) follows same logic.

  • checks if specified sql query exists
  • prepares sql query specified query/parameters pair
  • execute sql query , yield results

i'm bit lost here light on subject. seems yielding data row makes other execution branch unusable (i can perform many select queries want, no transactional operation works (create, insert, update, etc. isn't issued or executed not commited).

can give me (or me design) piece of pseudo code reflect correct pattern this? if code php 5.5 lot there's still things don't know or haven't experienced, bit of appreciated :)

edit: mean input() , output() methods scheme works only if separate select query own input() method (so using generator doesn't break other sql queries) , leave output() method other sql operation.


Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -