Skip to content

Commit

Permalink
Added Connection::query wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
Gusakov Nikita committed May 5, 2014
1 parent 1adac3f commit f0b5559
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,19 @@ public function prepare($sql, $driverOptions = [])
return parent::prepare($sql, $driverOptions);
}

/**
* @param string $sql
* @param array $parameters
*
* @return Query
*/
public function query($sql, array $parameters = [])
{
return $this->prepare($sql)->execute($parameters);
}

/**
* @return static
* @throws Exception
*/
public function beginTransaction()
{
Expand Down
13 changes: 13 additions & 0 deletions tests/ConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,19 @@ public function testParserSkipRepeatedTypes()
$this->assertAttributeSame(['sex' => \PDO::PARAM_BOOL], 'types', $stmt);
}

public function testQuery()
{
$stmt = $this->connection->query('SELECT * FROM users');

$this->assertInstanceOf('Flame\\Query', $stmt);
$this->assertSame(3, $stmt->columnCount());

$stmt = $this->connection->query('SELECT * FROM users WHERE id = i:id', ['id' => 1]);

$this->assertAttributeSame(['id'], 'placeholders', $stmt);
$this->assertAttributeSame(['id' => \PDO::PARAM_INT], 'types', $stmt);
}

public function testSelect()
{
$select = $this->connection->select('id', 'name', 'count');
Expand Down

0 comments on commit f0b5559

Please sign in to comment.