/** * Render the UPDATE statement * * @return string */ public function render() { // Start building the UPDATE statement $sql = 'UPDATE ' . $this->sql->quoteId($this->sql->getTable()) . ' SET '; $set = []; $paramCount = 1; $dbType = $this->sql->getDbType(); foreach ($this->columns as $column => $value) { $colValue = strpos($column, '.') !== false ? substr($column, strpos($column, '.') + 1) : $column; // Check for named parameters if (':' . $colValue == substr($value, 0, strlen(':' . $colValue)) && $dbType !== \Pop\Db\Sql::SQLITE && $dbType !== \Pop\Db\Sql::ORACLE) { if ($dbType == \Pop\Db\Sql::MYSQL || $dbType == \Pop\Db\Sql::SQLSRV) { $value = '?'; } else { if ($dbType == \Pop\Db\Sql::PGSQL && !$this->sql->getDb()->isPdo()) { $value = '$' . $paramCount; $paramCount++; } } } $val = null === $value ? 'NULL' : $this->sql->quote($value); $set[] = $this->sql->quoteId($column) . ' = ' . $val; } $sql .= implode(', ', $set); // Build any WHERE clauses if (null !== $this->where) { $sql .= ' WHERE ' . $this->where->render($paramCount); } // Build any ORDER BY clause if (null !== $this->orderBy) { $sql .= ' ORDER BY ' . $this->orderBy; } // Build any LIMIT clause if (null !== $this->limit) { $sql .= ' LIMIT ' . (int) $this->limit; } return $sql; }