From f5f1b6d0bb47521a5941740c52c439194cbdfddc Mon Sep 17 00:00:00 2001 From: Antoine Musso Date: Wed, 11 Jan 2012 09:46:21 +0000 Subject: [PATCH] Reverts MySQL stored procedure support 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 | 50 ++++++++++---------- includes/db/DatabaseMysql.php | 9 ---- includes/db/DatabasePostgres.php | 13 ----- tests/phpunit/data/db/mysql/functions.sql | 12 ----- tests/phpunit/data/db/postgres/functions.sql | 12 ----- tests/phpunit/includes/db/DatabaseTest.php | 32 +------------ 6 files changed, 26 insertions(+), 102 deletions(-) delete mode 100644 tests/phpunit/data/db/mysql/functions.sql delete mode 100644 tests/phpunit/data/db/postgres/functions.sql diff --git a/includes/db/Database.php b/includes/db/Database.php index 5c186df3b3..9adac3b66a 100644 --- a/includes/db/Database.php +++ b/includes/db/Database.php @@ -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(). diff --git a/includes/db/DatabaseMysql.php b/includes/db/DatabaseMysql.php index 95d3968be7..7054c8bb25 100644 --- a/includes/db/DatabaseMysql.php +++ b/includes/db/DatabaseMysql.php @@ -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 diff --git a/includes/db/DatabasePostgres.php b/includes/db/DatabasePostgres.php index 38950c3961..bb8ff7d7ad 100644 --- a/includes/db/DatabasePostgres.php +++ b/includes/db/DatabasePostgres.php @@ -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 index 9e5e470f59..0000000000 --- a/tests/phpunit/data/db/mysql/functions.sql +++ /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 index 3086d4d5a6..0000000000 --- a/tests/phpunit/data/db/postgres/functions.sql +++ /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$; diff --git a/tests/phpunit/includes/db/DatabaseTest.php b/tests/phpunit/includes/db/DatabaseTest.php index 672e6645b8..d480ac6e00 100644 --- a/tests/phpunit/includes/db/DatabaseTest.php +++ b/tests/phpunit/includes/db/DatabaseTest.php @@ -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' ? '()' : '' ) - ); - } } -- 2.20.1