@@ -51,7 +51,7 @@ class FakePdoStatement extends \PDOStatement
5151 private $ realStatement = null ;
5252
5353 /**
54- * @var array<string, scalar>
54+ * @var array<string|int , scalar>
5555 */
5656 private $ boundValues = [];
5757
@@ -82,10 +82,10 @@ public function bindValue($key, $value, $type = \PDO::PARAM_STR) : void
8282
8383 /**
8484 * Overriding execute method to add query logging
85- *
85+ * @param ?array $params
8686 * @return bool
8787 */
88- public function execute (? array $ params = null )
88+ public function execute ($ params = null )
8989 {
9090 $ sql = $ this ->getExecutedSql ($ this ->boundValues ?: $ params );
9191
@@ -96,55 +96,18 @@ public function execute(?array $params = null)
9696 }
9797 }
9898
99- //echo "\n" . $sql . "\n";
100-
101- if (stripos ($ sql , 'CREATE TABLE ' ) !== false
102- || stripos ($ sql , 'DROP TABLE ' ) !== false
103- || stripos ($ sql , 'SHOW TABLES ' ) !== false
104- ) {
105- $ parsed_query = new \PhpMyAdmin \SqlParser \Parser ($ sql );
106-
107- if ($ parsed_query ->errors ) {
108- throw $ parsed_query ->errors [0 ];
109- }
110-
111- if (!isset ($ parsed_query ->statements [0 ])) {
112- throw new \UnexpectedValueException ('Bad query ' . $ sql );
113- }
114-
115- $ statement = $ parsed_query ->statements [0 ];
116-
117- switch (get_class ($ statement )) {
118- case \PhpMyAdmin \SqlParser \Statements \CreateStatement::class:
119- Processor \CreateProcessor::process ($ this ->conn , $ statement );
120- break ;
121-
122- case \PhpMyAdmin \SqlParser \Statements \DropStatement::class:
123- $ this ->conn ->getServer ()->dropTable (
124- $ this ->conn ->databaseName ,
125- $ statement ->fields [0 ]->table
126- );
127- break ;
128- case \PhpMyAdmin \SqlParser \Statements \ShowStatement::class:
129- if (count ($ statement ->unknown ) === 7
130- && $ statement ->unknown [4 ]->value === 'LIKE '
131- ) {
132- if ($ this ->conn ->getServer ()->getTable (
133- $ this ->conn ->databaseName ,
134- $ statement ->unknown [4 ]->value
135- )) {
136- $ this ->result = [[$ statement ->unknown [4 ]->value ]];
137- }
99+ if (stripos ($ sql , 'CREATE TABLE ' ) !== false ) {
100+ $ create_queries = (new Parser \CreateTableParser ())->parse ($ sql );
138101
139- $ this ->result = [];
140-
141- return true ;
142- }
102+ foreach ($ create_queries as $ create_query ) {
103+ Processor \CreateProcessor::process ($ this ->conn , $ create_query );
143104 }
144105
145106 return true ;
146107 }
147108
109+ //echo "\n" . $sql . "\n";
110+
148111 $ parsed_query = Parser \SQLParser::parse ($ sql );
149112
150113 $ this ->result = null ;
@@ -210,6 +173,23 @@ function ($row) {
210173 );
211174 break ;
212175
176+ case Query \DropTableQuery::class:
177+ $ this ->conn ->getServer ()->dropTable (
178+ $ this ->conn ->databaseName ,
179+ $ parsed_query ->table
180+ );
181+ break ;
182+ case Query \ShowTablesQuery::class:
183+ if ($ this ->conn ->getServer ()->getTable (
184+ $ this ->conn ->databaseName ,
185+ $ parsed_query ->pattern
186+ )) {
187+ $ this ->result = [[$ parsed_query ->pattern ]];
188+ } else {
189+ $ this ->result = [];
190+ }
191+ break ;
192+
213193 default :
214194 throw new \UnexpectedValueException ('Unsupported operation type ' . $ sql );
215195 }
@@ -231,10 +211,15 @@ public function rowCount() : int
231211 return $ this ->affectedRows ;
232212 }
233213
214+ /**
215+ * @param int $fetch_style
216+ * @param int $cursor_orientation
217+ * @param int $cursor_offset
218+ */
234219 public function fetch (
235- int $ fetch_style = -123 ,
236- int $ cursor_orientation = \PDO ::FETCH_ORI_NEXT ,
237- int $ cursor_offset = 0
220+ $ fetch_style = -123 ,
221+ $ cursor_orientation = \PDO ::FETCH_ORI_NEXT ,
222+ $ cursor_offset = 0
238223 ) {
239224 if ($ fetch_style === -123 ) {
240225 $ fetch_style = $ this ->fetchMode ;
@@ -283,17 +268,19 @@ public function fetch(
283268
284269 /**
285270 * @param int $fetch_style
286- * @param mixed $args
271+ * @param string $fetch_argument
272+ * @param array $ctor_args
287273 */
288- public function fetchAll (int $ fetch_style = -123 , ... $ args ) : array
274+ public function fetchAll ($ fetch_style = -123 , $ fetch_argument = NULL , $ ctor_args = NULL ) : array
289275 {
290276 if ($ fetch_style === -123 ) {
291277 $ fetch_style = $ this ->fetchMode ;
292278 $ fetch_argument = $ this ->fetchArgument ;
293279 $ ctor_args = $ this ->fetchConstructorArgs ;
294280 } else {
295- $ fetch_argument = $ args [0 ] ?? null ;
296- $ ctor_args = $ args [1 ] ?? [];
281+ // may have to uncomment for PHP 8
282+ //$fetch_argument = $args[0] ?? null;
283+ //$ctor_args = $args[1] ?? [];
297284 }
298285
299286 if ($ fetch_style === \PDO ::FETCH_ASSOC ) {
@@ -387,12 +374,15 @@ function ($row) use ($fetch_argument, $ctor_args) {
387374
388375 /**
389376 * @param int $fetch_style
390- * @param mixed $args
377+ * @param mixed $fetch_argument
378+ * @param array $ctorargs
379+ * @param array ...$args
391380 */
392- public function setFetchMode (int $ mode , ... $ args ) : bool
381+ public function setFetchMode ($ mode , $ fetch_argument = null , $ ctorargs = [] ) : bool
393382 {
394- $ fetch_argument = $ args [0 ] ?? null ;
395- $ ctorargs = $ args [1 ] ?? [];
383+ // may have to uncomment for PHP 8
384+ //$fetch_argument = $args[0] ?? null;
385+ //$ctorargs = $args[1] ?? [];
396386
397387 if ($ this ->realStatement ) {
398388 $ this ->realStatement ->setFetchMode ($ mode , $ fetch_argument , $ ctorargs );
@@ -455,10 +445,11 @@ private static function lowercaseKeys(array $row)
455445 * @psalm-taint-sink callable $class
456446 *
457447 * @template T
458- * @param class-string<T> $class
448+ * @param class-string<T>|null $class
449+ * @param array|null $ctorArgs
459450 * @return false|T
460451 */
461- public function fetchObject (? string $ class = \stdClass::class, ? array $ ctorArgs = null )
452+ public function fetchObject ($ class = \stdClass::class, $ ctorArgs = null )
462453 {
463454 throw new \Exception ('not implemented ' );
464455 }
0 commit comments