public function testProperties() { $composite = $this->getMockBuilder('Faker\\Components\\Engine\\Common\\Composite\\CompositeInterface')->getMock(); $values = array('value' => 1); $id = 'table1'; $type = new GenerateEvent($composite, $values, $id); $this->assertSame($values, $type->getValues()); $this->assertSame($id, $type->getId()); $this->assertSame($composite, $type->getNode()); }
/** * Handles Event FormatEvents::onColumnEnd * * @param GenerateEvent $event */ public function onColumnEnd(GenerateEvent $event) { $values = $event->getValues(); $columnId = $event->getNode()->getId(); $writer = $this->getWriter(); $platform = $this->platform; $value = $this->valueConverter->convertValue($columnId, $platform, $values[$columnId]); if ($value !== null) { $writer->write('<value>' . \htmlentities($value) . '</value>' . PHP_EOL); } else { $writer->write('<null />'); } }
/** * Handles Event FormatEvents::onRowEnd * * @param GenerateEvent $event */ public function onRowEnd(GenerateEvent $event) { # iterate over the values and convert run them through the column map $values = $event->getValues(); $platform = $this->getPlatform(); $writer = $this->getWriter(); $table = $event->getNode()->getId(); $q = $platform->getIdentifierQuoteCharacter(); foreach ($values as $key => &$value) { $value = $this->valueConverter->convertValue($key, $platform, $value); } # build insert statement # column names add quotes to them $column_keys = array_map(function ($value) use($q) { return $q . $value . $q; }, array_keys($values)); $column_values = array_map(function ($value) { if (is_string($value)) { $value = "'" . str_replace("'", "''", $value) . "'"; } if (is_null($value) === true) { $value = 'NULL'; } return $value; }, array_values($values)); if (count($column_keys) !== count($column_values)) { throw new EngineException('Keys do not have enough values'); } $stm = 'INSERT INTO ' . $q . $table . $q . ' (' . implode(',', $column_keys) . ') VALUES (' . implode(',', $column_values) . ');' . PHP_EOL; unset($values); unset($column_keys); unset($column_values); $writer->write($stm); return $stm; }
/** * Handles Event FormatEvents::onRowEnd * * @param GenerateEvent $event */ public function onRowEnd(GenerateEvent $event) { $this->bar->next(1, 'Table ' . $event->getNode()->getId()); }
/** * Event hander for FormatEvents::onTableStart run before * other event handlers and will execute the DBALGathererVisitor * * @access public */ public function beforeTableStart(GenerateEvent $event) { $node = $event->getNode(); $visitor = $this->getVisitor(); $node->acceptVisitor($visitor); $this->valueConverter = $visitor->getResult(); }
/** * Handles Event FormatEvents::onTableEnd * * @param GenerateEvent $event */ public function onTableEnd(GenerateEvent $event) { $table_name = $event->getId(); $memory = $this->formatMemory(memory_get_usage()); $peak = $this->formatMemory(memory_get_peak_usage()); $this->output->writeln(sprintf('Finished Writing Table %s <info> memory_start= %s </info> <comment> memory_peak= %s </comment>', $table_name, $memory, $peak)); $this->row = 0; }