Skip to content
Permalink
Browse files

Implemented Connection::quote()

  • Loading branch information...
lorenzo committed Jul 9, 2012
1 parent a6423e7 commit 17df49acfee5361643e7ffdacc9293bfc846602a
@@ -13,6 +13,8 @@
**/
class Connection {
use TypeConverter;
/**
* Contains the configuration params for this connection
*
@@ -378,7 +380,9 @@ public function rollbackSavepoint($name) {
* @return mixed quoted value
**/
public function quote($value, $type = null) {
$this->connect();
list($value, $type) = $this->cast($value, $type);
return $this->_driver->quote($value, $type);
}
/**
@@ -61,7 +61,6 @@ abstract class Driver {
public abstract function rollbackTransaction();
/**
* Returns whether this driver supports save points for nested transactions
*
@@ -101,4 +100,10 @@ public function rollbackSavePointSQL($name) {
return 'ROLLBACK TO SAVEPOINT LEVEL' . $name;
}
/**
* Returns a value in a safe representation to be used in a query string
*
* @return string
**/
public abstract function quote($value, $type);
}
@@ -111,4 +111,13 @@ public function rollbackTransaction() {
return $this->_connection->rollback();
}
/**
* Returns a value in a safe representation to be used in a query string
*
* @return string
**/
public function quote($value, $type) {
return $this->_connection->quote($value, $type);
}
}
@@ -517,4 +517,24 @@ public function testSavePoints2() {
$result = $this->connection->execute('SELECT * FROM things');
$this->assertCount(1, $result);
}
/**
* Tests connection can quote values to be safely used in query strings
*
* @return void
**/
public function testQuote() {
$expected = "'2012-01-01'";
$result =$this->connection->quote(new \DateTime('2012-01-01'), 'date');
$this->assertEquals($expected, $result);
$expected = "'1'";
$result =$this->connection->quote(1, 'string');
$this->assertEquals($expected, $result);
$expected = "'hello'";
$result =$this->connection->quote('hello', 'string');
$this->assertEquals($expected, $result);
}
}

0 comments on commit 17df49a

Please sign in to comment.
You can’t perform that action at this time.