Skip to content

Commit ff624c4

Browse files
committed
NOT BETWEEN
1 parent 01de3cf commit ff624c4

File tree

14 files changed

+132
-59
lines changed

14 files changed

+132
-59
lines changed

README.md

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -768,28 +768,28 @@ SELECT user_email.* FROM user_email
768768
The following operators are available for filtering using WHERE conditionals:
769769

770770
```php
771-
public function subWhere($operator = 'OR');
772-
public function equals($column, $value);
773-
public function compare($column, $value, $operator);
774-
public function notEquals($column, $value);
775-
public function greaterThan($column, $value);
776-
public function greaterThanOrEqual($column, $value);
777-
public function lessThan($column, $value);
778-
public function lessThanOrEqual($column, $value);
779-
public function like($column, $value);
780-
public function notLike($column, $value);
781-
public function match(array $columns, array $values);
782-
public function matchBoolean(array $columns, array $values);
783-
public function matchWithQueryExpansion(array $columns, array $values);
784-
public function in($column, array $values);
785-
public function notIn($column, array $values);
786-
public function between($column, $a, $b);
787-
public function isNull($column);
788-
public function isNotNull($column);
789-
public function exists(Select $select);
790-
public function notExists(Select $select);
791-
public function addBitClause($column, $value);
792-
public function asLiteral($literal);
771+
public function subWhere($operator = 'OR');
772+
public function equals($column, $value);
773+
public function notEquals($column, $value);
774+
public function greaterThan($column, $value);
775+
public function greaterThanOrEqual($column, $value);
776+
public function lessThan($column, $value);
777+
public function lessThanOrEqual($column, $value);
778+
public function like($column, $value);
779+
public function notLike($column, $value);
780+
public function match(array $columns, array $values);
781+
public function matchBoolean(array $columns, array $values);
782+
public function matchWithQueryExpansion(array $columns, array $values);
783+
public function in($column, array $values);
784+
public function notIn($column, array $values);
785+
public function between($column, $a, $b);
786+
public function notBetween($column, $a, $b);
787+
public function isNull($column);
788+
public function isNotNull($column);
789+
public function exists(Select $select);
790+
public function notExists(Select $select);
791+
public function addBitClause($column, $value);
792+
public function asLiteral($literal);
793793
```
794794

795795
<a name="block4.2"></a>

src/Builder/GenericBuilder.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,37 +28,37 @@ class GenericBuilder implements BuilderInterface
2828
*
2929
* @var \NilPortugues\Sql\QueryBuilder\Builder\Syntax\PlaceholderWriter
3030
*/
31-
private $placeholderWriter;
31+
protected $placeholderWriter;
3232

3333
/**
3434
* The Where writer.
3535
*
3636
* @var \NilPortugues\Sql\QueryBuilder\Builder\Syntax\WhereWriter
3737
*/
38-
private $whereWriter;
38+
protected $whereWriter;
3939

4040
/**
4141
* The SQL formatter.
4242
*
4343
* @var \NilPortugues\Sql\QueryFormatter\Formatter
4444
*/
45-
private $sqlFormatter;
45+
protected $sqlFormatter;
4646

4747
/**
4848
* Class namespace for the query pretty output formatter.
4949
* Required to create the instance only if required.
5050
*
5151
* @var string
5252
*/
53-
private $sqlFormatterClass = 'NilPortugues\Sql\QueryFormatter\Formatter';
53+
protected $sqlFormatterClass = 'NilPortugues\Sql\QueryFormatter\Formatter';
5454

5555
/**
5656
* Array holding the writers for each query part. Methods are called upon request and stored in
5757
* the $queryWriterInstances array.
5858
*
5959
* @var array
6060
*/
61-
private $queryWriterArray = [
61+
protected $queryWriterArray = [
6262
'SELECT' => '\NilPortugues\Sql\QueryBuilder\Builder\Syntax\WriterFactory::createSelectWriter',
6363
'INSERT' => '\NilPortugues\Sql\QueryBuilder\Builder\Syntax\WriterFactory::createInsertWriter',
6464
'UPDATE' => '\NilPortugues\Sql\QueryBuilder\Builder\Syntax\WriterFactory::createUpdateWriter',
@@ -74,7 +74,7 @@ class GenericBuilder implements BuilderInterface
7474
*
7575
* @var array
7676
*/
77-
private $queryWriterInstances = [
77+
protected $queryWriterInstances = [
7878
'SELECT' => null,
7979
'INSERT' => null,
8080
'UPDATE' => null,
@@ -107,7 +107,7 @@ public function select($table = null, array $columns = null)
107107
/**
108108
* @param \NilPortugues\Sql\QueryBuilder\Manipulation\AbstractBaseQuery
109109
*
110-
*@return \NilPortugues\Sql\QueryBuilder\Manipulation\AbstractBaseQuery
110+
* @return \NilPortugues\Sql\QueryBuilder\Manipulation\AbstractBaseQuery
111111
*/
112112
protected function injectBuilder(AbstractBaseQuery $query)
113113
{

src/Builder/Syntax/ColumnWriter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ class ColumnWriter
2323
/**
2424
* @var \NilPortugues\Sql\QueryBuilder\Builder\GenericBuilder
2525
*/
26-
private $writer;
26+
protected $writer;
2727

2828
/**
2929
* @var PlaceholderWriter
3030
*/
31-
private $placeholderWriter;
31+
protected $placeholderWriter;
3232

3333
/**
3434
* @param GenericBuilder $writer

src/Builder/Syntax/DeleteWriter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ class DeleteWriter
2121
/**
2222
* @var GenericBuilder
2323
*/
24-
private $writer;
24+
protected $writer;
2525

2626
/**
2727
* @var PlaceholderWriter
2828
*/
29-
private $placeholderWriter;
29+
protected $placeholderWriter;
3030

3131
/**
3232
* @param GenericBuilder $writer

src/Builder/Syntax/InsertWriter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ class InsertWriter
2222
/**
2323
* @var GenericBuilder
2424
*/
25-
private $writer;
25+
protected $writer;
2626

2727
/**
2828
* @var ColumnWriter
2929
*/
30-
private $columnWriter;
30+
protected $columnWriter;
3131

3232
/**
3333
* @param GenericBuilder $writer

src/Builder/Syntax/MinusWriter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class MinusWriter
2121
/**
2222
* @var GenericBuilder
2323
*/
24-
private $writer;
24+
protected $writer;
2525

2626
/**
2727
* @param GenericBuilder $writer

src/Builder/Syntax/UpdateWriter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function write(Update $update)
5050
*
5151
* @return string
5252
*/
53-
private function writeUpdateValues(Update $update)
53+
protected function writeUpdateValues(Update $update)
5454
{
5555
$assigns = [];
5656
foreach ($update->getValues() as $column => $value) {

src/Builder/Syntax/WhereWriter.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public function writeWhereClauses(Where $where)
5151
$this->writeWhereIns($where, $whereArray);
5252
$this->writeWhereNotIns($where, $whereArray);
5353
$this->writeWhereBetweens($where, $whereArray);
54+
$this->writeWhereNotBetweens($where, $whereArray);
5455
$this->writeWhereComparisons($where, $whereArray);
5556
$this->writeWhereIsNulls($where, $whereArray);
5657
$this->writeWhereIsNotNulls($where, $whereArray);
@@ -183,6 +184,32 @@ function (&$between) {
183184
$whereArray = \array_merge($whereArray, $between);
184185
}
185186

187+
/**
188+
* @param Where $where
189+
* @param array $whereArray
190+
*
191+
* @return array
192+
*/
193+
protected function writeWhereNotBetweens(Where $where, array &$whereArray)
194+
{
195+
$between = $where->getNotBetweens();
196+
\array_walk(
197+
$between,
198+
function (&$between) {
199+
200+
$between = '('
201+
.$this->columnWriter->writeColumn($between['subject'])
202+
.' NOT BETWEEN '
203+
.$this->writer->writePlaceholderValue($between['a'])
204+
.' AND '
205+
.$this->writer->writePlaceholderValue($between['b'])
206+
.')';
207+
}
208+
);
209+
210+
$whereArray = \array_merge($whereArray, $between);
211+
}
212+
186213
/**
187214
* @param Where $where
188215
* @param array $whereArray

src/Manipulation/AbstractBaseQuery.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ abstract class AbstractBaseQuery implements QueryInterface, QueryPartInterface
3131
/**
3232
* @var \NilPortugues\Sql\QueryBuilder\Builder\BuilderInterface
3333
*/
34-
private $builder;
34+
protected $builder;
3535

3636
/**
3737
* @var string

src/Manipulation/Intersect.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class Intersect implements QueryInterface, QueryPartInterface
2222
/**
2323
* @var array
2424
*/
25-
private $intersect = [];
25+
protected $intersect = [];
2626

2727
/**
2828
* @return string

src/Manipulation/Minus.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ class Minus implements QueryInterface, QueryPartInterface
2222
/**
2323
* @var Select
2424
*/
25-
private $first;
25+
protected $first;
2626

2727
/**
2828
* @var Select
2929
*/
30-
private $second;
30+
protected $second;
3131

3232
/**
3333
* @return string

src/Syntax/SyntaxFactory.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,10 @@ public static function createColumn(array &$argument, $table = null)
7474
*/
7575
public static function createTable($table)
7676
{
77+
$tableName = $table;
7778
if (\is_array($table)) {
7879
$tableName = \current($table);
7980
$tableAlias = \key($table);
80-
} else {
81-
$tableName = $table;
8281
}
8382

8483
$newTable = new Table($tableName);

0 commit comments

Comments
 (0)