Documentation TYPO3 par Ameos

adodb-postgres7.inc.php

00001 <?php
00002 /*
00003  V4.93 10 Oct 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 
00060         // from  Edward Jaramilla, improved version - works on pg 7.4
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; //-1 because the last node is empty
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                         // We don't have native support for parameterized queries, so let's emulate it at the parent
00098                         return ADODB_postgres64::_query($sql, $inputarr);
00099                 }
00100                 $this->_errorMsg = false;
00101                 // -- added Cristiano da Cunha Duarte
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                 // check if no data returned, then no need to create real recordset
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          // this is a set of functions for managing client encoding - very important if the encodings
00129         // of your database and your output target (i.e. HTML) don't match
00130         //for instance, you may have UNICODE database and server it on-site as WIN1251 etc.
00131         // GetCharSet - get the name of the character set the client is using now
00132         // the functions should work with Postgres 7.0 and above, the set of charsets supported
00133         // depends on compile flags of postgres distribution - if no charsets were compiled into the server
00134         // it will return 'SQL_ANSI' always
00135         function GetCharSet()
00136         {
00137                 //we will use ADO's builtin property charSet
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         // SetCharSet - switch the client encoding
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          Class Name: Recordset
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                 // 10% speedup to move MoveNext to child class
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                 // Create associative array
00221         function _updatefields()
00222         {
00223                 if (ADODB_ASSOC_CASE == 2) return; // native
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 ?>


Généré par Les spécialistes TYPO3 avec  doxygen 1.4.6