Skip to content

Commit

Permalink
NOT BETWEEN
Browse files Browse the repository at this point in the history
  • Loading branch information
nilportugues committed Feb 8, 2016
1 parent 01de3cf commit ff624c4
Show file tree
Hide file tree
Showing 14 changed files with 132 additions and 59 deletions.
44 changes: 22 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -768,28 +768,28 @@ SELECT user_email.* FROM user_email
The following operators are available for filtering using WHERE conditionals:

```php
public function subWhere($operator = 'OR');
public function equals($column, $value);
public function compare($column, $value, $operator);
public function notEquals($column, $value);
public function greaterThan($column, $value);
public function greaterThanOrEqual($column, $value);
public function lessThan($column, $value);
public function lessThanOrEqual($column, $value);
public function like($column, $value);
public function notLike($column, $value);
public function match(array $columns, array $values);
public function matchBoolean(array $columns, array $values);
public function matchWithQueryExpansion(array $columns, array $values);
public function in($column, array $values);
public function notIn($column, array $values);
public function between($column, $a, $b);
public function isNull($column);
public function isNotNull($column);
public function exists(Select $select);
public function notExists(Select $select);
public function addBitClause($column, $value);
public function asLiteral($literal);
public function subWhere($operator = 'OR');
public function equals($column, $value);
public function notEquals($column, $value);
public function greaterThan($column, $value);
public function greaterThanOrEqual($column, $value);
public function lessThan($column, $value);
public function lessThanOrEqual($column, $value);
public function like($column, $value);
public function notLike($column, $value);
public function match(array $columns, array $values);
public function matchBoolean(array $columns, array $values);
public function matchWithQueryExpansion(array $columns, array $values);
public function in($column, array $values);
public function notIn($column, array $values);
public function between($column, $a, $b);
public function notBetween($column, $a, $b);
public function isNull($column);
public function isNotNull($column);
public function exists(Select $select);
public function notExists(Select $select);
public function addBitClause($column, $value);
public function asLiteral($literal);
```

<a name="block4.2"></a>
Expand Down
14 changes: 7 additions & 7 deletions src/Builder/GenericBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,37 +28,37 @@ class GenericBuilder implements BuilderInterface
*
* @var \NilPortugues\Sql\QueryBuilder\Builder\Syntax\PlaceholderWriter
*/
private $placeholderWriter;
protected $placeholderWriter;

/**
* The Where writer.
*
* @var \NilPortugues\Sql\QueryBuilder\Builder\Syntax\WhereWriter
*/
private $whereWriter;
protected $whereWriter;

/**
* The SQL formatter.
*
* @var \NilPortugues\Sql\QueryFormatter\Formatter
*/
private $sqlFormatter;
protected $sqlFormatter;

/**
* Class namespace for the query pretty output formatter.
* Required to create the instance only if required.
*
* @var string
*/
private $sqlFormatterClass = 'NilPortugues\Sql\QueryFormatter\Formatter';
protected $sqlFormatterClass = 'NilPortugues\Sql\QueryFormatter\Formatter';

