Ignore:
Timestamp:
2013/08/02 13:22:57 (13 years ago)
Author:
Seasoft
Message:

#2322 (セッションのGC処理がエラーとなる)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/version-2_13-dev/data/module/MDB2/Driver/Manager/pgsql.php

    r20764 r23022  
    4343// +----------------------------------------------------------------------+ 
    4444// 
    45 // $Id: pgsql.php,v 1.87 2008/11/29 14:09:59 afz Exp $ 
     45// $Id: pgsql.php 327310 2012-08-27 15:16:18Z danielc $ 
    4646 
    4747require_once 'MDB2/Driver/Manager/Common.php'; 
     
    6969    function createDatabase($name, $options = array()) 
    7070    { 
    71         $db =& $this->getDBInstance(); 
    72         if (PEAR::isError($db)) { 
     71        $db = $this->getDBInstance(); 
     72        if (MDB2::isError($db)) { 
    7373            return $db; 
    7474        } 
     
    9696    function alterDatabase($name, $options = array()) 
    9797    { 
    98         $db =& $this->getDBInstance(); 
    99         if (PEAR::isError($db)) { 
    100             return $db; 
    101         } 
    102  
    103         $query = 'ALTER DATABASE '. $db->quoteIdentifier($name, true); 
     98        $db = $this->getDBInstance(); 
     99        if (MDB2::isError($db)) { 
     100            return $db; 
     101        } 
     102 
     103        $query = ''; 
    104104        if (!empty($options['name'])) { 
    105105            $query .= ' RENAME TO ' . $options['name']; 
     
    108108            $query .= ' OWNER TO ' . $options['owner']; 
    109109        } 
     110 
     111        if (empty($query)) { 
     112            return MDB2_OK; 
     113        } 
     114 
     115        $query = 'ALTER DATABASE '. $db->quoteIdentifier($name, true) . $query; 
    110116        return $db->standaloneQuery($query, null, true); 
    111117    } 
     
    123129    function dropDatabase($name) 
    124130    { 
    125         $db =& $this->getDBInstance(); 
    126         if (PEAR::isError($db)) { 
     131        $db = $this->getDBInstance(); 
     132        if (MDB2::isError($db)) { 
    127133            return $db; 
    128134        } 
     
    182188    function truncateTable($name) 
    183189    { 
    184         $db =& $this->getDBInstance(); 
    185         if (PEAR::isError($db)) { 
     190        $db = $this->getDBInstance(); 
     191        if (MDB2::isError($db)) { 
    186192            return $db; 
    187193        } 
    188194 
    189195        $name = $db->quoteIdentifier($name, true); 
    190         return $db->exec("TRUNCATE TABLE $name"); 
     196        $result = $db->exec("TRUNCATE TABLE $name"); 
     197        if (MDB2::isError($result)) { 
     198            return $result; 
     199        } 
     200        return MDB2_OK; 
    191201    } 
    192202 
     
    210220    function vacuum($table = null, $options = array()) 
    211221    { 
    212         $db =& $this->getDBInstance(); 
    213         if (PEAR::isError($db)) { 
     222        $db = $this->getDBInstance(); 
     223        if (MDB2::isError($db)) { 
    214224            return $db; 
    215225        } 
     
    229239            $query .= ' '.$db->quoteIdentifier($table, true); 
    230240        } 
    231         return $db->exec($query); 
     241        $result = $db->exec($query); 
     242        if (MDB2::isError($result)) { 
     243            return $result; 
     244        } 
     245        return MDB2_OK; 
    232246    } 
    233247 
     
    327341    function alterTable($name, $changes, $check) 
    328342    { 
    329         $db =& $this->getDBInstance(); 
    330         if (PEAR::isError($db)) { 
     343        $db = $this->getDBInstance(); 
     344        if (MDB2::isError($db)) { 
    331345            return $db; 
    332346        } 
     
    357371                $query = 'DROP ' . $field_name; 
    358372                $result = $db->exec("ALTER TABLE $name $query"); 
    359                 if (PEAR::isError($result)) { 
     373                if (MDB2::isError($result)) { 
    360374                    return $result; 
    361375                } 
     
    367381                $field_name = $db->quoteIdentifier($field_name, true); 
    368382                $result = $db->exec("ALTER TABLE $name RENAME COLUMN $field_name TO ".$db->quoteIdentifier($field['name'], true)); 
    369                 if (PEAR::isError($result)) { 
     383                if (MDB2::isError($result)) { 
    370384                    return $result; 
    371385                } 
     
    377391                $query = 'ADD ' . $db->getDeclaration($field['type'], $field_name, $field); 
    378392                $result = $db->exec("ALTER TABLE $name $query"); 
    379                 if (PEAR::isError($result)) { 
     393                if (MDB2::isError($result)) { 
    380394                    return $result; 
    381395                } 
     
    388402                if (!empty($field['definition']['type'])) { 
    389403                    $server_info = $db->getServerVersion(); 
    390                     if (PEAR::isError($server_info)) { 
     404                    if (MDB2::isError($server_info)) { 
    391405                        return $server_info; 
    392406                    } 
     
    399413                    $query = "ALTER $field_name TYPE $type USING CAST($field_name AS $type)"; 
    400414                    $result = $db->exec("ALTER TABLE $name $query"); 
    401                     if (PEAR::isError($result)) { 
     415                    if (MDB2::isError($result)) { 
    402416                        return $result; 
    403417                    } 
     
    406420                    $query = "ALTER $field_name SET DEFAULT ".$db->quote($field['definition']['default'], $field['definition']['type']); 
    407421                    $result = $db->exec("ALTER TABLE $name $query"); 
    408                     if (PEAR::isError($result)) { 
     422                    if (MDB2::isError($result)) { 
    409423                        return $result; 
    410424                    } 
    411425                } 
    412                 if (!empty($field['definition']['notnull'])) { 
     426                if (array_key_exists('notnull', $field['definition'])) { 
    413427                    $query = "ALTER $field_name ".($field['definition']['notnull'] ? 'SET' : 'DROP').' NOT NULL'; 
    414428                    $result = $db->exec("ALTER TABLE $name $query"); 
    415                     if (PEAR::isError($result)) { 
     429                    if (MDB2::isError($result)) { 
    416430                        return $result; 
    417431                    } 
     
    423437            $change_name = $db->quoteIdentifier($changes['name'], true); 
    424438            $result = $db->exec("ALTER TABLE $name RENAME TO ".$change_name); 
    425             if (PEAR::isError($result)) { 
     439            if (MDB2::isError($result)) { 
    426440                return $result; 
    427441            } 
     
    442456    function listDatabases() 
    443457    { 
    444         $db =& $this->getDBInstance(); 
    445         if (PEAR::isError($db)) { 
     458        $db = $this->getDBInstance(); 
     459        if (MDB2::isError($db)) { 
    446460            return $db; 
    447461        } 
     
    455469        $result = $result2->fetchCol(); 
    456470        $result2->free(); 
    457         if (PEAR::isError($result)) { 
     471        if (MDB2::isError($result)) { 
    458472            return $result; 
    459473        } 
     
    475489    function listUsers() 
    476490    { 
    477         $db =& $this->getDBInstance(); 
    478         if (PEAR::isError($db)) { 
     491        $db = $this->getDBInstance(); 
     492        if (MDB2::isError($db)) { 
    479493            return $db; 
    480494        } 
     
    502516    function listViews() 
    503517    { 
    504         $db =& $this->getDBInstance(); 
    505         if (PEAR::isError($db)) { 
     518        $db = $this->getDBInstance(); 
     519        if (MDB2::isError($db)) { 
    506520            return $db; 
    507521        } 
     
    512526                     AND viewname !~ '^pg_'"; 
    513527        $result = $db->queryCol($query); 
    514         if (PEAR::isError($result)) { 
     528        if (MDB2::isError($result)) { 
    515529            return $result; 
    516530        } 
     
    533547    function listTableViews($table) 
    534548    { 
    535         $db =& $this->getDBInstance(); 
    536         if (PEAR::isError($db)) { 
     549        $db = $this->getDBInstance(); 
     550        if (MDB2::isError($db)) { 
    537551            return $db; 
    538552        } 
     
    541555        $query.= ' WHERE tablename ='.$db->quote($table, 'text'); 
    542556        $result = $db->queryCol($query); 
    543         if (PEAR::isError($result)) { 
     557        if (MDB2::isError($result)) { 
    544558            return $result; 
    545559        } 
     
    561575    function listFunctions() 
    562576    { 
    563         $db =& $this->getDBInstance(); 
    564         if (PEAR::isError($db)) { 
     577        $db = $this->getDBInstance(); 
     578        if (MDB2::isError($db)) { 
    565579            return $db; 
    566580        } 
     
    579593                    (SELECT oid FROM pg_namespace WHERE nspname NOT LIKE 'pg_%' AND nspname != 'information_schema')"; 
    580594        $result = $db->queryCol($query); 
    581         if (PEAR::isError($result)) { 
     595        if (MDB2::isError($result)) { 
    582596            return $result; 
    583597        } 
     
    600614    function listTableTriggers($table = null) 
    601615    { 
    602         $db =& $this->getDBInstance(); 
    603         if (PEAR::isError($db)) { 
     616        $db = $this->getDBInstance(); 
     617        if (MDB2::isError($db)) { 
    604618            return $db; 
    605619        } 
     
    609623                         pg_class tbl 
    610624                   WHERE trg.tgrelid = tbl.oid'; 
    611         if (!is_null($table)) { 
     625        if (null !== $table) { 
    612626            $table = $db->quote(strtoupper($table), 'text'); 
    613             $query .= " AND tbl.relname = $table"; 
     627            $query .= " AND UPPER(tbl.relname) = $table"; 
    614628        } 
    615629        $result = $db->queryCol($query); 
    616         if (PEAR::isError($result)) { 
     630        if (MDB2::isError($result)) { 
    617631            return $result; 
    618632        } 
     
    634648    function listTables() 
    635649    { 
    636         $db =& $this->getDBInstance(); 
    637         if (PEAR::isError($db)) { 
     650        $db = $this->getDBInstance(); 
     651        if (MDB2::isError($db)) { 
    638652            return $db; 
    639653        } 
     
    660674            . " AND c.relname !~ '^pg_'"; 
    661675        $result = $db->queryCol($query); 
    662         if (PEAR::isError($result)) { 
     676        if (MDB2::isError($result)) { 
    663677            return $result; 
    664678        } 
     
    681695    function listTableFields($table) 
    682696    { 
    683         $db =& $this->getDBInstance(); 
    684         if (PEAR::isError($db)) { 
     697        $db = $this->getDBInstance(); 
     698        if (MDB2::isError($db)) { 
    685699            return $db; 
    686700        } 
     
    694708        $db->setLimit(1); 
    695709        $result2 = $db->query("SELECT * FROM $table"); 
    696         if (PEAR::isError($result2)) { 
     710        if (MDB2::isError($result2)) { 
    697711            return $result2; 
    698712        } 
    699713        $result = $result2->getColumnNames(); 
    700714        $result2->free(); 
    701         if (PEAR::isError($result)) { 
     715        if (MDB2::isError($result)) { 
    702716            return $result; 
    703717        } 
     
    717731    function listTableIndexes($table) 
    718732    { 
    719         $db =& $this->getDBInstance(); 
    720         if (PEAR::isError($db)) { 
     733        $db = $this->getDBInstance(); 
     734        if (MDB2::isError($db)) { 
    721735            return $db; 
    722736        } 
     
    737751        $query = "SELECT relname FROM pg_class WHERE oid IN ($subquery)"; 
    738752        $indexes = $db->queryCol($query, 'text'); 
    739         if (PEAR::isError($indexes)) { 
     753        if (MDB2::isError($indexes)) { 
    740754            return $indexes; 
    741755        } 
     
    770784    function dropConstraint($table, $name, $primary = false) 
    771785    { 
    772         $db =& $this->getDBInstance(); 
    773         if (PEAR::isError($db)) { 
     786        $db = $this->getDBInstance(); 
     787        if (MDB2::isError($db)) { 
    774788            return $db; 
    775789        } 
     
    790804                    AND relname = '. $db->quote($table, 'text'); 
    791805        $unique = $db->queryCol($query, 'text'); 
    792         if (PEAR::isError($unique) || empty($unique)) { 
     806        if (MDB2::isError($unique) || empty($unique)) { 
    793807            // not an UNIQUE index, maybe a CONSTRAINT 
    794808            return parent::dropConstraint($table, $name, $primary); 
     
    796810 
    797811        if (in_array($name, $unique)) { 
    798             return $db->exec('DROP INDEX '.$db->quoteIdentifier($name, true)); 
     812            $result = $db->exec('DROP INDEX '.$db->quoteIdentifier($name, true)); 
     813            if (MDB2::isError($result)) { 
     814                return $result; 
     815            } 
     816            return MDB2_OK; 
    799817        } 
    800818        $idxname = $db->getIndexName($name); 
    801819        if (in_array($idxname, $unique)) { 
    802             return $db->exec('DROP INDEX '.$db->quoteIdentifier($idxname, true)); 
     820            $result = $db->exec('DROP INDEX '.$db->quoteIdentifier($idxname, true)); 
     821            if (MDB2::isError($result)) { 
     822                return $result; 
     823            } 
     824            return MDB2_OK; 
    803825        } 
    804826        return $db->raiseError(MDB2_ERROR_NOT_FOUND, null, null, 
     
    818840    function listTableConstraints($table) 
    819841    { 
    820         $db =& $this->getDBInstance(); 
    821         if (PEAR::isError($db)) { 
     842        $db = $this->getDBInstance(); 
     843        if (MDB2::isError($db)) { 
    822844            return $db; 
    823845        } 
     
    850872        $query .= ')'; 
    851873        $constraints = $db->queryCol($query); 
    852         if (PEAR::isError($constraints)) { 
     874        if (MDB2::isError($constraints)) { 
    853875            return $constraints; 
    854876        } 
     
    883905    function createSequence($seq_name, $start = 1) 
    884906    { 
    885         $db =& $this->getDBInstance(); 
    886         if (PEAR::isError($db)) { 
     907        $db = $this->getDBInstance(); 
     908        if (MDB2::isError($db)) { 
    887909            return $db; 
    888910        } 
    889911 
    890912        $sequence_name = $db->quoteIdentifier($db->getSequenceName($seq_name), true); 
    891         return $db->exec("CREATE SEQUENCE $sequence_name INCREMENT 1". 
     913        $result = $db->exec("CREATE SEQUENCE $sequence_name INCREMENT 1". 
    892914            ($start < 1 ? " MINVALUE $start" : '')." START $start"); 
     915        if (MDB2::isError($result)) { 
     916            return $result; 
     917        } 
     918        return MDB2_OK; 
    893919    } 
    894920 
     
    905931    function dropSequence($seq_name) 
    906932    { 
    907         $db =& $this->getDBInstance(); 
    908         if (PEAR::isError($db)) { 
     933        $db = $this->getDBInstance(); 
     934        if (MDB2::isError($db)) { 
    909935            return $db; 
    910936        } 
    911937 
    912938        $sequence_name = $db->quoteIdentifier($db->getSequenceName($seq_name), true); 
    913         return $db->exec("DROP SEQUENCE $sequence_name"); 
     939        $result = $db->exec("DROP SEQUENCE $sequence_name"); 
     940        if (MDB2::isError($result)) { 
     941            return $result; 
     942        } 
     943        return MDB2_OK; 
    914944    } 
    915945 
     
    925955    function listSequences() 
    926956    { 
    927         $db =& $this->getDBInstance(); 
    928         if (PEAR::isError($db)) { 
     957        $db = $this->getDBInstance(); 
     958        if (MDB2::isError($db)) { 
    929959            return $db; 
    930960        } 
     
    933963        $query.= "(SELECT oid FROM pg_namespace WHERE nspname NOT LIKE 'pg_%' AND nspname != 'information_schema')"; 
    934964        $table_names = $db->queryCol($query); 
    935         if (PEAR::isError($table_names)) { 
     965        if (MDB2::isError($table_names)) { 
    936966            return $table_names; 
    937967        } 
Note: See TracChangeset for help on using the changeset viewer.