Skip to content

Commit 4d60ce0

Browse files
PhalconAdapter fixes
1 parent 08ead01 commit 4d60ce0

File tree

1 file changed

+61
-12
lines changed

1 file changed

+61
-12
lines changed

src/Bridges/Phalcon/PhalconAdapter.php

+61-12
Original file line numberDiff line numberDiff line change
@@ -19,62 +19,111 @@ class PhalconAdapter implements IDbal
1919
/** @var Pdo */
2020
private $conn;
2121

22-
22+
/**
23+
* @param Pdo $connection
24+
*/
2325
public function __construct(Pdo $connection)
2426
{
2527
$this->conn = $connection;
2628
$this->conn->connect();
2729
}
2830

29-
31+
/**
32+
* @param string $sql
33+
* @return array list of rows represented by assoc. arrays
34+
*/
3035
public function query($sql)
3136
{
3237
return $this->conn->fetchAll($sql);
3338
}
3439

35-
40+
/**
41+
* @param string $sql
42+
* @return int number of affected rows
43+
*/
3644
public function exec($sql)
3745
{
3846
$this->conn->execute($sql);
39-
$this->conn->affectedRows();
47+
return $this->conn->affectedRows();
4048
}
4149

4250

43-
public function escapeString($value)
51+
/**
52+
* @param string $value
53+
* @return string escaped string wrapped in quotes
54+
*/
55+
public function escapeString($value)
4456
{
4557
return $this->conn->escapeString($value);
4658
}
4759

48-
60+
/**
61+
* @param int $value
62+
* @return string
63+
*/
4964
public function escapeInt($value)
5065
{
5166
return (string)(int)$value;
5267
}
5368

5469

70+
/**
71+
* @param bool $value
72+
* @return string
73+
* @throws ExecutionException
74+
*/
5575
public function escapeBool($value)
5676
{
57-
return (string)(int)$value;
58-
}
77+
if ($this->conn->getType() === self::TYPE_MYSQL) {
78+
return (string)(int)$value;
79+
}
5980

81+
if ($this->conn->getType() === self::TYPE_PGSQL) {
82+
return (bool)$value ? 'TRUE' : 'FALSE';
83+
}
6084

85+
throw new ExecutionException('Unsupported type of \Phalcon\Db\Adapter\Pdo driver.');
86+
}
87+
88+
/**
89+
* @param DateTime $value
90+
* @return string
91+
* @throws ExecutionException
92+
*/
6193
public function escapeDateTime(DateTime $value)
6294
{
6395
return $this->conn->escapeString($this->formatDateTime($value));
6496
}
6597

66-
98+
/**
99+
* @param string $value
100+
* @return string
101+
* @throws ExecutionException
102+
*/
67103
public function escapeIdentifier($value)
68104
{
69-
return $this->conn->escapeIdentifier($value);
105+
if ($this->conn->getType() === self::TYPE_MYSQL) {
106+
return '`' . $value . '`';
107+
}
108+
109+
if ($this->conn->getType() === self::TYPE_PGSQL) {
110+
return '"' . $value . '"';
111+
}
112+
113+
throw new ExecutionException('Unsupported type of \Phalcon\Db\Adapter\Pdo driver.');
70114
}
71115

116+
/**
117+
* @param DateTime $value
118+
* @return string
119+
* @throws ExecutionException
120+
*/
72121
private function formatDateTime(DateTime $value)
73122
{
74123
if (in_array($this->conn->getType(), [self::TYPE_MYSQL, self::TYPE_PGSQL], true)) {
75124
return $value->format('Y-m-d H:i:s');
76-
} else {
77-
throw new ExecutionException('Unsupported type of \Phalcon\Db\Adapter\Pdo driver.');
78125
}
126+
127+
throw new ExecutionException('Unsupported type of \Phalcon\Db\Adapter\Pdo driver.');
79128
}
80129
}

0 commit comments

Comments
 (0)