Merge remote-tracking branch 'origin' into dev-sql-escape

This commit is contained in:
Dave Mc Nicoll committed 2020-04-09 10:00:48 -04:00
commit def8decb4e
18 files changed
+246 -26

No files matched your search

+1 -1
View File
@@ -10,6 +10,6 @@ abstract class Fragment {
protected function renderSegments(array $segments, string $glue = " ") : string
{
return implode($glue, array_filter($segments));
return implode($glue, array_filter($segments, function($i) { return ! is_null($i) && $i !== false && $i !== ""; }));
}
}
+1 -1
View File
@@ -33,6 +33,6 @@ class Insert extends Fragment {
protected function renderTable() : string
{
return $this->table;
return "`$this->table`";
}
}
+5 -1
View File
@@ -19,8 +19,12 @@ class Limit extends Fragment {
public function render() : string
{
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([
static::SQL_TOKEN, $this->limit
static::SQL_TOKEN, abs($this->limit)
]);
}
}
+5
View File
@@ -13,11 +13,16 @@ class Offset extends Fragment {
public function set($offset) : self
{
$this->offset = $offset;
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}");
}
return $this->renderSegments([
static::SQL_TOKEN, $this->offset,
]);
+3
View File
@@ -12,12 +12,14 @@ class OrderBy extends Fragment {
public function set(array $order) : self
{
$this->orderBy = $order;
return $this;
}
public function add(string $field, ? string $direction = null) : self
{
$this->orderBy[] = [ $field, $direction ];
return $this;
}
@@ -25,6 +27,7 @@ class OrderBy extends Fragment {
{
$list = array_map(function($item) {
list($field, $direction) = $item;
return $field . ( $direction ? " $direction" : "" );
}, $this->orderBy);
+2 -2
View File
@@ -24,12 +24,12 @@ class Update extends Fragment {
'UPDATE',
( $this->priority ?? false ),
( $this->ignore ? 'IGNORE' : false ),
$this->table,
$this->renderTable(),
]);
}
protected function renderTable() : string
{
return $this->table;
return "`$this->table`";
}
}
+1 -1
View File
@@ -33,7 +33,7 @@ class Values extends Fragment {
public function render() : string
{
$this->queryBuilder->addValues($this->flattenRowsArray());
return $this->renderSegments([
'VALUES', $this->renderParameterPlaceholders(),
]);
+1 -1
View File
@@ -53,7 +53,7 @@ class Where extends Fragment {
public function render() : string
{
$stack = [];
foreach ($this->conditionList ?? [] as $key => $item) {
if ( $item instanceof Where ) {
if ( $item->conditionList ?? false ) {