fix update query

This commit is contained in:
Dennis Eichhorn 2023-09-27 18:16:48 +00:00
parent ee9391fd97
commit e07798e3b6
3 changed files with 6 additions and 15 deletions

View File

@ -1027,7 +1027,7 @@ class Builder extends BuilderAbstract
/** /**
* Update columns. * Update columns.
* *
* @param mixed ...$columns Column names to update * @param string $table Column names to update
* *
* @return Builder * @return Builder
* *
@ -1036,23 +1036,14 @@ class Builder extends BuilderAbstract
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public function update(mixed ...$columns) : self public function update(string $table) : self
{ {
if ($this->isReadOnly) { if ($this->isReadOnly) {
throw new \Exception(); throw new \Exception();
} }
$this->type = QueryType::UPDATE; $this->type = QueryType::UPDATE;
$this->updates[] = $table;
/** @var mixed[] $columns */
/** @var mixed $table */
foreach ($columns as $column) {
if (\is_string($column) || $column instanceof self) {
$this->updates[] = $column;
} else {
throw new \InvalidArgumentException();
}
}
return $this; return $this;
} }

View File

@ -166,7 +166,7 @@ class CsvDatabaseMapper implements IODatabaseMapper
// update data // update data
while (($cells = \fgetcsv($fp)) !== false) { while (($cells = \fgetcsv($fp)) !== false) {
$query = new Builder($this->con); $query = new Builder($this->con);
$query->update(...$titles)->into($table); $query->update($table);
for ($j = 2; $j <= $columns; ++$j) { for ($j = 2; $j <= $columns; ++$j) {
$query->sets((string) $titles[$j - 2], $cells[$j - 1]); $query->sets((string) $titles[$j - 2], $cells[$j - 1]);

View File

@ -221,7 +221,7 @@ class SpreadsheetDatabaseMapper implements IODatabaseMapper
$line = 2; $line = 2;
while (!empty($workSheet->getCell('A' . $line)->getCalculatedValue())) { while (!empty($workSheet->getCell('A' . $line)->getCalculatedValue())) {
$query = new Builder($this->con); $query = new Builder($this->con);
$query->update(...$titles)->into($table); $query->update($table);
for ($j = 2; $j <= $columns; ++$j) { for ($j = 2; $j <= $columns; ++$j) {
$query->sets((string) $titles[$j - 2], $workSheet->getCell(StringUtils::intToAlphabet($j) . $line)->getCalculatedValue()); $query->sets((string) $titles[$j - 2], $workSheet->getCell(StringUtils::intToAlphabet($j) . $line)->getCalculatedValue());