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.
10 28 Feb 2001: Currently indicate that we support LIMIT
11 01 Dec 2001: dannym added support for default values
14 include_once(ADODB_DIR . "/drivers/adodb-postgres64.inc.php");
16 class ADODB_postgres7 extends ADODB_postgres64
18 var $databaseType = 'postgres7';
19 var $hasLimit = true; // set to true for pgsql 6.5+ only. support pgsql/mysql SELECT * FROM TABLE LIMIT 10
20 var $ansiOuter = true;
21 var $charSet = true; //set to true for Postgres 7 and above - PG client supports encodings
23 function ADODB_postgres7()
25 $this->ADODB_postgres64();
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)
32 $offsetStr = ($offset >= 0) ? " OFFSET $offset" : '';
33 $limitStr = ($nrows >= 0) ? " LIMIT $nrows" : '';
35 $rs =& $this->CacheExecute($secs2cache, $sql . "$limitStr$offsetStr", $inputarr);
37 $rs =& $this->Execute($sql . "$limitStr$offsetStr", $inputarr);
43 function Prepare($sql)
45 $info = $this->ServerInfo();
46 if ($info['version']>=7.3) {
47 return array($sql,false);
53 // from Edward Jaramilla, improved version - works on pg 7.4
54 function MetaForeignKeys($table, $owner = false, $upper = false)
56 $sql = 'SELECT t.tgargs as args
58 pg_trigger t,pg_class c,pg_proc p
63 p.proname = \'RI_FKey_check_ins\' AND
64 c.relname = \'' . strtolower($table) . '\'
68 $rs = $this->Execute($sql);
70 if ($rs && !$rs->EOF) {
71 $arr =& $rs->GetArray();
73 foreach ($arr as $v) {
74 $data = explode(chr(0), $v['args']);
76 $a[strtoupper($data[2])][] = strtoupper($data[4] . '=' . $data[5]);
78 $a[$data[2]][] = $data[4] . '=' . $data[5];
86 function xMetaForeignKeys($table, $owner = false, $upper = false)
90 SELECT t.tgargs as args
97 AND t.tgconstrrelid=c2.oid
99 AND f.proname ~ \'^RI_FKey_check_ins\'
100 AND t.tgargs like \'$1\\\000' . strtolower($table) . '%\'
103 $rs = $this->Execute($sql);
104 if ($rs && !$rs->EOF) {
105 $arr =& $rs->GetArray();
107 foreach ($arr as $v) {
108 $data = explode(chr(0), $v['args']);
110 $a[] = array(strtoupper($data[2]) => strtoupper($data[4] . '=' . $data[5]));
112 $a[] = array($data[2] => $data[4] . '=' . $data[5]);
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()
129 //we will use ADO's builtin property charSet
130 $this->charSet = @pg_client_encoding($this->_connectionID);
131 if (!$this->charSet) {
134 return $this->charSet;
138 // SetCharSet - switch the client encoding
139 function SetCharSet($charset_name)
142 if ($this->charSet !== $charset_name) {
143 $if = pg_set_client_encoding($this->_connectionID, $charset_name);
144 if ($if == "0" & $this->GetCharSet() == $charset_name) {
152 /*--------------------------------------------------------------------------------------
153 Class Name: Recordset
154 --------------------------------------------------------------------------------------*/
156 class ADORecordSet_postgres7 extends ADORecordSet_postgres64
159 var $databaseType = "postgres7";
161 function ADORecordSet_postgres7($queryID, $mode = false)
163 $this->ADORecordSet_postgres64($queryID, $mode);
166 // 10% speedup to move MoveNext to child class
170 $this->_currentRow++;
171 if ($this->_numOfRows < 0 || $this->_numOfRows > $this->_currentRow) {
172 $this->fields = @pg_fetch_array($this->_queryID, $this->_currentRow, $this->fetchMode);
174 if (is_array($this->fields)) {
175 if ($this->fields && isset($this->_blobArr)) $this->_fixblobs();
179 $this->fields = false;