]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/WikiDB/adodb/drivers/adodb-postgres7.inc.php
No newline at end of file
[SourceForge/phpwiki.git] / lib / WikiDB / adodb / drivers / adodb-postgres7.inc.php
1 <?php
2 /*
3  V4.22 15 Apr 2004  (c) 2000-2004 John Lim (jlim@natsoft.com.my). All rights reserved.
4   Released under both BSD license and Lesser GPL library license.
5   Whenever there is any discrepancy between the two licenses,
6   the BSD license will take precedence.
7   Set tabs to 4.
8
9   Postgres7 support.
10   28 Feb 2001: Currently indicate that we support LIMIT
11   01 Dec 2001: dannym added support for default values
12 */
13
14 include_once(ADODB_DIR."/drivers/adodb-postgres64.inc.php");
15
16 class ADODB_postgres7 extends ADODB_postgres64 {
17     var $databaseType = 'postgres7';
18     var $hasLimit = true;       // set to true for pgsql 6.5+ only. support pgsql/mysql SELECT * FROM TABLE LIMIT 10
19     var $ansiOuter = true;
20     var $charSet = true; //set to true for Postgres 7 and above - PG client supports encodings
21
22     function ADODB_postgres7()
23     {
24         $this->ADODB_postgres64();
25     }
26
27
28     // the following should be compat with postgresql 7.2,
29     // which makes obsolete the LIMIT limit,offset syntax
30      function &SelectLimit($sql,$nrows=-1,$offset=-1,$inputarr=false,$secs2cache=0)
31      {
32          $offsetStr = ($offset >= 0) ? " OFFSET $offset" : '';
33          $limitStr  = ($nrows >= 0)  ? " LIMIT $nrows" : '';
34          if ($secs2cache)
35               $rs =& $this->CacheExecute($secs2cache,$sql."$limitStr$offsetStr",$inputarr);
36          else
37               $rs =& $this->Execute($sql."$limitStr$offsetStr",$inputarr);
38
39         return $rs;
40      }
41      /*
42      function Prepare($sql)
43     {
44         $info = $this->ServerInfo();
45         if ($info['version']>=7.3) {
46             return array($sql,false);
47         }
48         return $sql;
49     }
50      */
51
52     // from  Edward Jaramilla, improved version - works on pg 7.4
53 function MetaForeignKeys($table, $owner=false, $upper=false)
54 {
55     $sql = 'SELECT t.tgargs as args
56     FROM
57     pg_trigger t,pg_class c,pg_proc p
58     WHERE
59     t.tgenabled AND
60     t.tgrelid = c.oid AND
61     t.tgfoid = p.oid AND
62     p.proname = \'RI_FKey_check_ins\' AND
63     c.relname = \''.strtolower($table).'\'
64     ORDER BY
65         t.tgrelid';
66
67     $rs = $this->Execute($sql);
68
69     if ($rs && !$rs->EOF) {
70         $arr =& $rs->GetArray();
71         $a = array();
72         foreach($arr as $v)
73         {
74             $data = explode(chr(0), $v['args']);
75             if ($upper) {
76                 $a[strtoupper($data[2])][] = strtoupper($data[4].'='.$data[5]);
77             } else {
78             $a[$data[2]][] = $data[4].'='.$data[5];
79             }
80         }
81         return $a;
82     }
83     return false;
84 }
85
86
87
88     function xMetaForeignKeys($table, $owner=false, $upper=false)
89     {
90
91         $sql = '
92 SELECT t.tgargs as args
93    FROM pg_trigger t,
94         pg_class c,
95         pg_class c2,
96         pg_proc f
97    WHERE t.tgenabled
98    AND t.tgrelid=c.oid
99    AND t.tgconstrrelid=c2.oid
100    AND t.tgfoid=f.oid
101    AND f.proname ~ \'^RI_FKey_check_ins\'
102    AND t.tgargs like \'$1\\\000'.strtolower($table).'%\'
103    ORDER BY t.tgrelid';
104
105         $rs = $this->Execute($sql);
106         if ($rs && !$rs->EOF) {
107             $arr =& $rs->GetArray();
108             $a = array();
109             foreach($arr as $v) {
110                 $data = explode(chr(0), $v['args']);
111                 if ($upper) {
112                     $a[] = array(strtoupper($data[2]) => strtoupper($data[4].'='.$data[5]));
113                 } else {
114                     $a[] = array($data[2] => $data[4].'='.$data[5]);
115                 }
116
117             }
118             return $a;
119         }
120         else return false;
121     }
122
123       // this is a set of functions for managing client encoding - very important if the encodings
124     // of your database and your output target (i.e. HTML) don't match
125     //for instance, you may have UNICODE database and server it on-site as WIN1251 etc.
126     // GetCharSet - get the name of the character set the client is using now
127     // the functions should work with Postgres 7.0 and above, the set of charsets supported
128     // depends on compile flags of postgres distribution - if no charsets were compiled into the server
129     // it will return 'SQL_ANSI' always
130     function GetCharSet()
131     {
132         //we will use ADO's builtin property charSet
133         $this->charSet = @pg_client_encoding($this->_connectionID);
134         if (!$this->charSet) {
135             return false;
136         } else {
137             return $this->charSet;
138         }
139     }
140
141     // SetCharSet - switch the client encoding
142     function SetCharSet($charset_name)
143     {
144         $this->GetCharSet();
145         if ($this->charSet !== $charset_name) {
146             $if = pg_set_client_encoding($this->_connectionID, $charset_name);
147             if ($if == "0" & $this->GetCharSet() == $charset_name) {
148                 return true;
149             } else return false;
150         } else return true;
151     }
152
153 }
154
155 /*--------------------------------------------------------------------------------------
156      Class Name: Recordset
157 --------------------------------------------------------------------------------------*/
158
159 class ADORecordSet_postgres7 extends ADORecordSet_postgres64{
160
161     var $databaseType = "postgres7";
162
163
164     function ADORecordSet_postgres7($queryID,$mode=false)
165     {
166         $this->ADORecordSet_postgres64($queryID,$mode);
167     }
168
169          // 10% speedup to move MoveNext to child class
170     function MoveNext()
171     {
172         if (!$this->EOF) {
173             $this->_currentRow++;
174             if ($this->_numOfRows < 0 || $this->_numOfRows > $this->_currentRow) {
175                 $this->fields = @pg_fetch_array($this->_queryID,$this->_currentRow,$this->fetchMode);
176
177                 if (is_array($this->fields)) {
178                     if ($this->fields && isset($this->_blobArr)) $this->_fixblobs();
179                     return true;
180                 }
181             }
182             $this->fields = false;
183             $this->EOF = true;
184         }
185         return false;
186     }
187
188 }
189 ?>