protected function initQuery() { if ($this->rows instanceof \PDOStatement) { $this->cleanupResults(); } $this->rows = $this->fromDbHelper->getAdapter()->prepare($this->query . ' LIMIT ' . $this->start . ', ' . $this->loadAtOnce); $this->rows->execute(); $this->currentPosition = 0; }
/** * Returns the archive list as strings looking like this: '2014-01' * * @param \DateTime $from * @param \DateTime $to * * @return string[] */ public function getArchiveList(\DateTime $from = null, \DateTime $to = null) { $tablePrefix = $this->database->prefixTable('archive_numeric_'); // We can't use Piwik\DataAccess\ArchiveTableCreator::getTablesArchivesInstalled() // because of the global DB object: it will use the "sourceDb" instead of the "targetDb"... // TODO Fix later when we have dependency injection $archives = $this->database->getAdapter()->fetchCol("SHOW TABLES LIKE '" . $tablePrefix . "%'"); $archives = array_map(function ($value) use($tablePrefix) { return str_replace($tablePrefix, '', $value); }, $archives); $archives = array_filter($archives, function ($archive) use($from, $to) { $date = new \DateTime(str_replace('_', '-', $archive) . '-01'); $excluded = $from && $from > $date || $to && $to < $date; return !$excluded; }); return array_values($archives); }
private function getArchiveId($archiveDate, $archiveId) { if (!isset($this->archiveIdMap[$archiveDate][$archiveId])) { $sequence = new Sequence($this->targetDb->prefixTable('archive_numeric_' . $archiveDate), $this->targetDb->getAdapter(), $this->targetDb->prefixTable('')); if (!$sequence->exists()) { $sequence->create(); } $this->archiveIdMap[$archiveDate][$archiveId] = $sequence->getNextId(); } return $this->archiveIdMap[$archiveDate][$archiveId]; }
public function test_getAdapter() { $this->assertEquals($this->adapter, $this->dbHelper->getAdapter()); }