<?php
 class vB_dB_Query_Update extends vB_dB_Query_TableQuery { public function execSQL() : mixed { if (!$this->data_loaded) { return false; } $querystring = $this->buildQuery($this->params); if (!$querystring) { throw new Exception('invalid_query_definition'); } $this->logQuery($querystring); return $this->doQuery($querystring); } protected function buildQuery(array $values) : string { $queryBuilder = self::$queryBuilders[$this->db_type]; $params = $this->extractParamsFromValues($values); $where = ''; if (!isset($values[self::CONDITIONS_KEY])) { $where = $this->getPrimaryKeyWhere($queryBuilder, $values); if (!$where) { throw new vB_Exception_Assertor('missing_query_condition'); } } else { $where = $this->getWhere($queryBuilder, $values); } $setline = $queryBuilder->valueArrayToSetLine($values, $this->structure['forcetext'] ?? []); return $queryBuilder->makeUpdateQuery($this->queryid, $where, $setline, $params); } private function getPrimaryKeyWhere(vB_dB_QueryBuilder $queryBuilder, array &$values) : string { $primarykey = $this->structure['key'] ?? []; if (!$primarykey) { return ''; } foreach (is_array($primarykey) ? $primarykey : [$primarykey] AS $field) { if (!isset($values[$field])) { return ''; } } return $queryBuilder->primaryKeyToFilter($primarykey, $values, $this->structure['forcetext'] ?? []); } protected function doQuery(string $querystring) : mixed { $this->db->query_write($querystring); $count = $this->db->affected_rows(); $error = $this->db->error(); if (!empty($error)) { throw new Exception($error); } return $count; } } 