Skip to content

Commit 58f852a

Browse files
committed
Fixing the issue of not handling the procedures options correctly
Signed-off-by: Fawzi E. Abdulfattah <[email protected]>
1 parent c2ba926 commit 58f852a

5 files changed

Lines changed: 59 additions & 31 deletions

File tree

src/Statements/CreateStatement.php

Lines changed: 43 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -219,21 +219,50 @@ class CreateStatement extends Statement
219219
* @var array
220220
*/
221221
public static $FUNC_OPTIONS = array(
222-
'COMMENT' => array(
223-
1,
222+
'NOT' => array(
223+
2,
224+
'var',
225+
),
226+
'FUNCTION' => array(
227+
3,
224228
'var=',
225229
),
226-
'LANGUAGE SQL' => 2,
227-
'DETERMINISTIC' => 3,
228-
'NOT DETERMINISTIC' => 3,
229-
'CONTAINS SQL' => 4,
230-
'NO SQL' => 4,
231-
'READS SQL DATA' => 4,
232-
'MODIFIES SQL DATA' => 4,
233-
'SQL SECURITY DEFINER' => array(
234-
5,
230+
'PROCEDURE' => array(
231+
3,
232+
'var=',
233+
),
234+
'CONTAINS' => array(
235+
4,
236+
'expr',
237+
),
238+
'NO' => array(
239+
4,
235240
'var',
236-
)
241+
),
242+
'READS' => array(
243+
4,
244+
'var',
245+
),
246+
'MODIFIES' => array(
247+
4,
248+
'expr',
249+
),
250+
'SQL SECURITY' => array(
251+
6,
252+
'var',
253+
),
254+
'LANGUAGE' => array(
255+
7,
256+
'var',
257+
),
258+
'COMMENT' => array(
259+
8,
260+
'var',
261+
),
262+
263+
'CREATE' => 1,
264+
'DETERMINISTIC' => 2,
265+
'DATA' => 5,
237266
);
238267

239268
/**
@@ -451,7 +480,8 @@ public function build()
451480
. OptionsArray::build($this->options) . ' '
452481
. Expression::build($this->name) . ' '
453482
. ParameterDefinition::build($this->parameters) . ' '
454-
. $tmp . ' ' . TokensList::build($this->body);
483+
. $tmp . ' ' . OptionsArray::build($this->entityOptions) . ' '
484+
. TokensList::build($this->body);
455485
}
456486

457487
return 'CREATE '

tests/Builder/CreateStatementTest.php

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -412,9 +412,8 @@ public function testBuilderCreateProcedure()
412412
$stmt->build()
413413
);
414414

415-
$this->assertTrue($stmt->entityOptions->isEmpty());
415+
$this->assertFalse($stmt->entityOptions->isEmpty());
416416
$this->assertFalse($stmt->options->isEmpty());
417-
418417
$this->assertSame(
419418
'DEFINER=`root`@`%` PROCEDURE',
420419
$stmt->options->__toString()
@@ -431,12 +430,12 @@ public function testBuilderCreateProcedure()
431430
);
432431

433432
$this->assertSame(
434-
'',
433+
'NOT DETERMINISTIC NO SQL SQL SECURITY INVOKER NO SQL SQL SECURITY INVOKER',
435434
$stmt->entityOptions->__toString()
436435
);
437436

438437
$this->assertSame(
439-
'NOT DETERMINISTIC NO SQL SQL SECURITY INVOKER NO SQL SQL SECURITY INVOKER SELECT _var',
438+
'SELECT _var',
440439
TokensList::build($stmt->body)
441440
);
442441
}
@@ -446,9 +445,9 @@ public function testBuilderCreateFunction()
446445
$parser = new Parser(
447446
'CREATE DEFINER=`root`@`localhost`'
448447
. ' FUNCTION `inventory_in_stock`(`p_inventory_id` INT) RETURNS tinyint(1)'
449-
. ' READS SQL DATA' . "\n"
450-
. ' COMMENT \'My best function written by a friend\'\'s friend' . "\n"
451-
. 'BEGIN' . "\n"
448+
. ' READS SQL DATA'
449+
. ' COMMENT \'My best function written by a friend\'\'s friend\''
450+
. ' BEGIN' . "\n"
452451
. ' DECLARE v_rentals INT;' . "\n"
453452
. ' DECLARE v_out INT;' . "\n"
454453
. "\n"
@@ -482,9 +481,9 @@ public function testBuilderCreateFunction()
482481
$this->assertSame(
483482
'CREATE DEFINER=`root`@`localhost`'
484483
. ' FUNCTION `inventory_in_stock` (`p_inventory_id` INT) RETURNS TINYINT(1)'
485-
. ' READS SQL DATA' . "\n"
486-
. ' COMMENT \'My best function written by a friend\'\'s friend' . "\n"
487-
. 'BEGIN' . "\n"
484+
. ' READS SQL DATA'
485+
. ' COMMENT \'My best function written by a friend\'\'s friend\''
486+
. ' BEGIN' . "\n"
488487
. ' DECLARE v_rentals INT;' . "\n"
489488
. ' DECLARE v_out INT;' . "\n"
490489
. "\n"
@@ -513,7 +512,7 @@ public function testBuilderCreateFunction()
513512
$stmt->build()
514513
);
515514

516-
$this->assertTrue($stmt->entityOptions->isEmpty());
515+
$this->assertFalse($stmt->entityOptions->isEmpty());
517516
$this->assertFalse($stmt->options->isEmpty());
518517

519518
$this->assertSame(
@@ -532,14 +531,12 @@ public function testBuilderCreateFunction()
532531
);
533532

534533
$this->assertSame(
535-
'',
534+
'READS SQL DATA COMMENT \'My best function written by a friend\'\'s friend\'',
536535
$stmt->entityOptions->__toString()
537536
);
538537

539538
$this->assertSame(
540-
'READS SQL DATA' . "\n"
541-
. ' COMMENT \'My best function written by a friend\'\'s friend' . "\n"
542-
. 'BEGIN' . "\n"
539+
'BEGIN' . "\n"
543540
. ' DECLARE v_rentals INT;' . "\n"
544541
. ' DECLARE v_out INT;' . "\n"
545542
. "\n"
@@ -600,7 +597,7 @@ public function testBuilderRoutine()
600597

601598
$this->assertEquals(
602599
'CREATE FUNCTION test (IN `i` INT) RETURNS VARCHAR ' .
603-
'BEGIN ' .
600+
' BEGIN ' .
604601
'DECLARE name VARCHAR DEFAULT ""; ' .
605602
'SELECT name INTO name FROM employees WHERE id = i; ' .
606603
'RETURN name; ' .

tests/Parser/AlterStatementTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public function alterProvider()
5252
array('parser/parseAlterUser5'),
5353
array('parser/parseAlterUser6'),
5454
array('parser/parseAlterUser7'),
55+
array('parser/parseAlterUser8'),
5556
);
5657
}
5758
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
CREATE DEFINER=`root`@`%` PROCEDURE `test2`(IN `_var` INT) NOT DETERMINISTIC NO SQL SQL SECURITY INVOKER NO SQL SQL SECURITY INVOKER SELECT _var
1+
CREATE DEFINER=`root`@`%` PROCEDURE `test2`(IN `_var` INT) NOT DETERMINISTIC NO SQL SQL SECURITY INVOKER SELECT _var

0 commit comments

Comments
 (0)