public function fetch() { $options = $this->getOptionManager()->getOptions(); if ($this->reporter) { $this->reporter->setFetchedLines(++$this->line); } return fgetcsv($this->handler, $options['length'], $options['delimiter'], $options['enclosure'], $options['escape']); }
public function write($line) { $options = $this->getOptions(); $keys = '"' . implode('","', array_map('trim', array_keys($line))) . '"'; // escaping values $values = array_map('XtoY\\Writer\\SQLWriter::escaping', array_values($line)); //imploding $values = '"' . implode('","', $values) . '"'; $sql = sprintf('INSERT INTO %s (%s) VALUES(%s)' . "\n", $options['table'], $keys, $values); fputs($this->document, $sql); if ($this->reporter) { $this->reporter->setWrittenLines(++$this->line); } }
public function write($line) { $translation = $this->document->createElement('trans-unit'); $translation->setAttribute('id', md5($line['source'])); $translation->setAttribute('resname', $line['source']); $s = $translation->appendChild($this->document->createElement('source')); $s->appendChild($this->document->createTextNode($line['source'])); $t = $translation->appendChild($this->document->createElement('target')); $t->appendChild($this->document->createTextNode($line['target'])); $this->body->appendChild($translation); if ($this->reporter) { $this->reporter->setWrittenLines(++$this->line); } }
public function fetch() { $returnValue = false; if ($this->currentRow < $this->nbRow) { $returnValue = array(); for ($c = 1; $c <= $this->nbCol; $c++) { $returnValue[$c - 1] = utf8_encode($this->handler->val($this->currentRow, $c)); } if ($this->reporter) { $this->reporter->setFetchedLines($this->currentRow); } $this->currentRow++; } return $returnValue; }
public function batchConvert($datas) { $returnValue = array(); $rules = $this->getRules(); foreach ($datas as $idx => $line) { $returnValue[$idx] = array(); foreach ($rules as $outputField => $ruleConfig) { $returnValue[$idx][$outputField] = $this->applyRule($line, $ruleConfig); } if ($this->reporter) { $this->reporter->setMappedLines(++$this->line); } } return $returnValue; }
public function fetch($raw = false) { $options = $this->getOptions(); $returnValue = false; if ($this->handler->valid()) { $returnValue = $this->handler->current(); $this->handler->next(); if ($options['firstline_as_keys'] && !$raw) { $nbValue = count($returnValue); $nbKeys = count($this->keys); if ($nbValue < $nbKeys) { for ($i = $nbValue; $i < $nbKeys; $i++) { $returnValue[$i] = ""; } } elseif ($nbValue > $nbKeys) { throw new \Exception('Missing column names'); } $returnValue = array_combine($this->keys, $returnValue); } if ($this->reporter) { $this->reporter->setFetchedLines(++$this->line); } } return $returnValue; }
public function write($line) { $options = $this->getOptions(); $keys = '' . implode(',', array_map('trim', array_keys($line))) . ''; $marks = implode(',', array_fill(0, count(array_keys($line)), '?')); $sql = sprintf('INSERT INTO %s (%s) VALUES(%s)' . "\n", $options['table'], $keys, $marks); $sth = $this->dbh->prepare($sql); try { $sth->execute(array_values($line)); } catch (\PDOException $e) { if (!$options['ignore_duplicate'] || $e->getCode() != 23000) { throw $e; } } if ($this->reporter) { $this->reporter->setWrittenLines(++$this->line); } }
public function write($line) { $options = $this->getOptions(); $cond = array(); foreach ($options['where'] as $f) { $cond[] = $f . '=' . $this->dbh->quote($line[$f]); unset($line[$f]); // if in where doesn't need to be updated } $fields = array(); foreach ($line as $k => $v) { $fields[] = $k . '=' . $this->dbh->quote($v); } $sql = sprintf('UPDATE %s SET %s WHERE %s' . "\n", $options['table'], implode(',', $fields), implode(' AND ', $cond)); $sth = $this->dbh->exec($sql); if ($this->reporter) { $this->reporter->setWrittenLines(++$this->line); } }