/** * Fetch all rows of the result set as an array of key-value pairs * * The first column is the key, the second column is the value. * * @param DbQuery $query * * @return array */ public function fetchPairs(DbQuery $query) { return $this->dbAdapter->fetchPairs($query->getSelectQuery()); }
/** * {@inheritdoc} */ public function _getGroup() { throw new NotImplementedError('Does not work in its current state but will, probably, in the future'); // TODO: order by?? $group = parent::getGroup(); if (!empty($group) && $this->ds->getDbType() === 'pgsql') { $group = is_array($group) ? $group : array($group); foreach ($this->columns as $alias => $column) { if ($column instanceof Zend_Db_Expr) { continue; } // TODO: What if $alias is neither a native nor a custom alias??? $table = $this->aliasToTableName($this->hasAliasName($alias) ? $alias : $this->customAliasToAlias($alias)); // TODO: We cannot rely on the underlying select here, tables may be joined multiple times with // different aliases so the only way to get the correct alias here is to register such by ourself // for each virtual column (We may also inspect $column for the alias but this will probably lead // to false positives.. AND prevents custom implementations from providing their own "mapping") if (($tableAlias = $this->getJoinedTableAlias($this->prefix . $table)) === null) { $tableAlias = $table; } // TODO: Same issue as with identifying table aliases; Our virtual tables are not named exactly how // they are in the IDO. We definitely need to register aliases explicitly (hint: DbRepository // is already providing such..) $aliasedPk = $tableAlias . '.' . $this->getPrimaryKeyColumn($table); if (!in_array($aliasedPk, $group)) { $group[] = $aliasedPk; } } } return $group; }
/** * {@inheritdoc} */ public function getGroup() { $group = parent::getGroup() ?: array(); if (!is_array($group)) { $group = array($group); } foreach ($this->groupOrigin as $table) { if ($this->hasJoinedVirtualTable($table)) { $groupedTables = array(); foreach ($this->groupBase as $table => $columns) { foreach ($columns as $column) { $group[] = $column; } $groupedTables[$table] = true; } if ($this->getDatasource()->getDbType() !== 'pgsql') { return $group; } $columnIterator = new AppendIterator(); $columnIterator->append(new ColumnFilterIterator($this->columns)); $columnIterator->append(new ArrayIterator($this->orderColumns)); foreach ($columnIterator as $alias => $column) { $alias = $this->hasAliasName($alias) ? $alias : $this->customAliasToAlias($alias); if ($this->handleGroupColumn($alias, $group, $groupedTables) === true) { continue; } $tableName = $this->aliasToTableName($alias); if (isset($groupedTables[$tableName])) { continue; } switch ($tableName) { case 'checktimeperiods': $group[] = 'ctp.timeperiod_id'; break; case 'contacts': $group[] = 'co.object_id'; $group[] = 'c.contact_id'; break; case 'hostobjects': $group[] = 'ho.object_id'; break; case 'hosts': $group[] = 'h.host_id'; break; case 'hostgroups': $group[] = 'hgo.object_id'; $group[] = 'hg.hostgroup_id'; break; case 'hoststatus': $group[] = 'hs.hoststatus_id'; break; case 'instances': $group[] = 'i.instance_id'; break; case 'servicegroups': $group[] = 'sgo.object_id'; $group[] = 'sg.servicegroup_id'; break; case 'serviceobjects': $group[] = 'so.object_id'; break; case 'serviceproblemsummary': $group[] = 'sps.unhandled_services_count'; break; case 'services': $group[] = 'so.object_id'; $group[] = 's.service_id'; break; case 'servicestatus': $group[] = 'ss.servicestatus_id'; break; case 'timeperiods': $group[] = 'ht.timeperiod_id'; $group[] = 'st.timeperiod_id'; break; default: continue 2; } $groupedTables[$tableName] = true; } break; } } return array_unique($group); }
/** * {@inheritdoc} */ public function getGroup() { $group = parent::getGroup() ?: array(); if (!is_array($group)) { $group = array($group); } $joinedOrigins = array_filter($this->groupOrigin, array($this, 'hasJoinedVirtualTable')); if (empty($joinedOrigins)) { return $group; } $groupedTables = array(); foreach ($this->groupBase as $baseTable => $aliasedPks) { $groupedTables[$baseTable] = true; foreach ($aliasedPks as $aliasedPk) { $group[] = $aliasedPk; } } foreach (new ColumnFilterIterator($this->columns) as $desiredAlias => $desiredColumn) { $alias = is_string($desiredAlias) ? $this->customAliasToAlias($desiredAlias) : $desiredColumn; $table = $this->aliasToTableName($alias); if ($table && !isset($groupedTables[$table]) && (in_array($table, $joinedOrigins, true) || $this->getDatasource()->getDbType() === 'pgsql')) { $this->registerGroupColumns($alias, $table, $group, $groupedTables); } } if (!empty($group) && $this->getDatasource()->getDbType() === 'pgsql') { foreach (new ColumnFilterIterator($this->orderColumns) as $alias) { $table = $this->aliasToTableName($alias); if ($table && !isset($groupedTables[$table]) && !in_array($this->getMappedField($alias), $this->columns, true)) { $this->registerGroupColumns($alias, $table, $group, $groupedTables); } } } return array_unique($group); }