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