r87290 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r87289‎ | r87290 | r87291 >
Date:20:14, 2 May 2011
Author:reedy
Status:resolved (Comments)
Tags:
Comment:
Add makeInsertOptions

Allow Sqlite to OR IGNORE on UPDATE or INSERT
Modified paths:
  • /trunk/phase3/includes/db/Database.php (modified) (history)
  • /trunk/phase3/includes/db/DatabaseSqlite.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/db/Database.php
@@ -1258,6 +1258,14 @@
12591259 }
12601260
12611261 /**
 1262+ * @param $options array
 1263+ * @return string
 1264+ */
 1265+ function makeInsertOptions( $options ) {
 1266+ return implode( ' ', $options );
 1267+ }
 1268+
 1269+ /**
12621270 * INSERT wrapper, inserts an array into a table
12631271 *
12641272 * $a may be a single associative array, or an array of these with numeric keys, for
@@ -1285,6 +1293,8 @@
12861294 $options = array( $options );
12871295 }
12881296
 1297+ $options = $this->makeInsertOptions( $options );
 1298+
12891299 if ( isset( $a[0] ) && is_array( $a[0] ) ) {
12901300 $multi = true;
12911301 $keys = array_keys( $a[0] );
@@ -1293,7 +1303,7 @@
12941304 $keys = array_keys( $a );
12951305 }
12961306
1297 - $sql = 'INSERT ' . implode( ' ', $options ) .
 1307+ $sql = 'INSERT ' . $options .
12981308 " INTO $table (" . implode( ',', $keys ) . ') VALUES ';
12991309
13001310 if ( $multi ) {
Index: trunk/phase3/includes/db/DatabaseSqlite.php
@@ -363,23 +363,45 @@
364364 }
365365
366366 /**
367 - * Based on generic method (parent) with some prior SQLite-sepcific adjustments
 367+ * @param $options array
 368+ * @return string
368369 */
369 - function insert( $table, $a, $fname = 'DatabaseSqlite::insert', $options = array() ) {
370 - if ( !count( $a ) ) {
371 - return true;
372 - }
373 - if ( !is_array( $options ) ) {
374 - $options = array( $options );
375 - }
 370+ function makeUpdateOptions( $options ) {
 371+ $options = self::fixIgnore( $options );
 372+ return parent::makeUpdateOptions( $options );
 373+ }
376374
 375+ /**
 376+ * @param $options array
 377+ * @return array
 378+ */
 379+ static function fixIgnore( $options ) {
377380 # SQLite uses OR IGNORE not just IGNORE
378381 foreach ( $options as $k => $v ) {
379382 if ( $v == 'IGNORE' ) {
380383 $options[$k] = 'OR IGNORE';
381384 }
382385 }
 386+ return $options;
 387+ }
383388
 389+ /**
 390+ * @param $options array
 391+ * @return string
 392+ */
 393+ function makeInsertOptions( &$options ) {
 394+ $options = self::fixIgnore( $options );
 395+ return parent::makeInsertOptions( $options );
 396+ }
 397+
 398+ /**
 399+ * Based on generic method (parent) with some prior SQLite-sepcific adjustments
 400+ */
 401+ function insert( $table, $a, $fname = 'DatabaseSqlite::insert', $options = array() ) {
 402+ if ( !count( $a ) ) {
 403+ return true;
 404+ }
 405+
384406 # SQLite can't handle multi-row inserts, so divide up into multiple single-row inserts
385407 if ( isset( $a[0] ) && is_array( $a[0] ) ) {
386408 $ret = true;

Follow-up revisions

RevisionCommit summaryAuthorDate
r87302Kill & from r87290reedy21:38, 2 May 2011

Comments

#Comment by Raymond (talk | contribs)   21:37, 2 May 2011

Seen on Translatewiki:

 PHP Strict Standards: Declaration of DatabaseSqlite::makeInsertOptions() should be compatible with that of DatabaseBase::makeInsertOptions() in /www/w/includes/db/DatabaseSqlite.php on line 669
PHP Strict Standards: Declaration of DatabaseSqlite::makeInsertOptions() should be compatible with that of DatabaseBase::makeInsertOptions() in /www/w/includes/AutoLoader.php on line 877
#Comment by Brion VIBBER (talk | contribs)   20:42, 7 June 2011

This was fixed in r87302. Looks ok otherwise.

Status & tagging log