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
00061 function MetaForeignKeys($table, $owner=false, $upper=false)
00062 {
00063 $sql = 'SELECT t.tgargs as args
00064 FROM
00065 pg_trigger t,pg_class c,pg_proc p
00066 WHERE
00067 t.tgenabled AND
00068 t.tgrelid = c.oid AND
00069 t.tgfoid = p.oid AND
00070 p.proname = \'RI_FKey_check_ins\' AND
00071 c.relname = \''.strtolower($table).'\'
00072 ORDER BY
00073 t.tgrelid';
00074
00075 $rs =& $this->Execute($sql);
00076
00077 if (!$rs || $rs->EOF) return false;
00078
00079 $arr =& $rs->GetArray();
00080 $a = array();
00081 foreach($arr as $v) {
00082 $data = explode(chr(0), $v['args']);
00083 $size = count($data)-1;
00084 for($i = 4; $i < $size; $i++) {
00085 if ($upper)
00086 $a[strtoupper($data[2])][] = strtoupper($data[$i].'='.$data[++$i]);
00087 else
00088 $a[$data[2]][] = $data[$i].'='.$data[++$i];
00089 }
00090 }
00091 return $a;
00092 }
00093
00094 function _query($sql,$inputarr)
00095 {
00096 if (! $this->_bindInputArray) {
00097
00098 return ADODB_postgres64::_query($sql, $inputarr);
00099 }
00100 $this->_errorMsg = false;
00101
00102 if ($inputarr) {
00103 $sqlarr = explode('?',trim($sql));
00104 $sql = '';
00105 $i = 1;
00106 $last = sizeof($sqlarr)-1;
00107 foreach($sqlarr as $v) {
00108 if ($last < $i) $sql .= $v;
00109 else $sql .= $v.' $'.$i;
00110 $i++;
00111 }
00112
00113 $rez = pg_query_params($this->_connectionID,$sql, $inputarr);
00114 } else {
00115 $rez = pg_query($this->_connectionID,$sql);
00116 }
00117
00118 if ($rez && pg_numfields($rez) <= 0) {
00119 if (is_resource($this->_resultid) && get_resource_type($this->_resultid) === 'pgsql result') {
00120 pg_freeresult($this->_resultid);
00121 }
00122 $this->_resultid = $rez;
00123 return true;
00124 }
00125 return $rez;
00126 }
00127
00128
00129
00130
00131
00132
00133
00134
00135 function GetCharSet()
00136 {
00137
00138 $this->charSet = @pg_client_encoding($this->_connectionID);
00139 if (!$this->charSet) {
00140 return false;
00141 } else {
00142 return $this->charSet;
00143 }
00144 }
00145
00146
00147 function SetCharSet($charset_name)
00148 {
00149 $this->GetCharSet();
00150 if ($this->charSet !== $charset_name) {
00151 $if = pg_set_client_encoding($this->_connectionID, $charset_name);
00152 if ($if == "0" & $this->GetCharSet() == $charset_name) {
00153 return true;
00154 } else return false;
00155 } else return true;
00156 }
00157
00158 }
00159
00160
00161
00162
00163
00164 class ADORecordSet_postgres7 extends ADORecordSet_postgres64{
00165
00166 var $databaseType = "postgres7";
00167
00168
00169 function ADORecordSet_postgres7($queryID,$mode=false)
00170 {
00171 $this->ADORecordSet_postgres64($queryID,$mode);
00172 }
00173
00174
00175 function MoveNext()
00176 {
00177 if (!$this->EOF) {
00178 $this->_currentRow++;
00179 if ($this->_numOfRows < 0 || $this->_numOfRows > $this->_currentRow) {
00180 $this->fields = @pg_fetch_array($this->_queryID,$this->_currentRow,$this->fetchMode);
00181
00182 if (is_array($this->fields)) {
00183 if ($this->fields && isset($this->_blobArr)) $this->_fixblobs();
00184 return true;
00185 }
00186 }
00187 $this->fields = false;
00188 $this->EOF = true;
00189 }
00190 return false;
00191 }
00192
00193 }
00194
00195 class ADORecordSet_assoc_postgres7 extends ADORecordSet_postgres64{
00196
00197 var $databaseType = "postgres7";
00198
00199
00200 function ADORecordSet_assoc_postgres7($queryID,$mode=false)
00201 {
00202 $this->ADORecordSet_postgres64($queryID,$mode);
00203 }
00204
00205 function _fetch()
00206 {
00207 if ($this->_currentRow >= $this->_numOfRows && $this->_numOfRows >= 0)
00208 return false;
00209
00210 $this->fields = @pg_fetch_array($this->_queryID,$this->_currentRow,$this->fetchMode);
00211
00212 if ($this->fields) {
00213 if (isset($this->_blobArr)) $this->_fixblobs();
00214 $this->_updatefields();
00215 }
00216
00217 return (is_array($this->fields));
00218 }
00219
00220
00221 function _updatefields()
00222 {
00223 if (ADODB_ASSOC_CASE == 2) return;
00224
00225 $arr = array();
00226 $lowercase = (ADODB_ASSOC_CASE == 0);
00227
00228 foreach($this->fields as $k => $v) {
00229 if (is_integer($k)) $arr[$k] = $v;
00230 else {
00231 if ($lowercase)
00232 $arr[strtolower($k)] = $v;
00233 else
00234 $arr[strtoupper($k)] = $v;
00235 }
00236 }
00237 $this->fields = $arr;
00238 }
00239
00240 function MoveNext()
00241 {
00242 if (!$this->EOF) {
00243 $this->_currentRow++;
00244 if ($this->_numOfRows < 0 || $this->_numOfRows > $this->_currentRow) {
00245 $this->fields = @pg_fetch_array($this->_queryID,$this->_currentRow,$this->fetchMode);
00246
00247 if (is_array($this->fields)) {
00248 if ($this->fields) {
00249 if (isset($this->_blobArr)) $this->_fixblobs();
00250
00251 $this->_updatefields();
00252 }
00253 return true;
00254 }
00255 }
00256
00257
00258 $this->fields = false;
00259 $this->EOF = true;
00260 }
00261 return false;
00262 }
00263 }
00264 ?>