Ejemplo n.º 1
0
 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());
 }
Ejemplo n.º 2
0
 /**
  *  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 />');
     }
 }
Ejemplo n.º 3
0
 /**
  *  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;
 }
Ejemplo n.º 4
0
 /**
  *  Handles Event FormatEvents::onRowEnd
  *
  *  @param GenerateEvent $event
  */
 public function onRowEnd(GenerateEvent $event)
 {
     $this->bar->next(1, 'Table ' . $event->getNode()->getId());
 }
Ejemplo n.º 5
0
 /**
  *  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();
 }
Ejemplo n.º 6
0
 /**
  *  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;
 }