Reverts MySQL stored procedure support
authorAntoine Musso <hashar@users.mediawiki.org>
Wed, 11 Jan 2012 09:46:21 +0000 (09:46 +0000)
committerAntoine Musso <hashar@users.mediawiki.org>
Wed, 11 Jan 2012 09:46:21 +0000 (09:46 +0000)
This is reverting the work done by MaxSem to support stored procedures
and stored function in MySQL. The reasons are:
 - it is not needed yet
 - tests are not functionals
 - alter the stable include/db/Database.php and drop support for ';;'

So please create a branch to work on it and merge it back in trunk
once we have branched 1.19 :-)

I have opened bug 33654 to track this enhancement request.

Reverts r107376, r107994.

includes/db/Database.php
includes/db/DatabaseMysql.php
includes/db/DatabasePostgres.php
tests/phpunit/data/db/mysql/functions.sql [deleted file]
tests/phpunit/data/db/postgres/functions.sql [deleted file]
tests/phpunit/includes/db/DatabaseTest.php

index 5c186df..9adac3b 100644 (file)
@@ -228,8 +228,6 @@ abstract class DatabaseBase implements DatabaseType {
 
        protected $htmlErrors;
 
-       protected $delimiter = ';';
-
 # ------------------------------------------------------------------------------
 # Accessors
 # ------------------------------------------------------------------------------
@@ -3156,17 +3154,19 @@ abstract class DatabaseBase implements DatabaseType {
        function sourceStream( $fp, $lineCallback = false, $resultCallback = false,
                $fname = 'DatabaseBase::sourceStream' )
        {
-               $cmd = '';
+               $cmd = "";
                $done = false;
+               $dollarquote = false;
 
-               while ( !feof( $fp ) ) {
+               while ( ! feof( $fp ) ) {
                        if ( $lineCallback ) {
                                call_user_func( $lineCallback );
                        }
 
                        $line = trim( fgets( $fp ) );
+                       $sl = strlen( $line ) - 1;
 
-                       if ( $line == '' ) {
+                       if ( $sl < 0 ) {
                                continue;
                        }
 
@@ -3174,15 +3174,31 @@ abstract class DatabaseBase implements DatabaseType {
                                continue;
                        }
 
+                       # # Allow dollar quoting for function declarations
+                       if ( substr( $line, 0, 4 ) == '$mw$' ) {
+                               if ( $dollarquote ) {
+                                       $dollarquote = false;
+                                       $done = true;
+                               }
+                               else {
+                                       $dollarquote = true;
+                               }
+                       }
+                       elseif ( !$dollarquote ) {
+                               if ( ';' == $line[$sl] && ( $sl < 2 || ';' != $line[$sl - 1] ) ) {
+                                       $done = true;
+                                       $line = substr( $line, 0, $sl );
+                               }
+                       }
+
                        if ( $cmd != '' ) {
                                $cmd .= ' ';
                        }
 
-                       $done = $this->streamStatementEnd( $cmd, $line );
-
                        $cmd .= "$line\n";
 
-                       if ( $done || feof( $fp ) ) {
+                       if ( $done ) {
+                               $cmd = str_replace( ';;', ";", $cmd );
                                $cmd = $this->replaceVars( $cmd );
                                $res = $this->query( $cmd, $fname );
 
@@ -3203,24 +3219,6 @@ abstract class DatabaseBase implements DatabaseType {
                return true;
        }
 
-       /**
-        * Called by sourceStream() to check if we've reached a statement end
-        *
-        * @param $sql String: SQL assembled so far
-        * @param $newLine String: New line about to be added to $sql
-        * @returns Bool: Whether $newLine contains end of the statement
-        */
-       protected function streamStatementEnd( &$sql, &$newLine ) {
-               if ( $this->delimiter ) {
-                       $prev = $newLine;
-                       $newLine = preg_replace( '/' . preg_quote( $this->delimiter, '/' ) . '$/', '', $newLine );
-                       if ( $newLine != $prev ) {
-                               return true;
-                       }
-               }
-               return false;
-       }
-
        /**
         * Database independent variable replacement. Replaces a set of variables
         * in an SQL statement with their contents as given by $this->getSchemaVars().
index 95d3968..7054c8b 100644 (file)
@@ -670,15 +670,6 @@ class DatabaseMysql extends DatabaseBase {
                }
        }
 
-       protected function streamStatementEnd( &$sql, &$newLine ) {
-               if ( strtoupper( substr( $newLine, 0, 9 ) ) == 'DELIMITER' ) {
-                       preg_match( '/^DELIMITER\s+(\S+)/' , $newLine, $m );
-                       $this->delimiter = $m[1];
-                       $newLine = '';
-               }
-               return parent::streamStatementEnd( $sql, $newLine );
-       }
-
        /**
         * @param $lockName string
         * @param $method string
index 38950c3..bb8ff7d 100644 (file)
@@ -1045,17 +1045,4 @@ SQL;
        public function getSearchEngine() {
                return 'SearchPostgres';
        }
-
-       protected function streamStatementEnd( &$sql, &$newLine ) {
-               # Allow dollar quoting for function declarations
-               if ( substr( $newLine, 0, 4 ) == '$mw$' ) {
-                       if ( $this->delimiter ) {
-                               $this->delimiter = false;
-                       }
-                       else {
-                               $this->delimiter = ';';
-                       }
-               }
-               return parent::streamStatementEnd( $sql, $newLine );
-       }
 } // end DatabasePostgres class
diff --git a/tests/phpunit/data/db/mysql/functions.sql b/tests/phpunit/data/db/mysql/functions.sql
deleted file mode 100644 (file)
index 9e5e470..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
--- MySQL test file for DatabaseTest::testStoredFunctions()
-
-DELIMITER //
-
-CREATE FUNCTION mw_test_function()
-RETURNS int DETERMINISTIC
-BEGIN
-       SET @foo = 21;
-       RETURN @foo * 2;
-END//
-
-DELIMITER //
diff --git a/tests/phpunit/data/db/postgres/functions.sql b/tests/phpunit/data/db/postgres/functions.sql
deleted file mode 100644 (file)
index 3086d4d..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
--- Postgres test file for DatabaseTest::testStoredFunctions()
-
-CREATE FUNCTION mw_test_function()
-RETURNS INTEGER
-LANGUAGE plpgsql AS
-$mw$
-DECLARE foo INTEGER;
-BEGIN
-       foo := 21;
-       RETURN foo * 2;
-END
-$mw$;
index 672e664..d480ac6 100644 (file)
@@ -2,20 +2,12 @@
 
 /**
  * @group Database
- * @group DatabaseBase
  */
 class DatabaseTest extends MediaWikiTestCase {
-       var $db, $functionTest = false;
+       var $db;
 
        function setUp() {
-               $this->db = wfGetDB( DB_MASTER );
-       }
-
-       function tearDown() {
-               if ( $this->functionTest ) {
-                       $this->dropFunctions();
-                       $this->functionTest = false;
-               }
+               $this->db = wfGetDB( DB_SLAVE );
        }
 
        function testAddQuotesNull() {
@@ -98,26 +90,6 @@ class DatabaseTest extends MediaWikiTestCase {
                        $sql );
        }
 
-       /**
-        * @group Broken
-        */
-       function testStoredFunctions() {
-               if ( !in_array( wfGetDB( DB_MASTER )->getType(), array( 'mysql', 'postgres' ) ) ) {
-                       $this->markTestSkipped( 'MySQL or Postgres required' );
-               }
-               global $IP;
-               $this->dropFunctions();
-               $this->functionTest = true;
-               $this->assertTrue( $this->db->sourceFile( "$IP/tests/phpunit/data/db/{$this->db->getType()}/functions.sql" ) );
-               $res = $this->db->query( 'SELECT mw_test_function() AS test', __METHOD__ );
-               $this->assertEquals( 42, $res->fetchObject()->test );
-       }
-
-       private function dropFunctions() {
-               $this->db->query( 'DROP FUNCTION IF EXISTS mw_test_function'
-                       . ( $this->db->getType() == 'postgres'  ? '()' : '' )
-               );
-       }
 }