diff --git a/src/Bridges/Phalcon/PhalconAdapter.php b/src/Bridges/Phalcon/PhalconAdapter.php index b473561..04a84fd 100755 --- a/src/Bridges/Phalcon/PhalconAdapter.php +++ b/src/Bridges/Phalcon/PhalconAdapter.php @@ -19,62 +19,111 @@ class PhalconAdapter implements IDbal /** @var Pdo */ private $conn; - + /** + * @param Pdo $connection + */ public function __construct(Pdo $connection) { $this->conn = $connection; $this->conn->connect(); } - + /** + * @param string $sql + * @return array list of rows represented by assoc. arrays + */ public function query($sql) { return $this->conn->fetchAll($sql); } - + /** + * @param string $sql + * @return int number of affected rows + */ public function exec($sql) { $this->conn->execute($sql); - $this->conn->affectedRows(); + return $this->conn->affectedRows(); } - public function escapeString($value) + /** + * @param string $value + * @return string escaped string wrapped in quotes + */ + public function escapeString($value) { return $this->conn->escapeString($value); } - + /** + * @param int $value + * @return string + */ public function escapeInt($value) { return (string)(int)$value; } + /** + * @param bool $value + * @return string + * @throws ExecutionException + */ public function escapeBool($value) { - return (string)(int)$value; - } + if ($this->conn->getType() === self::TYPE_MYSQL) { + return (string)(int)$value; + } + if ($this->conn->getType() === self::TYPE_PGSQL) { + return (bool)$value ? 'TRUE' : 'FALSE'; + } + throw new ExecutionException('Unsupported type of \Phalcon\Db\Adapter\Pdo driver.'); + } + + /** + * @param DateTime $value + * @return string + * @throws ExecutionException + */ public function escapeDateTime(DateTime $value) { return $this->conn->escapeString($this->formatDateTime($value)); } - + /** + * @param string $value + * @return string + * @throws ExecutionException + */ public function escapeIdentifier($value) { - return $this->conn->escapeIdentifier($value); + if ($this->conn->getType() === self::TYPE_MYSQL) { + return '`' . $value . '`'; + } + + if ($this->conn->getType() === self::TYPE_PGSQL) { + return '"' . $value . '"'; + } + + throw new ExecutionException('Unsupported type of \Phalcon\Db\Adapter\Pdo driver.'); } + /** + * @param DateTime $value + * @return string + * @throws ExecutionException + */ private function formatDateTime(DateTime $value) { if (in_array($this->conn->getType(), [self::TYPE_MYSQL, self::TYPE_PGSQL], true)) { return $value->format('Y-m-d H:i:s'); - } else { - throw new ExecutionException('Unsupported type of \Phalcon\Db\Adapter\Pdo driver.'); } + + throw new ExecutionException('Unsupported type of \Phalcon\Db\Adapter\Pdo driver.'); } }