Added back the notab style formatting for the patient summary screen
[openemr.git] / gacl / adodb / drivers / adodb-postgres7.inc.php
blob6856a6612aa3e3c1e184fea53cbd9608c0738c8a
1 <?php
2 /*
3 V4.92a 29 Aug 2006 (c) 2000-2006 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.
9 Postgres7 support.
10 28 Feb 2001: Currently indicate that we support LIMIT
11 01 Dec 2001: dannym added support for default values
14 // security - hide paths
15 if (!defined('ADODB_DIR')) die();
17 include_once(ADODB_DIR."/drivers/adodb-postgres64.inc.php");
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
25 function ADODB_postgres7()
27 $this->ADODB_postgres64();
28 if (ADODB_ASSOC_CASE !== 2) {
29 $this->rsPrefix .= 'assoc_';
31 $this->_bindInputArray = PHP_VERSION >= 5.1;
33 $info = $this->ServerInfo();
34 $this->pgVersion = (float) substr($info['version'],0,3);
35 if ($this->pgVersion >= 7.1) { // good till version 999
36 $this->_nestedSQL = true;
41 // the following should be compat with postgresql 7.2,
42 // which makes obsolete the LIMIT limit,offset syntax
43 function &SelectLimit($sql,$nrows=-1,$offset=-1,$inputarr=false,$secs2cache=0)
45 $offsetStr = ($offset >= 0) ? " OFFSET ".((integer)$offset) : '';
46 $limitStr = ($nrows >= 0) ? " LIMIT ".((integer)$nrows) : '';
47 if ($secs2cache)
48 $rs =& $this->CacheExecute($secs2cache,$sql."$limitStr$offsetStr",$inputarr);
49 else
50 $rs =& $this->Execute($sql."$limitStr$offsetStr",$inputarr);
52 return $rs;
55 function Prepare($sql)
57 $info = $this->ServerInfo();
58 if ($info['version']>=7.3) {
59 return array($sql,false);
61 return $sql;
66 // from Edward Jaramilla, improved version - works on pg 7.4
67 function MetaForeignKeys($table, $owner=false, $upper=false)
69 $sql = 'SELECT t.tgargs as args
70 FROM
71 pg_trigger t,pg_class c,pg_proc p
72 WHERE
73 t.tgenabled AND
74 t.tgrelid = c.oid AND
75 t.tgfoid = p.oid AND
76 p.proname = \'RI_FKey_check_ins\' AND
77 c.relname = \''.strtolower($table).'\'
78 ORDER BY
79 t.tgrelid';
81 $rs =& $this->Execute($sql);
83 if (!$rs || $rs->EOF) return false;
85 $arr =& $rs->GetArray();
86 $a = array();
87 foreach($arr as $v) {
88 $data = explode(chr(0), $v['args']);
89 $size = count($data)-1; //-1 because the last node is empty
90 for($i = 4; $i < $size; $i++) {
91 if ($upper)
92 $a[strtoupper($data[2])][] = strtoupper($data[$i].'='.$data[++$i]);
93 else
94 $a[$data[2]][] = $data[$i].'='.$data[++$i];
97 return $a;
100 function _query($sql,$inputarr)
102 if (! $this->_bindInputArray) {
103 // We don't have native support for parameterized queries, so let's emulate it at the parent
104 return ADODB_postgres64::_query($sql, $inputarr);
106 $this->_errorMsg = false;
107 // -- added Cristiano da Cunha Duarte
108 if ($inputarr) {
109 $sqlarr = explode('?',trim($sql));
110 $sql = '';
111 $i = 1;
112 $last = sizeof($sqlarr)-1;
113 foreach($sqlarr as $v) {
114 if ($last < $i) $sql .= $v;
115 else $sql .= $v.' $'.$i;
116 $i++;
119 $rez = pg_query_params($this->_connectionID,$sql, $inputarr);
120 } else {
121 $rez = pg_query($this->_connectionID,$sql);
123 // check if no data returned, then no need to create real recordset
124 if ($rez && pg_numfields($rez) <= 0) {
125 if (is_resource($this->_resultid) && get_resource_type($this->_resultid) === 'pgsql result') {
126 pg_freeresult($this->_resultid);
128 $this->_resultid = $rez;
129 return true;
131 return $rez;
134 // this is a set of functions for managing client encoding - very important if the encodings
135 // of your database and your output target (i.e. HTML) don't match
136 //for instance, you may have UNICODE database and server it on-site as WIN1251 etc.
137 // GetCharSet - get the name of the character set the client is using now
138 // the functions should work with Postgres 7.0 and above, the set of charsets supported
139 // depends on compile flags of postgres distribution - if no charsets were compiled into the server
140 // it will return 'SQL_ANSI' always
141 function GetCharSet()
143 //we will use ADO's builtin property charSet
144 $this->charSet = @pg_client_encoding($this->_connectionID);
145 if (!$this->charSet) {
146 return false;
147 } else {
148 return $this->charSet;
152 // SetCharSet - switch the client encoding
153 function SetCharSet($charset_name)
155 $this->GetCharSet();
156 if ($this->charSet !== $charset_name) {
157 $if = pg_set_client_encoding($this->_connectionID, $charset_name);
158 if ($if == "0" & $this->GetCharSet() == $charset_name) {
159 return true;
160 } else return false;
161 } else return true;
166 /*--------------------------------------------------------------------------------------
167 Class Name: Recordset
168 --------------------------------------------------------------------------------------*/
170 class ADORecordSet_postgres7 extends ADORecordSet_postgres64{
172 var $databaseType = "postgres7";
175 function ADORecordSet_postgres7($queryID,$mode=false)
177 $this->ADORecordSet_postgres64($queryID,$mode);
180 // 10% speedup to move MoveNext to child class
181 function MoveNext()
183 if (!$this->EOF) {
184 $this->_currentRow++;
185 if ($this->_numOfRows < 0 || $this->_numOfRows > $this->_currentRow) {
186 $this->fields = @pg_fetch_array($this->_queryID,$this->_currentRow,$this->fetchMode);
188 if (is_array($this->fields)) {
189 if ($this->fields && isset($this->_blobArr)) $this->_fixblobs();
190 return true;
193 $this->fields = false;
194 $this->EOF = true;
196 return false;
201 class ADORecordSet_assoc_postgres7 extends ADORecordSet_postgres64{
203 var $databaseType = "postgres7";
206 function ADORecordSet_assoc_postgres7($queryID,$mode=false)
208 $this->ADORecordSet_postgres64($queryID,$mode);
211 function _fetch()
213 if ($this->_currentRow >= $this->_numOfRows && $this->_numOfRows >= 0)
214 return false;
216 $this->fields = @pg_fetch_array($this->_queryID,$this->_currentRow,$this->fetchMode);
218 if ($this->fields) {
219 if (isset($this->_blobArr)) $this->_fixblobs();
220 $this->_updatefields();
223 return (is_array($this->fields));
226 // Create associative array
227 function _updatefields()
229 if (ADODB_ASSOC_CASE == 2) return; // native
231 $arr = array();
232 $lowercase = (ADODB_ASSOC_CASE == 0);
234 foreach($this->fields as $k => $v) {
235 if (is_integer($k)) $arr[$k] = $v;
236 else {
237 if ($lowercase)
238 $arr[strtolower($k)] = $v;
239 else
240 $arr[strtoupper($k)] = $v;
243 $this->fields = $arr;
246 function MoveNext()
248 if (!$this->EOF) {
249 $this->_currentRow++;
250 if ($this->_numOfRows < 0 || $this->_numOfRows > $this->_currentRow) {
251 $this->fields = @pg_fetch_array($this->_queryID,$this->_currentRow,$this->fetchMode);
253 if (is_array($this->fields)) {
254 if ($this->fields) {
255 if (isset($this->_blobArr)) $this->_fixblobs();
257 $this->_updatefields();
259 return true;
264 $this->fields = false;
265 $this->EOF = true;
267 return false;