@@ -19,62 +19,102 @@ class PhalconAdapter implements IDbal
19
19
/** @var Pdo */
20
20
private $ conn ;
21
21
22
-
22
+ /**
23
+ * @param Pdo $connection
24
+ */
23
25
public function __construct (Pdo $ connection )
24
26
{
25
27
$ this ->conn = $ connection ;
26
28
$ this ->conn ->connect ();
27
29
}
28
30
29
-
31
+ /**
32
+ * @param string $sql
33
+ * @return array list of rows represented by assoc. arrays
34
+ */
30
35
public function query ($ sql )
31
36
{
32
37
return $ this ->conn ->fetchAll ($ sql );
33
38
}
34
39
35
-
40
+ /**
41
+ * @param string $sql
42
+ * @return int number of affected rows
43
+ */
36
44
public function exec ($ sql )
37
45
{
38
46
$ this ->conn ->execute ($ sql );
39
- $ this ->conn ->affectedRows ();
47
+ return $ this ->conn ->affectedRows ();
40
48
}
41
49
42
50
43
- public function escapeString ($ value )
51
+ /**
52
+ * @param string $value
53
+ * @return string escaped string wrapped in quotes
54
+ */
55
+ public function escapeString ($ value )
44
56
{
45
- return $ this ->conn ->getPdo ()->quote ($ value , \PDO ::PARAM_STR );
46
- }
47
-
57
+ return $ this ->conn ->escapeString ($ value );
58
+ }
48
59
60
+ /**
61
+ * @param int $value
62
+ * @return string
63
+ */
49
64
public function escapeInt ($ value )
50
65
{
51
66
return (string )(int )$ value ;
52
67
}
53
68
54
69
70
+ /**
71
+ * @param bool $value
72
+ * @return string
73
+ */
55
74
public function escapeBool ($ value )
56
75
{
57
76
return (string )(int )$ value ;
58
77
}
59
78
60
-
79
+ /**
80
+ * @param DateTime $value
81
+ * @return string
82
+ * @throws ExecutionException
83
+ */
61
84
public function escapeDateTime (DateTime $ value )
62
85
{
63
86
return $ this ->conn ->escapeString ($ this ->formatDateTime ($ value ));
64
87
}
65
88
66
-
89
+ /**
90
+ * @param string $value
91
+ * @return string
92
+ * @throws ExecutionException
93
+ */
67
94
public function escapeIdentifier ($ value )
68
95
{
69
- return $ this ->conn ->escapeIdentifier ($ value );
96
+ if ($ this ->conn ->getType () === self ::TYPE_MYSQL ) {
97
+ return '` ' . $ value . '` ' ;
98
+ }
99
+
100
+ if ($ this ->conn ->getType () === self ::TYPE_PGSQL ) {
101
+ return '" ' . $ value . '" ' ;
102
+ }
103
+
104
+ throw new ExecutionException ('Unsupported type of \Phalcon\Db\Adapter\Pdo driver. ' );
70
105
}
71
106
107
+ /**
108
+ * @param DateTime $value
109
+ * @return string
110
+ * @throws ExecutionException
111
+ */
72
112
private function formatDateTime (DateTime $ value )
73
113
{
74
114
if (in_array ($ this ->conn ->getType (), [self ::TYPE_MYSQL , self ::TYPE_PGSQL ], true )) {
75
115
return $ value ->format ('Y-m-d H:i:s ' );
76
- } else {
77
- throw new ExecutionException ('Unsupported type of \Phalcon\Db\Adapter\Pdo driver. ' );
78
116
}
117
+
118
+ throw new ExecutionException ('Unsupported type of \Phalcon\Db\Adapter\Pdo driver. ' );
79
119
}
80
120
}
0 commit comments