Documentation TYPO3 par Ameos

adodb-postgres7.inc.php

00001 <?php
00002 /*
00003  V4.80 8 Mar 2006  (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
00004   Released under both BSD license and Lesser GPL library license. 
00005   Whenever there is any discrepancy between the two licenses, 
00006   the BSD license will take precedence.
00007   Set tabs to 4.
00008   
00009   Postgres7 support.
00010   28 Feb 2001: Currently indicate that we support LIMIT
00011   01 Dec 2001: dannym added support for default values
00012 */
00013 
00014 // security - hide paths
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;   // set to true for pgsql 6.5+ only. support pgsql/mysql SELECT * FROM TABLE LIMIT 10
00022         var $ansiOuter = true;
00023         var $charSet = true; //set to true for Postgres 7 and above - PG client supports encodings
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         // the following should be compat with postgresql 7.2, 
00036         // which makes obsolete the LIMIT limit,offset syntax
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         function Prepare($sql)
00050         {
00051                 $info = $this->ServerInfo();
00052                 if ($info['version']>=7.3) {
00053                         return array($sql,false);
00054                 }
00055                 return $sql;
00056         }
00057         */
00058 
00059         // from  Edward Jaramilla, improved version - works on pg 7.4
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                         // We don't have native support for parameterized queries, so let's emulate it at the parent
00097                         return ADODB_postgres64::_query($sql, $inputarr);
00098                 }
00099                 // -- added Cristiano da Cunha Duarte
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                 // check if no data returned, then no need to create real recordset
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          // this is a set of functions for managing client encoding - very important if the encodings
00127         // of your database and your output target (i.e. HTML) don't match
00128         //for instance, you may have UNICODE database and server it on-site as WIN1251 etc.
00129         // GetCharSet - get the name of the character set the client is using now
00130         // the functions should work with Postgres 7.0 and above, the set of charsets supported
00131         // depends on compile flags of postgres distribution - if no charsets were compiled into the server
00132         // it will return 'SQL_ANSI' always
00133         function GetCharSet()
00134         {
00135                 //we will use ADO's builtin property charSet
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         // SetCharSet - switch the client encoding
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          Class Name: Recordset
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                 // 10% speedup to move MoveNext to child class
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                 // Create associative array
00219         function _updatefields()
00220         {
00221                 if (ADODB_ASSOC_CASE == 2) return; // native
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 ?>


Généré par Le spécialiste TYPO3 avec  doxygen 1.4.6