Source for file postgresql.php

Documentation is available at postgresql.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Platform
  4.  * @subpackage  Database
  5.  *
  6.  * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
  7.  * @license     GNU General Public License version 2 or later; see LICENSE
  8.  */
  9.  
  10. defined('JPATH_PLATFORM'or die;
  11.  
  12. /**
  13.  * PostgreSQL export driver.
  14.  *
  15.  * @package     Joomla.Platform
  16.  * @subpackage  Database
  17.  * @since       12.1
  18.  */
  19. {
  20.     /**
  21.      * Builds the XML data for the tables to export.
  22.      *
  23.      * @return  string  An XML string
  24.      *
  25.      * @since   12.1
  26.      * @throws  Exception if an error occurs.
  27.      */
  28.     protected function buildXml()
  29.     {
  30.         $buffer array();
  31.  
  32.         $buffer['<?xml version="1.0"?>';
  33.         $buffer['<postgresqldump xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">';
  34.         $buffer[' <database name="">';
  35.  
  36.         $buffer array_merge($buffer$this->buildXmlStructure());
  37.  
  38.         $buffer[' </database>';
  39.         $buffer['</postgresqldump>';
  40.  
  41.         return implode("\n"$buffer);
  42.     }
  43.  
  44.     /**
  45.      * Builds the XML structure to export.
  46.      *
  47.      * @return  array  An array of XML lines (strings).
  48.      *
  49.      * @since   12.1
  50.      * @throws  Exception if an error occurs.
  51.      */
  52.     protected function buildXmlStructure()
  53.     {
  54.         $buffer array();
  55.  
  56.         foreach ($this->from as $table)
  57.         {
  58.             // Replace the magic prefix if found.
  59.             $table $this->getGenericTableName($table);
  60.  
  61.             // Get the details columns information.
  62.             $fields $this->db->getTableColumns($tablefalse);
  63.             $keys $this->db->getTableKeys($table);
  64.             $sequences $this->db->getTableSequences($table);
  65.  
  66.             $buffer['  <table_structure name="' $table '">';
  67.  
  68.             foreach ($sequences as $sequence)
  69.             {
  70.                 if (version_compare($this->db->getVersion()'9.1.0'0)
  71.                 {
  72.                     $sequence->start_value null;
  73.                 }
  74.  
  75.                 $buffer['   <sequence Name="' $sequence->sequence '"' ' Schema="' $sequence->schema '"' .
  76.                     ' Table="' $sequence->table '"' ' Column="' $sequence->column '"' ' Type="' $sequence->data_type '"' .
  77.                     ' Start_Value="' $sequence->start_value '"' ' Min_Value="' $sequence->minimum_value '"' .
  78.                     ' Max_Value="' $sequence->maximum_value '"' ' Increment="' $sequence->increment '"' .
  79.                     ' Cycle_option="' $sequence->cycle_option '"' .
  80.                     ' />';
  81.             }
  82.  
  83.             foreach ($fields as $field)
  84.             {
  85.                 $buffer['   <field Field="' $field->column_name '"' ' Type="' $field->type '"' ' Null="' $field->null '"' .
  86.                             (isset($field->default' Default="' $field->default '"' ''' Comments="' $field->comments '"' .
  87.                     ' />';
  88.             }
  89.  
  90.             foreach ($keys as $key)
  91.             {
  92.                 $buffer['   <key Index="' $key->idxName '"' ' is_primary="' $key->isPrimary '"' ' is_unique="' $key->isUnique '"' .
  93.                     ' Query="' $key->Query '" />';
  94.             }
  95.  
  96.             $buffer['  </table_structure>';
  97.         }
  98.  
  99.         return $buffer;
  100.     }
  101.  
  102.     /**
  103.      * Checks if all data and options are in order prior to exporting.
  104.      *
  105.      * @return  JDatabaseExporterPostgresql  Method supports chaining.
  106.      *
  107.      * @since   12.1
  108.      * @throws  Exception if an error is encountered.
  109.      */
  110.     public function check()
  111.     {
  112.         // Check if the db connector has been set.
  113.         if (!($this->db instanceof JDatabaseDriverPostgresql))
  114.         {
  115.             throw new Exception('JPLATFORM_ERROR_DATABASE_CONNECTOR_WRONG_TYPE');
  116.         }
  117.  
  118.         // Check if the tables have been specified.
  119.         if (empty($this->from))
  120.         {
  121.             throw new Exception('JPLATFORM_ERROR_NO_TABLES_SPECIFIED');
  122.         }
  123.  
  124.         return $this;
  125.     }
  126. }

Documentation generated on Tue, 19 Nov 2013 15:11:09 +0100 by phpDocumentor 1.4.3