/**
* Array holding the writers for each query part. Methods are called upon request and stored in
* the $queryWriterInstances array.
*
* @var array
*/
private $queryWriterArray = [
protected $queryWriterArray = [
'SELECT' => '\NilPortugues\Sql\QueryBuilder\Builder\Syntax\WriterFactory::createSelectWriter',
'INSERT' => '\NilPortugues\Sql\QueryBuilder\Builder\Syntax\WriterFactory::createInsertWriter',
'UPDATE' => '\NilPortugues\Sql\QueryBuilder\Builder\Syntax\WriterFactory::createUpdateWriter',
Expand All @@ -74,7 +74,7 @@ class GenericBuilder implements BuilderInterface
*
* @var array
*/
private $queryWriterInstances = [
protected $queryWriterInstances = [
'SELECT' => null,
'INSERT' => null,
'UPDATE' => null,
Expand Down Expand Up @@ -107,7 +107,7 @@ public function select($table = null, array $columns = null)
/**
* @param \NilPortugues\Sql\QueryBuilder\Manipulation\AbstractBaseQuery
*
*@return \NilPortugues\Sql\QueryBuilder\Manipulation\AbstractBaseQuery
* @return \NilPortugues\Sql\QueryBuilder\Manipulation\AbstractBaseQuery
*/
protected function injectBuilder(AbstractBaseQuery $query)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Builder/Syntax/ColumnWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ class ColumnWriter
/**
* @var \NilPortugues\Sql\QueryBuilder\Builder\GenericBuilder
*/
private $writer;
protected $writer;

/**
* @var PlaceholderWriter
*/
private $placeholderWriter;
protected $placeholderWriter;

/**
* @param GenericBuilder $writer
Expand Down
4 changes: 2 additions & 2 deletions src/Builder/Syntax/DeleteWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ class DeleteWriter
/**
* @var GenericBuilder
*/
private $writer;
protected $writer;

/**
* @var PlaceholderWriter
*/
private $placeholderWriter;
protected $placeholderWriter;

/**
* @param GenericBuilder $writer
Expand Down
4 changes: 2 additions & 2 deletions src/Builder/Syntax/InsertWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ class InsertWriter
/**
* @var GenericBuilder
*/
private $writer;
protected $writer;

/**
* @var ColumnWriter
*/
private $columnWriter;
protected $columnWriter;

/**
* @param GenericBuilder $writer
Expand Down
2 changes: 1 addition & 1 deletion src/Builder/Syntax/MinusWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class MinusWriter
/**
* @var GenericBuilder
*/
private $writer;
protected $writer;

/**
* @param GenericBuilder $writer
Expand Down
2 changes: 1 addition & 1 deletion src/Builder/Syntax/UpdateWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function write(Update $update)
*
* @return string
*/
private function writeUpdateValues(Update $update)
protected function writeUpdateValues(Update $update)
{
$assigns = [];
foreach ($update->getValues() as $column => $value) {
Expand Down
27 changes: 27 additions & 0 deletions src/Builder/Syntax/WhereWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public function writeWhereClauses(Where $where)
$this->writeWhereIns($where, $whereArray);
$this->writeWhereNotIns($where, $whereArray);
$this->writeWhereBetweens($where, $whereArray);
$this->writeWhereNotBetweens($where, $whereArray);
$this->writeWhereComparisons($where, $whereArray);
$this->writeWhereIsNulls($where, $whereArray);
$this->writeWhereIsNotNulls($where, $whereArray);
Expand Down Expand Up @@ -183,6 +184,32 @@ function (&$between) {
$whereArray = \array_merge($whereArray, $between);
}

/**
* @param Where $where
* @param array $whereArray
*
* @return array
*/
protected function writeWhereNotBetweens(Where $where, array &$whereArray)
{
$between = $where->getNotBetweens();
\array_walk(
$between,
function (&$between) {

$between = '('
.$this->columnWriter->writeColumn($between['subject'])
.' NOT BETWEEN '
.$this->writer->writePlaceholderValue($between['a'])
.' AND '
.$this->writer->writePlaceholderValue($between['b'])
.')';
}
);

$whereArray = \array_merge($whereArray, $between);
}

/**
* @param Where $where
* @param array $whereArray
Expand Down
2 changes: 1 addition & 1 deletion src/Manipulation/AbstractBaseQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ abstract class AbstractBaseQuery implements QueryInterface, QueryPartInterface
/**
* @var \NilPortugues\Sql\QueryBuilder\Builder\BuilderInterface
*/
private $builder;
protected $builder;

/**
* @var string
Expand Down
2 changes: 1 addition & 1 deletion src/Manipulation/Intersect.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Intersect implements QueryInterface, QueryPartInterface
/**
* @var array
*/
private $intersect = [];
protected $intersect = [];

/**
* @return string
Expand Down
4 changes: 2 additions & 2 deletions src/Manipulation/Minus.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ class Minus implements QueryInterface, QueryPartInterface
/**
* @var Select
*/
private $first;
protected $first;

/**
* @var Select
*/
private $second;
protected $second;

/**
* @return string
Expand Down
3 changes: 1 addition & 2 deletions src/Syntax/SyntaxFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,10 @@ public static function createColumn(array &$argument, $table = null)
*/
public static function createTable($table)
{
$tableName = $table;
if (\is_array($table)) {
$tableName = \current($table);
$tableAlias = \key($table);
} else {
$tableName = $table;
}

$newTable = new Table($tableName);
Expand Down
Loading

0 comments on commit ff624c4

Please sign in to comment.