Skip to content

Commit

Permalink
Removing parentheses from generated Query when converting to string.
Browse files Browse the repository at this point in the history
  • Loading branch information
renan committed Mar 30, 2014
1 parent 03103d4 commit 6342328
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
3 changes: 1 addition & 2 deletions src/Database/Driver/PDODriverTrait.php
Expand Up @@ -79,8 +79,7 @@ public function disconnect() {
*/
public function prepare($query) {
$this->connect();
$sql = $query instanceof Query ? $query->sql() : $query;
$statement = $this->_connection->prepare($sql);
$statement = $this->_connection->prepare((string)$query);
return new PDOStatement($statement, $this);
}

Expand Down
3 changes: 1 addition & 2 deletions src/Database/Driver/Sqlite.php
Expand Up @@ -88,8 +88,7 @@ public function enabled() {
*/
public function prepare($query) {
$this->connect();
$sql = $query instanceof Query ? $query->sql() : $query;
$statement = $this->_connection->prepare($sql);
$statement = $this->_connection->prepare((string)$query);
return new SqliteStatement(new PDOStatement($statement, $this), $this);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Database/Query.php
Expand Up @@ -1822,7 +1822,7 @@ protected function _dirty() {
* @return string
*/
public function __toString() {
return sprintf('(%s)', $this->sql());
return $this->sql();
}

/**
Expand Down
14 changes: 14 additions & 0 deletions tests/TestCase/Database/QueryTest.php
Expand Up @@ -2396,6 +2396,20 @@ public function testQuotingInsert() {
$this->assertQuotedQuery('INSERT INTO <foo> \(\(bar\)\)', $sql);
}

/**
* Tests converting a query to a string
*
* @return void
*/
public function testToString() {
$query = new Query($this->connection);
$query
->select(['title'])
->from('articles');
$result = (string)$query;
$this->assertQuotedQuery('SELECT <title> FROM <articles>', $result, true);
}

/**
* Tests __debugInfo
*
Expand Down

0 comments on commit 6342328

Please sign in to comment.