Skip to content
This repository has been archived by the owner on Mar 2, 2021. It is now read-only.

Commit

Permalink
Merge pull request #25 from chrisandchris/release/v2.3
Browse files Browse the repository at this point in the history
fixed issue when using auto camelCase and typecast and explicit schema
  • Loading branch information
chrisandchris authored Aug 24, 2017
2 parents ed87a8d + 143e379 commit 8a60906
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.vagrant/
!app/cache/.gitkeep
!app/logs/.gitkeep
/build/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
class MySqlBag extends AbstractBag implements SnippetBagInterface
{

const DELIMITER = '`';
/** @var array */
private $snippets = [];
const DELIMITER = '`';

public function __construct()
{
Expand Down Expand Up @@ -113,15 +113,20 @@ private function init()

// key = db column name, value = alias
foreach ($params['fields'] as $key => $value) {
// explicit value
// explicit value or auto camelCase
if (!is_numeric($key) || substr($value, 0, 1) === '!') {
// auto camelCase
if (substr($value, 0, 1) === '!') {
$key = substr($value, 1);
$value = $this->toCamelCase($key);
}
} else {
// implicit value
$key = $value;
}

// remove explicit schema qualifier and typecast from alias
if (strstr($value, ':') !== false) {
// remove casting and schema/table qualifier from alias
$value = strrev(explode(':',
strrev(explode('::', $value)[0]))[0]);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace ChrisAndChris\Common\RowMapperBundle\Tests\Services\Query;

use ChrisAndChris\Common\RowMapperBundle\Exceptions\MalformedQueryException;
Expand Down Expand Up @@ -132,6 +133,17 @@ public function testFieldlist_withCast()
$this->equals('`table`.`field1` as `field1`', $builder);
}

public function testFiedllist_withCastAndCamelCase()
{
$builder = $this->getBuilder();
$builder->fieldlist(
[
'!table:camel_case::int',
]
);
$this->equals('`table`.`camel_case` as `camelCase`', $builder);
}

public function testFieldlist()
{
$builder = $this->getBuilder();
Expand Down Expand Up @@ -187,7 +199,8 @@ public function testFieldlist()
'!first_name',
]
);
$this->equals('`user_id` as `userId`, `first_name` as `firstName`', $builder);
$this->equals('`user_id` as `userId`, `first_name` as `firstName`',
$builder);

$builder = $this->getBuilder();
$builder->fieldlist(
Expand Down Expand Up @@ -517,7 +530,8 @@ function () {

$this->assertEquals(5, count($builder->getStatement()));
$query = $builder->getSqlQuery();
$this->assertEquals('`field` `field` `field` `field` `field`', $query->getQuery());
$this->assertEquals('`field` `field` `field` `field` `field`',
$query->getQuery());
}

public function testEach()
Expand Down

0 comments on commit 8a60906

Please sign in to comment.