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