Ticket #126: postgres_schema_support.patch

File postgres_schema_support.patch, 4.9 kB (added by bithead, 13 months ago)

Additions to QPostgreSqlDatabase, QDatabaseBase, QApplicationBase

  • database/QPostgreSqlDatabase.class.php

     
    158158                        $strUsername = $this->Username; 
    159159                        $strPassword = $this->Password; 
    160160                        $strPort = $this->Port; 
     161                        $strSchema = $this->Schema; 
    161162 
    162163                        // Connect to the Database Server 
    163164                        $this->objPgSql = pg_connect(sprintf('host=%s dbname=%s user=%s password=%s port=%s',$strServer, $strName, $strUsername, $strPassword, $strPort)); 
     
    165166                        if (!$this->objPgSql) 
    166167                                throw new QPostgreSqlDatabaseException("Unable to connect to Database", -1, null); 
    167168 
     169                        //Set to schema, if different from "public" 
     170                        if ($strSchema) $this->Query("SET search_path TO " . $this->Schema . ";"); 
     171 
    168172                        // Update Connected Flag 
    169173                        $this->blnConnectedFlag = true; 
    170174                } 
     
    216220                } 
    217221 
    218222                public function GetTables() { 
    219                         $objResult = $this->Query("SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = current_schema() ORDER BY TABLE_NAME ASC"); 
     223                        $objResult = $this->Query("SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = ANY(current_schemas(false)) ORDER BY TABLE_NAME ASC"); 
    220224                        $strToReturn = array(); 
    221225                        while ($strRowArray = $objResult->FetchRow()) 
    222226                                array_push($strToReturn, $strRowArray[0]); 
     
    238242                                FROM  
    239243                                        INFORMATION_SCHEMA.COLUMNS  
    240244                                WHERE  
    241                                         table_schema = current_schema()  
     245                                        table_schema = ANY(current_schemas(false)) 
    242246                                AND  
    243247                                        table_name = %s  
    244248                                ORDER BY ordinal_position                
     
    378382                                                                        oid  
    379383                                                                FROM  
    380384                                                                        pg_catalog.pg_namespace 
    381                                                                 WHERE  
    382                                                                         nspname=current_schema() 
     385                                                                WHERE 
     386                                    nspname=ANY(current_schemas(false)) 
    383387                                                        ) 
    384388                                        ) 
    385389                                AND  
     
    399403                                // Index 1: the list of columns that are the foreign key 
    400404                                // Index 2: the table which this FK references 
    401405                                // Index 3: the list of columns which this FK references 
    402                                 $strTokenArray = split('FOREIGN KEY ', $objRow->GetColumn('consrc')); 
    403                                 $strTokenArray[1] = split(' REFERENCES ', $strTokenArray[1]); 
     406                                $strTokenArray = explode('FOREIGN KEY ', $objRow->GetColumn('consrc')); 
     407                                $strTokenArray[1] = explode(' REFERENCES ', $strTokenArray[1]); 
    404408                                $strTokenArray[2] = $strTokenArray[1][1]; 
    405409                                $strTokenArray[1] = $strTokenArray[1][0]; 
    406410                                $strTokenArray[2] = explode("(", $strTokenArray[2]); 
     
    569573                                WHERE  
    570574                                        tc.table_name = %s  
    571575                                AND  
    572                                         tc.table_schema = current_schema()  
     576                                        tc.table_schema = ANY(current_schemas(false)) 
    573577                                AND  
    574578                                        tc.constraint_type = \'PRIMARY KEY\'  
    575579                                AND  
     
    598602                                WHERE  
    599603                                        tc.table_name = %s  
    600604                                AND  
    601                                         tc.table_schema = current_schema()  
     605                                        tc.table_schema = ANY(current_schemas(false)) 
    602606                                AND  
    603607                                        tc.constraint_type = \'UNIQUE\'  
    604608                                AND  
     
    646650                                        break; 
    647651                                case 'character': 
    648652                                        $this->strType = QDatabaseFieldType::Char; 
    649                                         break;                           
     653                                        break; 
     654                case 'interval': 
    650655                                case 'character varying': 
    651656                                case 'double precision':  
    652657                                        // NOTE: PHP does not offer full support of double-precision floats. 
     
    659664                                        $this->strType = QDatabaseFieldType::Blob; 
    660665                                        break; 
    661666                                case 'timestamp': 
     667                                case 'timestamp with time zone': 
    662668                                case 'timestamp without time zone': 
    663                                         // System-generated Timestamp values need to be treated as plain text 
    664                                         $this->strType = QDatabaseFieldType::VarChar; 
     669                                        // System-generated Timestamp values need to be treated as plain text 
     670                                        $this->strType = QDatabaseFieldType::VarChar; 
    665671                                        $this->blnTimestamp = true; 
    666672                                        break; 
    667673                                case 'date': 
    668674                                        $this->strType = QDatabaseFieldType::Date; 
    669675                                        break; 
    670676                                case 'time': 
    671                                 case 'time without time zone':           
     677                                case 'time with time zone': 
     678                                case 'time without time zone': 
    672679                                        $this->strType = QDatabaseFieldType::Time; 
    673680                                        break; 
    674681                                default: 
  • framework/QApplicationBase.class.php

     
    377377                                        // Expected Keys to be Set 
    378378                                        $strExpectedKeys = array( 
    379379                                                'adapter', 'server', 'port', 'database', 
    380                                                 'username', 'password', 'profiling' 
     380                                                'username', 'password', 'profiling', 'schema' 
    381381                                        ); 
    382382 
    383383                                        // Lookup the Serialized Array from the DB_CONFIG constants and unserialize it 
  • framework/QDatabaseBase.class.php

     
    7373                                case 'Database': 
    7474                                case 'Username': 
    7575                                case 'Password': 
     76                                case 'Schema': 
    7677                                        return $this->objConfigArray[strtolower($strName)]; 
    7778 
    7879                                default: