Minor update

This commit is contained in:
2022-03-08 11:50:18 +01:00
parent b97b5d9d67
commit 5bb0d1419f
5 changed files with 34 additions and 15 deletions

View File

@@ -18,6 +18,7 @@ class Select extends Query {
private bool $sortAscending;
private int $limit;
private int $offset;
private bool $forUpdate;
public function __construct($sql, ...$selectValues) {
parent::__construct($sql);
@@ -31,6 +32,7 @@ class Select extends Query {
$this->limit = 0;
$this->offset = 0;
$this->sortAscending = true;
$this->forUpdate = false;
}
public function from(...$tables): Select {
@@ -88,6 +90,11 @@ class Select extends Query {
return $this;
}
public function lockForUpdate(): Select {
$this->forUpdate = true;
return $this;
}
public function execute() {
return $this->sql->executeQuery($this, true);
}
@@ -174,6 +181,7 @@ class Select extends Query {
$limit = ($this->getLimit() > 0 ? (" LIMIT " . $this->getLimit()) : "");
$offset = ($this->getOffset() > 0 ? (" OFFSET " . $this->getOffset()) : "");
return "SELECT $selectValues FROM $tables$joinStr$where$groupBy$havingClause$orderBy$limit$offset";
$forUpdate = ($this->forUpdate ? " FOR UPDATE" : "");
return "SELECT $selectValues FROM $tables$joinStr$where$groupBy$havingClause$orderBy$limit$offset$forUpdate";
}
}