rdbms: Remove references to pg_attrdef.adsrc in Postgres code
[lhc/web/wiklou.git] / includes / libs / rdbms / database / DatabasePostgres.php
index 525d308..299eb3c 100644 (file)
@@ -640,6 +640,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', ... ]
@@ -789,7 +801,9 @@ __INDEXATTR__;
                $newNameE = $this->addIdentifierQuotes( $newName );
                $oldNameE = $this->addIdentifierQuotes( $oldName );
 
-               $ret = $this->query( 'CREATE ' . ( $temporary ? 'TEMPORARY ' : '' ) . " TABLE $newNameE " .
+               $temporary = $temporary ? 'TEMPORARY' : '';
+
+               $ret = $this->query( "CREATE $temporary TABLE $newNameE " .
                        "(LIKE $oldNameE INCLUDING DEFAULTS INCLUDING INDEXES)", $fname );
                if ( !$ret ) {
                        return $ret;
@@ -802,7 +816,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 );
@@ -812,7 +826,7 @@ __INDEXATTR__;
                        $fieldE = $this->addIdentifierQuotes( $field );
                        $newSeqE = $this->addIdentifierQuotes( $newSeq );
                        $newSeqQ = $this->addQuotes( $newSeq );
-                       $this->query( 'CREATE ' . ( $temporary ? 'TEMPORARY ' : '' ) . " SEQUENCE $newSeqE", $fname );
+                       $this->query( "CREATE $temporary SEQUENCE $newSeqE OWNED BY $newNameE.$fieldE", $fname );
                        $this->query(
                                "ALTER TABLE $newNameE ALTER COLUMN $fieldE SET DEFAULT nextval({$newSeqQ}::regclass)",
                                $fname
@@ -837,10 +851,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 );