<?php
 abstract class vB_dB_Query_TableQuery extends vB_dB_Query { protected array $structure = []; protected $sortorder = false; public function setQuery(array $params, array|string $sortorder) : bool { $this->structure = $this->querydefs->getTableData()[$this->queryid] ?? []; if (!$this->structure) { throw new vB_Exception_Assertor('invalid_query_definition_x', $this->queryid); } $this->params = $params; $this->sortorder = $sortorder; $this->data_loaded = true; return true; } public function execSQL() : mixed { if (!$this->data_loaded) { throw new vB_Exception_Assertor('invalid_query_definition_x', $this->queryid); } $querystring = $this->buildQuery($this->params); if (!$querystring) { return false; } $this->logQuery($querystring); return $this->doQuery($querystring); } protected function getWhere(vB_dB_QueryBuilder $queryBuilder, array $values) : string { $where = ''; if (isset($values[self::CONDITIONS_KEY])) { if (is_string($values[self::CONDITIONS_KEY]) AND $values[self::CONDITIONS_KEY] == self::CONDITION_ALL) { $where = self::CONDITION_ALL; } else { $where = $queryBuilder->conditionsToFilter($values[self::CONDITIONS_KEY], $this->structure['forcetext'] ?? []); } } else { $where = $queryBuilder->valueArrayToFilter($values, $this->structure['forcetext'] ?? []); } return $where; } protected function extractParamsFromValues(array &$values) : array { $params = []; foreach ([self::COLUMNS_KEY, self::PARAM_LIMIT, self::PARAM_LIMITSTART] AS $key) { if (!empty($values[$key])) { $params[$key] = $values[$key]; unset($values[$key]); } } return $params; } abstract protected function buildQuery(array $values) : string; abstract protected function doQuery(string $querystring) : mixed; } 