Index: trunk/phase3/includes/db/DatabaseMysql.php |
— | — | @@ -670,15 +670,6 @@ |
671 | 671 | } |
672 | 672 | } |
673 | 673 | |
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 | | - |
683 | 674 | /** |
684 | 675 | * @param $lockName string |
685 | 676 | * @param $method string |
Index: trunk/phase3/includes/db/DatabasePostgres.php |
— | — | @@ -1045,17 +1045,4 @@ |
1046 | 1046 | public function getSearchEngine() { |
1047 | 1047 | return 'SearchPostgres'; |
1048 | 1048 | } |
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 | | - } |
1062 | 1049 | } // end DatabasePostgres class |
Index: trunk/phase3/includes/db/Database.php |
— | — | @@ -228,8 +228,6 @@ |
229 | 229 | |
230 | 230 | protected $htmlErrors; |
231 | 231 | |
232 | | - protected $delimiter = ';'; |
233 | | - |
234 | 232 | # ------------------------------------------------------------------------------ |
235 | 233 | # Accessors |
236 | 234 | # ------------------------------------------------------------------------------ |
— | — | @@ -3156,17 +3154,19 @@ |
3157 | 3155 | function sourceStream( $fp, $lineCallback = false, $resultCallback = false, |
3158 | 3156 | $fname = 'DatabaseBase::sourceStream' ) |
3159 | 3157 | { |
3160 | | - $cmd = ''; |
| 3158 | + $cmd = ""; |
3161 | 3159 | $done = false; |
| 3160 | + $dollarquote = false; |
3162 | 3161 | |
3163 | | - while ( !feof( $fp ) ) { |
| 3162 | + while ( ! feof( $fp ) ) { |
3164 | 3163 | if ( $lineCallback ) { |
3165 | 3164 | call_user_func( $lineCallback ); |
3166 | 3165 | } |
3167 | 3166 | |
3168 | 3167 | $line = trim( fgets( $fp ) ); |
| 3168 | + $sl = strlen( $line ) - 1; |
3169 | 3169 | |
3170 | | - if ( $line == '' ) { |
| 3170 | + if ( $sl < 0 ) { |
3171 | 3171 | continue; |
3172 | 3172 | } |
3173 | 3173 | |
— | — | @@ -3174,15 +3174,31 @@ |
3175 | 3175 | continue; |
3176 | 3176 | } |
3177 | 3177 | |
| 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 | + |
3178 | 3195 | if ( $cmd != '' ) { |
3179 | 3196 | $cmd .= ' '; |
3180 | 3197 | } |
3181 | 3198 | |
3182 | | - $done = $this->streamStatementEnd( $cmd, $line ); |
3183 | | - |
3184 | 3199 | $cmd .= "$line\n"; |
3185 | 3200 | |
3186 | | - if ( $done || feof( $fp ) ) { |
| 3201 | + if ( $done ) { |
| 3202 | + $cmd = str_replace( ';;', ";", $cmd ); |
3187 | 3203 | $cmd = $this->replaceVars( $cmd ); |
3188 | 3204 | $res = $this->query( $cmd, $fname ); |
3189 | 3205 | |
— | — | @@ -3204,24 +3220,6 @@ |
3205 | 3221 | } |
3206 | 3222 | |
3207 | 3223 | /** |
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 | | - /** |
3226 | 3224 | * Database independent variable replacement. Replaces a set of variables |
3227 | 3225 | * in an SQL statement with their contents as given by $this->getSchemaVars(). |
3228 | 3226 | * |
Index: trunk/phase3/tests/phpunit/includes/db/DatabaseTest.php |
— | — | @@ -2,22 +2,14 @@ |
3 | 3 | |
4 | 4 | /** |
5 | 5 | * @group Database |
6 | | - * @group DatabaseBase |
7 | 6 | */ |
8 | 7 | class DatabaseTest extends MediaWikiTestCase { |
9 | | - var $db, $functionTest = false; |
| 8 | + var $db; |
10 | 9 | |
11 | 10 | function setUp() { |
12 | | - $this->db = wfGetDB( DB_MASTER ); |
| 11 | + $this->db = wfGetDB( DB_SLAVE ); |
13 | 12 | } |
14 | 13 | |
15 | | - function tearDown() { |
16 | | - if ( $this->functionTest ) { |
17 | | - $this->dropFunctions(); |
18 | | - $this->functionTest = false; |
19 | | - } |
20 | | - } |
21 | | - |
22 | 14 | function testAddQuotesNull() { |
23 | 15 | $check = "NULL"; |
24 | 16 | if ( $this->db->getType() === 'sqlite' || $this->db->getType() === 'oracle' ) { |
— | — | @@ -98,26 +90,6 @@ |
99 | 91 | $sql ); |
100 | 92 | } |
101 | 93 | |
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 | | - } |
122 | 94 | } |
123 | 95 | |
124 | 96 | |