DatabasePostgres: Ignore "IGNORE" option to update()
[lhc/web/wiklou.git] / includes / libs / rdbms / database / DatabasePostgres.php
index e1cd764..381b1fd 100644 (file)
@@ -653,6 +653,18 @@ __INDEXATTR__;
                return true;
        }
 
+       protected function makeUpdateOptionsArray( $options ) {
+               if ( !is_array( $options ) ) {
+                       $options = [ $options ];
+               }
+
+               // PostgreSQL doesn't support anything like "ignore" for
+               // UPDATE.
+               $options = array_diff( $options, [ 'IGNORE' ] );
+
+               return parent::makeUpdateOptionsArray( $options );
+       }
+
        /**
         * INSERT SELECT wrapper
         * $varMap must be an associative array of the form [ 'dest1' => 'source1', ... ]
@@ -670,9 +682,8 @@ __INDEXATTR__;
         * @param array $insertOptions
         * @param array $selectOptions
         * @param array $selectJoinConds
-        * @return bool
         */
-       public function nativeInsertSelect(
+       protected function nativeInsertSelect(
                $destTable, $srcTable, $varMap, $conds, $fname = __METHOD__,
                $insertOptions = [], $selectOptions = [], $selectJoinConds = []
        ) {
@@ -697,18 +708,18 @@ __INDEXATTR__;
                                $sql = "INSERT INTO $destTable (" . implode( ',', array_keys( $varMap ) ) . ') ' .
                                        $selectSql . ' ON CONFLICT DO NOTHING';
 
-                               return $this->query( $sql, $fname );
+                               $this->query( $sql, $fname );
                        } else {
                                // IGNORE and we don't have ON CONFLICT DO NOTHING, so just use the non-native version
-                               return $this->nonNativeInsertSelect(
+                               $this->nonNativeInsertSelect(
                                        $destTable, $srcTable, $varMap, $conds, $fname,
                                        $insertOptions, $selectOptions, $selectJoinConds
                                );
                        }
+               } else {
+                       parent::nativeInsertSelect( $destTable, $srcTable, $varMap, $conds, $fname,
+                               $insertOptions, $selectOptions, $selectJoinConds );
                }
-
-               return parent::nativeInsertSelect( $destTable, $srcTable, $varMap, $conds, $fname,
-                       $insertOptions, $selectOptions, $selectJoinConds );
        }
 
        public function tableName( $name, $format = 'quoted' ) {
@@ -817,7 +828,7 @@ __INDEXATTR__;
                        . ' WHERE relkind = \'r\''
                        . ' AND nspname = ' . $this->addQuotes( $this->getCoreSchema() )
                        . ' AND relname = ' . $this->addQuotes( $oldName )
-                       . ' AND adsrc LIKE \'nextval(%\'',
+                       . ' AND pg_get_expr(adbin, adrelid) LIKE \'nextval(%\'',
                        $fname
                );
                $row = $this->fetchObject( $res );
@@ -852,10 +863,10 @@ __INDEXATTR__;
                        }
 
                        $oid = $this->fetchObject( $res )->oid;
-                       $res = $this->query( 'SELECT adsrc FROM pg_attribute a'
+                       $res = $this->query( 'SELECT pg_get_expr(adbin, adrelid) AS adsrc FROM pg_attribute a'
                                . ' JOIN pg_attrdef d ON (a.attrelid=d.adrelid and a.attnum=d.adnum)'
                                . " WHERE a.attrelid = $oid"
-                               . ' AND adsrc LIKE \'nextval(%\'',
+                               . ' AND pg_get_expr(adbin, adrelid) LIKE \'nextval(%\'',
                                $fname
                        );
                        $row = $this->fetchObject( $res );
@@ -917,22 +928,22 @@ __INDEXATTR__;
         * @return string[]
         */
        private function pg_array_parse( $text, &$output, $limit = false, $offset = 1 ) {
-               if ( false === $limit ) {
+               if ( $limit === false ) {
                        $limit = strlen( $text ) - 1;
                        $output = [];
                }
-               if ( '{}' == $text ) {
+               if ( $text == '{}' ) {
                        return $output;
                }
                do {
-                       if ( '{' != $text[$offset] ) {
+                       if ( $text[$offset] != '{' ) {
                                preg_match( "/(\\{?\"([^\"\\\\]|\\\\.)*\"|[^,{}]+)+([,}]+)/",
                                        $text, $match, 0, $offset );
                                $offset += strlen( $match[0] );
-                               $output[] = ( '"' != $match[1][0]
+                               $output[] = ( $match[1][0] != '"'
                                        ? $match[1]
                                        : stripcslashes( substr( $match[1], 1, -1 ) ) );
-                               if ( '},' == $match[3] ) {
+                               if ( $match[3] == '},' ) {
                                        return $output;
                                }
                        } else {