1 <?php
2 3 4 5 6 7 8
9
10 defined('JPATH_PLATFORM') or die;
11
12 13 14 15 16 17 18
19 class JDatabaseExporterPostgresql extends JDatabaseExporter
20 {
21 22 23 24 25 26 27 28
29 protected function buildXml()
30 {
31 $buffer = array();
32
33 $buffer[] = '<?xml version="1.0"?>';
34 $buffer[] = '<postgresqldump xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">';
35 $buffer[] = ' <database name="">';
36
37 $buffer = array_merge($buffer, $this->buildXmlStructure());
38
39 $buffer[] = ' </database>';
40 $buffer[] = '</postgresqldump>';
41
42 return implode("\n", $buffer);
43 }
44
45 46 47 48 49 50 51 52
53 protected function buildXmlStructure()
54 {
55 $buffer = array();
56
57 foreach ($this->from as $table)
58 {
59
60 $table = $this->getGenericTableName($table);
61
62
63 $fields = $this->db->getTableColumns($table, false);
64 $keys = $this->db->getTableKeys($table);
65 $sequences = $this->db->getTableSequences($table);
66
67 $buffer[] = ' <table_structure name="' . $table . '">';
68
69 foreach ($sequences as $sequence)
70 {
71 if (version_compare($this->db->getVersion(), '9.1.0') < 0)
72 {
73 $sequence->start_value = null;
74 }
75
76 $buffer[] = ' <sequence Name="' . $sequence->sequence . '"' . ' Schema="' . $sequence->schema . '"' .
77 ' Table="' . $sequence->table . '"' . ' Column="' . $sequence->column . '"' . ' Type="' . $sequence->data_type . '"' .
78 ' Start_Value="' . $sequence->start_value . '"' . ' Min_Value="' . $sequence->minimum_value . '"' .
79 ' Max_Value="' . $sequence->maximum_value . '"' . ' Increment="' . $sequence->increment . '"' .
80 ' Cycle_option="' . $sequence->cycle_option . '"' .
81 ' />';
82 }
83
84 foreach ($fields as $field)
85 {
86 $buffer[] = ' <field Field="' . $field->column_name . '"' . ' Type="' . $field->type . '"' . ' Null="' . $field->null . '"' .
87 (isset($field->default) ? ' Default="' . $field->default . '"' : '') . ' Comments="' . $field->comments . '"' .
88 ' />';
89 }
90
91 foreach ($keys as $key)
92 {
93 $buffer[] = ' <key Index="' . $key->idxName . '"' . ' is_primary="' . $key->isPrimary . '"' . ' is_unique="' . $key->isUnique . '"' .
94 ' Query="' . $key->Query . '" />';
95 }
96
97 $buffer[] = ' </table_structure>';
98 }
99
100 return $buffer;
101 }
102
103 104 105 106 107 108 109 110
111 public function check()
112 {
113
114 if (!($this->db instanceof JDatabaseDriverPostgresql))
115 {
116 throw new Exception('JPLATFORM_ERROR_DATABASE_CONNECTOR_WRONG_TYPE');
117 }
118
119
120 if (empty($this->from))
121 {
122 throw new Exception('JPLATFORM_ERROR_NO_TABLES_SPECIFIED');
123 }
124
125 return $this;
126 }
127 }
128