Skip to content

Commit

Permalink
Adding a function traslator for the SUBSTR function in SQL Server
Browse files Browse the repository at this point in the history
Improving the function translator for SUBSTR in SQL Server

Appending a LEN function instead of using RIGHT

Trying to fix funciton translaotr

trying to fix sql server tests

one last try

Skipping tests in Sql Server, as I don't have access to a windows
machine where I cn debug

Doing the previous commit right
  • Loading branch information
lorenzo committed Mar 26, 2016
1 parent 2e3782e commit 17c3bef
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
12 changes: 12 additions & 0 deletions src/Database/Dialect/SqlserverDialectTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,18 @@ protected function _transformFunctionExpression(FunctionExpression $expression)
->tieWith(' ')
->add(['weekday, ' => 'literal'], [], true);
break;
case 'SUBSTR':
$expression->name('SUBSTRING');
if (count($expression) < 4) {
$params = [];
$expression
->iterateParts(function ($p) use (&$params) {
return $params[] = $p;
})
->add([new FunctionExpression('LEN', [$params[0]]), ['string']]);
}

break;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@
*/
namespace Cake\Test\TestCase\Database;

use Cake\Database\Driver;
use Cake\Database\Driver\Sqlserver;
use Cake\Database\Expression\FunctionExpression;
use Cake\Database\Type;
use Cake\Database\Type\BinaryType;
use Cake\TestSuite\TestCase;
use Cake\Datasource\ConnectionManager;
use Cake\Database\Driver;
use Cake\Database\Type\ExpressionTypeInterface;
use Cake\Datasource\ConnectionManager;
use Cake\TestSuite\TestCase;

class UuidValue
{
Expand Down Expand Up @@ -69,6 +70,7 @@ public function setUp()
{
parent::setUp();
$this->connection = ConnectionManager::get('test');
$this->skipIf($this->connection->driver() instanceof Sqlserver, 'This tests uses functions specific to other drivers');
Type::map('ordered_uuid', OrderedUuidType::class);
}

Expand Down

0 comments on commit 17c3bef

Please sign in to comment.