@@ -19,62 +19,111 @@ 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
57
return $ this ->conn ->escapeString ($ value );
46
58
}
47
59
48
-
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
+ * @throws ExecutionException
74
+ */
55
75
public function escapeBool ($ value )
56
76
{
57
- return (string )(int )$ value ;
58
- }
77
+ if ($ this ->conn ->getType () === self ::TYPE_MYSQL ) {
78
+ return (string )(int )$ value ;
79
+ }
59
80
81
+ if ($ this ->conn ->getType () === self ::TYPE_PGSQL ) {
82
+ return (bool )$ value ? 'TRUE ' : 'FALSE ' ;
83
+ }
60
84
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
+ */
61
93
public function escapeDateTime (DateTime $ value )
62
94
{
63
95
return $ this ->conn ->escapeString ($ this ->formatDateTime ($ value ));
64
96
}
65
97
66
-
98
+ /**
99
+ * @param string $value
100
+ * @return string
101
+ * @throws ExecutionException
102
+ */
67
103
public function escapeIdentifier ($ value )
68
104
{
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. ' );
70
114
}
71
115
116
+ /**
117
+ * @param DateTime $value
118
+ * @return string
119
+ * @throws ExecutionException
120
+ */
72
121
private function formatDateTime (DateTime $ value )
73
122
{
74
123
if (in_array ($ this ->conn ->getType (), [self ::TYPE_MYSQL , self ::TYPE_PGSQL ], true )) {
75
124
return $ value ->format ('Y-m-d H:i:s ' );
76
- } else {
77
- throw new ExecutionException ('Unsupported type of \Phalcon\Db\Adapter\Pdo driver. ' );
78
125
}
126
+
127
+ throw new ExecutionException ('Unsupported type of \Phalcon\Db\Adapter\Pdo driver. ' );
79
128
}
80
129
}
0 commit comments