splitSql() public static method

Single line or line end comments and multi line comments are stripped off.
public static splitSql ( string $sql ) : array
$sql string Input SQL string with which to split into individual queries.
return array
Exemplo n.º 1
0
 public function test()
 {
     $queries = Str::splitSql('SELECT * FROM #__foo;SELECT * FROM #__bar;');
     isSame(array('SELECT * FROM #__foo;', 'SELECT * FROM #__bar;'), $queries);
     $queries = Str::splitSql('
         ALTER TABLE `#__redirect_links` DROP INDEX `idx_link_old`;
         -- Some comment
         ALTER TABLE `#__redirect_links` MODIFY `old_url` VARCHAR(2048) NOT NULL;
         -- Some comment
         -- Some comment --
         ALTER TABLE `#__redirect_links` MODIFY `new_url` VARCHAR(2048) NOT NULL;
         -- Some comment
         ALTER TABLE `#__redirect_links` MODIFY `referer` VARCHAR(2048) NOT NULL;
         
         ALTER TABLE `#__redirect_links` ADD INDEX `idx_old_url` (`old_url`(100));
     ');
     isSame(array('ALTER TABLE `#__redirect_links` DROP INDEX `idx_link_old`;', 'ALTER TABLE `#__redirect_links` MODIFY `old_url` VARCHAR(2048) NOT NULL;', 'ALTER TABLE `#__redirect_links` MODIFY `new_url` VARCHAR(2048) NOT NULL;', 'ALTER TABLE `#__redirect_links` MODIFY `referer` VARCHAR(2048) NOT NULL;', 'ALTER TABLE `#__redirect_links` ADD INDEX `idx_old_url` (`old_url`(100));'), $queries);
 }