- Fixed the QueryBuilder's escaping problem - adapters are now responsible for escaping identifiers.

- Added a MsSQL offset query fragment. There is still a problem with the way the Repository must act within another adapter.
This commit is contained in:
Dave Mc Nicoll committed 2020-04-14 09:47:09 -04:00
1 parent 3ff97f3bf0
commit 026a0f4f83
8 files changed
+75 -26

No files matched your search

+3 -1
View File
@@ -25,6 +25,8 @@ class Join extends Fragment {
public /*string|QueryBuilder*/ $table;
public ? string $alias;
public string $field;
public /*string|QueryBuilder*/ $value;
@@ -45,6 +47,6 @@ class Join extends Fragment {
public function render() : string
{
return $this->renderSegments([ $this->side, static::SQL_TOKEN, $this->table, $this->attachment, $this->field, "=", $this->value ]);
return $this->renderSegments([ $this->side, static::SQL_TOKEN, $this->table, $this->alias ?? "", $this->attachment, $this->field, "=", $this->value ]);
}
}
+37
View File
@@ -0,0 +1,37 @@
<?php
namespace Ulmus\Query\MsSQL;
class Offset extends \Ulmus\Query\Fragment {
const SQL_TOKEN = "OFFSET %s ROWS FETCH NEXT %s ROWS ONLY";
public int $order = 95;
public int $offset;
public int $limit;
public function set(int $offset, int $limit) : self
{
$this->offset = $offset;
$this->limit = $limit;
return $this;
}
public function render() : string
{
if ( $this->offset < 0 ) {
throw new \Exception("An error occured trying to render the OFFSET fragment ; given value has to be > 0. Received {$this->offset}");
}
if ( $this->limit < 0 ) {
throw new \Exception("An error occured trying to render the LIMIT fragment ; given value has to be > 0. Received {$this->limit}");
}
return $this->renderSegments([
sprintf(static::SQL_TOKEN, $this->offset, $this->limit)
]);
}
}
+5 -3
View File
@@ -8,9 +8,11 @@ class Offset extends Fragment {
public int $order = 95;
protected int $offset = 0;
public int $offset = 0;
public string $rows = "";
public function set($offset) : self
public function set(int $offset) : self
{
$this->offset = $offset;
@@ -24,7 +26,7 @@ class Offset extends Fragment {
}
return $this->renderSegments([
static::SQL_TOKEN, $this->offset,
static::SQL_TOKEN, $this->offset, $this->rows
]);
}
}