00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 if (!defined('ADODB_DIR')) die();
00016
00017 include_once(ADODB_DIR."/drivers/adodb-postgres64.inc.php");
00018
00019 class ADODB_postgres7 extends ADODB_postgres64 {
00020 var $databaseType = 'postgres7';
00021 var $hasLimit = true;
00022 var $ansiOuter = true;
00023 var $charSet = true;
00024
00025 function ADODB_postgres7()
00026 {
00027 $this->ADODB_postgres64();
00028 if (ADODB_ASSOC_CASE !== 2) {
00029 $this->rsPrefix .= 'assoc_';
00030 }
00031 $this->_bindInputArray = PHP_VERSION >= 5.1;
00032 }
00033
00034
00035
00036
00037 function &SelectLimit($sql,$nrows=-1,$offset=-1,$inputarr=false,$secs2cache=0)
00038 {
00039 $offsetStr = ($offset >= 0) ? " OFFSET ".((integer)$offset) : '';
00040 $limitStr = ($nrows >= 0) ? " LIMIT ".((integer)$nrows) : '';
00041 if ($secs2cache)
00042 $rs =& $this->CacheExecute($secs2cache,$sql."$limitStr$offsetStr",$inputarr);
00043 else
00044 $rs =& $this->Execute($sql."$limitStr$offsetStr",$inputarr);
00045
00046 return $rs;
00047 }
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060 function MetaForeignKeys($table, $owner=false, $upper=false)
00061 {
00062 $sql = 'SELECT t.tgargs as args
00063 FROM
00064 pg_trigger t,pg_class c,pg_proc p
00065 WHERE
00066 t.tgenabled AND
00067 t.tgrelid = c.oid AND
00068 t.tgfoid = p.oid AND
00069 p.proname = \'RI_FKey_check_ins\' AND
00070 c.relname = \''.strtolower($table).'\'
00071 ORDER BY
00072 t.tgrelid';
00073
00074 $rs =& $this->Execute($sql);
00075
00076 if ($rs && !$rs->EOF) {
00077 $arr =& $rs->GetArray();
00078 $a = array();
00079 foreach($arr as $v)
00080 {
00081 $data = explode(chr(0), $v['args']);
00082 if ($upper) {
00083 $a[strtoupper($data[2])][] = strtoupper($data[4].'='.$data[5]);
00084 } else {
00085 $a[$data[2]][] = $data[4].'='.$data[5];
00086 }
00087 }
00088 return $a;
00089 }
00090 return false;
00091 }
00092
00093 function _query($sql,$inputarr)
00094 {
00095 if (! $this->_bindInputArray) {
00096
00097 return ADODB_postgres64::_query($sql, $inputarr);
00098 }
00099
00100 if ($inputarr) {
00101 $sqlarr = explode('?',trim($sql));
00102 $sql = '';
00103 $i = 1;
00104 $last = sizeof($sqlarr)-1;
00105 foreach($sqlarr as $v) {
00106 if ($last < $i) $sql .= $v;
00107 else $sql .= $v.' $'.$i;
00108 $i++;
00109 }
00110
00111 $rez = pg_query_params($this->_connectionID,$sql, $inputarr);
00112 } else {
00113 $rez = pg_query($this->_connectionID,$sql);
00114 }
00115
00116 if ($rez && pg_numfields($rez) <= 0) {
00117 if (is_resource($this->_resultid) && get_resource_type($this->_resultid) === 'pgsql result') {
00118 pg_freeresult($this->_resultid);
00119 }
00120 $this->_resultid = $rez;
00121 return true;
00122 }
00123 return $rez;
00124 }
00125
00126
00127
00128
00129
00130
00131
00132
00133 function GetCharSet()
00134 {
00135
00136 $this->charSet = @pg_client_encoding($this->_connectionID);
00137 if (!$this->charSet) {
00138 return false;
00139 } else {
00140 return $this->charSet;
00141 }
00142 }
00143
00144
00145 function SetCharSet($charset_name)
00146 {
00147 $this->GetCharSet();
00148 if ($this->charSet !== $charset_name) {
00149 $if = pg_set_client_encoding($this->_connectionID, $charset_name);
00150 if ($if == "0" & $this->GetCharSet() == $charset_name) {
00151 return true;
00152 } else return false;
00153 } else return true;
00154 }
00155
00156 }
00157
00158
00159
00160
00161
00162 class ADORecordSet_postgres7 extends ADORecordSet_postgres64{
00163
00164 var $databaseType = "postgres7";
00165
00166
00167 function ADORecordSet_postgres7($queryID,$mode=false)
00168 {
00169 $this->ADORecordSet_postgres64($queryID,$mode);
00170 }
00171
00172
00173 function MoveNext()
00174 {
00175 if (!$this->EOF) {
00176 $this->_currentRow++;
00177 if ($this->_numOfRows < 0 || $this->_numOfRows > $this->_currentRow) {
00178 $this->fields = @pg_fetch_array($this->_queryID,$this->_currentRow,$this->fetchMode);
00179
00180 if (is_array($this->fields)) {
00181 if ($this->fields && isset($this->_blobArr)) $this->_fixblobs();
00182 return true;
00183 }
00184 }
00185 $this->fields = false;
00186 $this->EOF = true;
00187 }
00188 return false;
00189 }
00190
00191 }
00192
00193 class ADORecordSet_assoc_postgres7 extends ADORecordSet_postgres64{
00194
00195 var $databaseType = "postgres7";
00196
00197
00198 function ADORecordSet_assoc_postgres7($queryID,$mode=false)
00199 {
00200 $this->ADORecordSet_postgres64($queryID,$mode);
00201 }
00202
00203 function _fetch()
00204 {
00205 if ($this->_currentRow >= $this->_numOfRows && $this->_numOfRows >= 0)
00206 return false;
00207
00208 $this->fields = @pg_fetch_array($this->_queryID,$this->_currentRow,$this->fetchMode);
00209
00210 if ($this->fields) {
00211 if (isset($this->_blobArr)) $this->_fixblobs();
00212 $this->_updatefields();
00213 }
00214
00215 return (is_array($this->fields));
00216 }
00217
00218
00219 function _updatefields()
00220 {
00221 if (ADODB_ASSOC_CASE == 2) return;
00222
00223 $arr = array();
00224 $lowercase = (ADODB_ASSOC_CASE == 0);
00225
00226 foreach($this->fields as $k => $v) {
00227 if (is_integer($k)) $arr[$k] = $v;
00228 else {
00229 if ($lowercase)
00230 $arr[strtolower($k)] = $v;
00231 else
00232 $arr[strtoupper($k)] = $v;
00233 }
00234 }
00235 $this->fields = $arr;
00236 }
00237
00238 function MoveNext()
00239 {
00240 if (!$this->EOF) {
00241 $this->_currentRow++;
00242 if ($this->_numOfRows < 0 || $this->_numOfRows > $this->_currentRow) {
00243 $this->fields = @pg_fetch_array($this->_queryID,$this->_currentRow,$this->fetchMode);
00244
00245 if (is_array($this->fields)) {
00246 if ($this->fields) {
00247 if (isset($this->_blobArr)) $this->_fixblobs();
00248
00249 $this->_updatefields();
00250 }
00251 return true;
00252 }
00253 }
00254
00255
00256 $this->fields = false;
00257 $this->EOF = true;
00258 }
00259 return false;
00260 }
00261 }
00262 ?>