r108603 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r108602‎ | r108603 | r108604 >
Date:09:46, 11 January 2012
Author:hashar
Status:reverted (Comments)
Tags:
Comment:
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.
Modified paths:
  • /trunk/phase3/includes/db/Database.php (modified) (history)
  • /trunk/phase3/includes/db/DatabaseMysql.php (modified) (history)
  • /trunk/phase3/includes/db/DatabasePostgres.php (modified) (history)
  • /trunk/phase3/tests/phpunit/data/db/mysql (deleted) (history)
  • /trunk/phase3/tests/phpunit/data/db/postgres (deleted) (history)
  • /trunk/phase3/tests/phpunit/includes/db/DatabaseTest.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/db/DatabaseMysql.php
@@ -670,15 +670,6 @@
671671 }
672672 }
673673
674 - protected function streamStatementEnd( &$sql, &$newLine ) {
675 - if ( strtoupper( substr( $newLine, 0, 9 ) ) == 'DELIMITER' ) {
676 - preg_match( '/^DELIMITER\s+(\S+)/' , $newLine, $m );
677 - $this->delimiter = $m[1];
678 - $newLine = '';
679 - }
680 - return parent::streamStatementEnd( $sql, $newLine );
681 - }
682 -
683674 /**
684675 * @param $lockName string
685676 * @param $method string
Index: trunk/phase3/includes/db/DatabasePostgres.php
@@ -1045,17 +1045,4 @@
10461046 public function getSearchEngine() {
10471047 return 'SearchPostgres';
10481048 }
1049 -
1050 - protected function streamStatementEnd( &$sql, &$newLine ) {
1051 - # Allow dollar quoting for function declarations
1052 - if ( substr( $newLine, 0, 4 ) == '$mw$' ) {
1053 - if ( $this->delimiter ) {
1054 - $this->delimiter = false;
1055 - }
1056 - else {
1057 - $this->delimiter = ';';
1058 - }
1059 - }
1060 - return parent::streamStatementEnd( $sql, $newLine );
1061 - }
10621049 } // end DatabasePostgres class
Index: trunk/phase3/includes/db/Database.php
@@ -228,8 +228,6 @@
229229
230230 protected $htmlErrors;
231231
232 - protected $delimiter = ';';
233 -
234232 # ------------------------------------------------------------------------------
235233 # Accessors
236234 # ------------------------------------------------------------------------------
@@ -3156,17 +3154,19 @@
31573155 function sourceStream( $fp, $lineCallback = false, $resultCallback = false,
31583156 $fname = 'DatabaseBase::sourceStream' )
31593157 {
3160 - $cmd = '';
 3158+ $cmd = "";
31613159 $done = false;
 3160+ $dollarquote = false;
31623161
3163 - while ( !feof( $fp ) ) {
 3162+ while ( ! feof( $fp ) ) {
31643163 if ( $lineCallback ) {
31653164 call_user_func( $lineCallback );
31663165 }
31673166
31683167 $line = trim( fgets( $fp ) );
 3168+ $sl = strlen( $line ) - 1;
31693169
3170 - if ( $line == '' ) {
 3170+ if ( $sl < 0 ) {
31713171 continue;
31723172 }
31733173
@@ -3174,15 +3174,31 @@
31753175 continue;
31763176 }
31773177
 3178+ # # Allow dollar quoting for function declarations
 3179+ if ( substr( $line, 0, 4 ) == '$mw$' ) {
 3180+ if ( $dollarquote ) {
 3181+ $dollarquote = false;
 3182+ $done = true;
 3183+ }
 3184+ else {
 3185+ $dollarquote = true;
 3186+ }
 3187+ }
 3188+ elseif ( !$dollarquote ) {
 3189+ if ( ';' == $line[$sl] && ( $sl < 2 || ';' != $line[$sl - 1] ) ) {
 3190+ $done = true;
 3191+ $line = substr( $line, 0, $sl );
 3192+ }
 3193+ }
 3194+
31783195 if ( $cmd != '' ) {
31793196 $cmd .= ' ';
31803197 }
31813198
3182 - $done = $this->streamStatementEnd( $cmd, $line );
3183 -
31843199 $cmd .= "$line\n";
31853200
3186 - if ( $done || feof( $fp ) ) {
 3201+ if ( $done ) {
 3202+ $cmd = str_replace( ';;', ";", $cmd );
31873203 $cmd = $this->replaceVars( $cmd );
31883204 $res = $this->query( $cmd, $fname );
31893205
@@ -3204,24 +3220,6 @@
32053221 }
32063222
32073223 /**
3208 - * Called by sourceStream() to check if we've reached a statement end
3209 - *
3210 - * @param $sql String: SQL assembled so far
3211 - * @param $newLine String: New line about to be added to $sql
3212 - * @returns Bool: Whether $newLine contains end of the statement
3213 - */
3214 - protected function streamStatementEnd( &$sql, &$newLine ) {
3215 - if ( $this->delimiter ) {
3216 - $prev = $newLine;
3217 - $newLine = preg_replace( '/' . preg_quote( $this->delimiter, '/' ) . '$/', '', $newLine );
3218 - if ( $newLine != $prev ) {
3219 - return true;
3220 - }
3221 - }
3222 - return false;
3223 - }
3224 -
3225 - /**
32263224 * Database independent variable replacement. Replaces a set of variables
32273225 * in an SQL statement with their contents as given by $this->getSchemaVars().
32283226 *
Index: trunk/phase3/tests/phpunit/includes/db/DatabaseTest.php
@@ -2,22 +2,14 @@
33
44 /**
55 * @group Database
6 - * @group DatabaseBase
76 */
87 class DatabaseTest extends MediaWikiTestCase {
9 - var $db, $functionTest = false;
 8+ var $db;
109
1110 function setUp() {
12 - $this->db = wfGetDB( DB_MASTER );
 11+ $this->db = wfGetDB( DB_SLAVE );
1312 }
1413
15 - function tearDown() {
16 - if ( $this->functionTest ) {
17 - $this->dropFunctions();
18 - $this->functionTest = false;
19 - }
20 - }
21 -
2214 function testAddQuotesNull() {
2315 $check = "NULL";
2416 if ( $this->db->getType() === 'sqlite' || $this->db->getType() === 'oracle' ) {
@@ -98,26 +90,6 @@
9991 $sql );
10092 }
10193
102 - /**
103 - * @group Broken
104 - */
105 - function testStoredFunctions() {
106 - if ( !in_array( wfGetDB( DB_MASTER )->getType(), array( 'mysql', 'postgres' ) ) ) {
107 - $this->markTestSkipped( 'MySQL or Postgres required' );
108 - }
109 - global $IP;
110 - $this->dropFunctions();
111 - $this->functionTest = true;
112 - $this->assertTrue( $this->db->sourceFile( "$IP/tests/phpunit/data/db/{$this->db->getType()}/functions.sql" ) );
113 - $res = $this->db->query( 'SELECT mw_test_function() AS test', __METHOD__ );
114 - $this->assertEquals( 42, $res->fetchObject()->test );
115 - }
116 -
117 - private function dropFunctions() {
118 - $this->db->query( 'DROP FUNCTION IF EXISTS mw_test_function'
119 - . ( $this->db->getType() == 'postgres' ? '()' : '' )
120 - );
121 - }
12294 }
12395
12496

Follow-up revisions

RevisionCommit summaryAuthorDate
r108671Revert r108603, which was itself a revert of r107376, r107994. Before conside...maxsem20:19, 11 January 2012

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r107376Added support for stored procedures/functions to MySQL:...maxsem12:29, 27 December 2011
r107994Follow-up r107376: disable test by default, causes failures in some configura...maxsem08:38, 4 January 2012

Comments

#Comment by Hashar (talk | contribs)   09:47, 11 January 2012

MaxSem > please note I am not against stored procedures supports. But I think it is unlikely to get reviewed for 1.19 so it will most probably end up getting reverted anyway.

Please keep up the work on it, if you need Jenkins to be setup to run test on the branch, let me know!

#Comment by MaxSem (talk | contribs)   09:47, 11 January 2012

It is needed for GeoData.

Status & tagging log