Skip to content

Commit

Permalink
Adding quoting flag for 4.1.29 changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jfelder committed May 30, 2014
1 parent a708b44 commit 87396f2
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/Jfelder/OracleDB/OracleDBServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class OracledbServiceProvider extends ServiceProvider {
*/
public function boot()
{

}

/**
Expand Down
23 changes: 16 additions & 7 deletions src/Jfelder/OracleDB/Query/Grammars/OracleGrammar.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
<?php namespace Jfelder\OracleDB\Query\Grammars;

use \Illuminate\Database\Query\Builder;
use Config;

class OracleGrammar extends \Illuminate\Database\Query\Grammars\Grammar {

/**
* The keyword identifier wrapper format.
*
* @var string
*/
protected $wrapper = '%s';

/**
* Compile a select query into SQL.
*
Expand Down Expand Up @@ -146,4 +140,19 @@ protected function compileOffset(Builder $query, $offset)
return '';
}

/**
* Wrap a single string in keyword identifiers.
*
* @param string $value
* @return string
*/
protected function wrapValue($value)
{
if (Config::get('oracledb::database.quoting') === true) {
return parent::wrapValue($value);
}

return $value;
}

}
17 changes: 16 additions & 1 deletion src/Jfelder/OracleDB/Schema/Grammars/OracleGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use \Illuminate\Support\Fluent;
use \Illuminate\Database\Connection;
use \Illuminate\Database\Schema\Blueprint;

use Config;
class OracleGrammar extends \Illuminate\Database\Schema\Grammars\Grammar {

/**
Expand Down Expand Up @@ -354,6 +354,21 @@ public function compileRenameColumn(Blueprint $blueprint, Fluent $command, Conne
return $rs;
}

/**
* Wrap a single string in keyword identifiers.
*
* @param string $value
* @return string
*/
protected function wrapValue($value)
{
if (Config::get('oracledb::database.quoting') === true) {
return parent::wrapValue($value);
}

return $value;
}

/**
* Create the column definition for a string type.
*
Expand Down
1 change: 1 addition & 0 deletions src/config/database.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
'password' => '',
'charset' => 'WE8ISO8859P1',
'prefix' => '',
'quoting' => false,
),

),
Expand Down
37 changes: 36 additions & 1 deletion tests/OracleDBQueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ public function testBasicSelect()
}


public function testBasicTableWrappingProtectsQuotationMarks()
{
$builder = $this->getBuilder(true);
$builder->select('*')->from('some"table');
$this->assertEquals('select * from "some""table"', $builder->toSql());
}


public function testAddingSelects()
{
$builder = $this->getBuilder();
Expand Down Expand Up @@ -793,6 +801,30 @@ public function setupCacheTestQuery($cache, $driver)
}


public function testBasicSelectUsingQuotes()
{
$builder = $this->getBuilder(true);
$builder->select('*')->from('users');
$this->assertEquals('select * from "users"', $builder->toSql());

$builder = $this->getBuilder(true);
$builder->select('id')->from('users');
$this->assertEquals('select "id" from "users"', $builder->toSql());
}


public function testBasicSelectNotUsingQuotes()
{
$builder = $this->getBuilder(false);
$builder->select('*')->from('users');
$this->assertEquals('select * from users', $builder->toSql());

$builder = $this->getBuilder(false);
$builder->select('id')->from('users');
$this->assertEquals('select id from users', $builder->toSql());
}


public function testOracleLock()
{
$builder = $this->getBuilder();
Expand All @@ -807,8 +839,11 @@ public function testOracleLock()
}


protected function getBuilder()
protected function getBuilder($quote = false)
{
global $ConfigReturnValue;
$ConfigReturnValue = $quote;

$grammar = new Jfelder\OracleDB\Query\Grammars\OracleGrammar;
$processor = m::mock('Jfelder\OracleDB\Query\Processors\OracleProcessor');
return new Builder(m::mock('Illuminate\Database\ConnectionInterface'), $grammar, $processor);
Expand Down
35 changes: 34 additions & 1 deletion tests/OracleDBSchemaGrammarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -601,13 +601,46 @@ public function testAddingBinary()
$this->assertEquals('alter table users add ( foo blob not null )', $statements[0]);
}

public function testBasicSelectUsingQuotes()
{
$blueprint = new Blueprint('users');
$blueprint->create();
$blueprint->increments('id');
$blueprint->string('email');

$conn = $this->getConnection();

$statements = $blueprint->toSql($conn, $this->getGrammar(true));

$this->assertEquals(1, count($statements));
$this->assertEquals('create table "users" ( "id" number(10,0) not null, "email" varchar2(255) not null, constraint users_id_primary primary key ( "id" ) )', $statements[0]);
}

public function testBasicSelectNotUsingQuotes()
{
$blueprint = new Blueprint('users');
$blueprint->create();
$blueprint->increments('id');
$blueprint->string('email');

$conn = $this->getConnection();

$statements = $blueprint->toSql($conn, $this->getGrammar(false));

$this->assertEquals(1, count($statements));
$this->assertEquals('create table users ( id number(10,0) not null, email varchar2(255) not null, constraint users_id_primary primary key ( id ) )', $statements[0]);
}

protected function getConnection()
{
return m::mock('Illuminate\Database\Connection');
}

public function getGrammar()
public function getGrammar($quote = false)
{
global $ConfigReturnValue;
$ConfigReturnValue = $quote;

return new Jfelder\OracleDB\Schema\Grammars\OracleGrammar;
}

Expand Down
6 changes: 6 additions & 0 deletions tests/mocks/PDOMocks.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
<?php
$ConfigReturnValue = false;

if(!class_exists('ProcessorTestPDOStub')) {
class ProcessorTestPDOStub extends PDO {
public function __construct() {}
public function lastInsertId($sequence = null) {}
}
}
if(!class_exists('Config')) {
class Config {
public static function get($value) { global $ConfigReturnValue; return $ConfigReturnValue; }
}
}

0 comments on commit 87396f2

Please sign in to comment.