"Fossies" - the Fresh Open Source Software Archive

Member "phpESP/admin/include/lib/adodb/drivers/adodb-postgres7.inc.php" (5 Apr 2008, 7047 Bytes) of package /linux/www/old/phpESP-2.1.4.tgz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 <?php
    2 /*
    3  V4.98 13 Feb 2008  (c) 2000-2008 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.
    8   
    9   Postgres7 support.
   10   28 Feb 2001: Currently indicate that we support LIMIT
   11   01 Dec 2001: dannym added support for default values
   12 */
   13 
   14 // security - hide paths
   15 if (!defined('ADODB_DIR')) die();
   16 
   17 include_once(ADODB_DIR."/drivers/adodb-postgres64.inc.php");
   18 
   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
   24     
   25     function ADODB_postgres7() 
   26     {
   27         $this->ADODB_postgres64();
   28         if (ADODB_ASSOC_CASE !== 2) {
   29             $this->rsPrefix .= 'assoc_';
   30         }
   31         $this->_bindInputArray = PHP_VERSION >= 5.1;
   32     }
   33 
   34     
   35     // the following should be compat with postgresql 7.2, 
   36     // which makes obsolete the LIMIT limit,offset syntax
   37      function &SelectLimit($sql,$nrows=-1,$offset=-1,$inputarr=false,$secs2cache=0) 
   38      {
   39          $offsetStr = ($offset >= 0) ? " OFFSET ".((integer)$offset) : '';
   40          $limitStr  = ($nrows >= 0)  ? " LIMIT ".((integer)$nrows) : '';
   41          if ($secs2cache)
   42             $rs =& $this->CacheExecute($secs2cache,$sql."$limitStr$offsetStr",$inputarr);
   43          else
   44             $rs =& $this->Execute($sql."$limitStr$offsetStr",$inputarr);
   45         
   46         return $rs;
   47      }
   48     /*
   49     function Prepare($sql)
   50     {
   51         $info = $this->ServerInfo();
   52         if ($info['version']>=7.3) {
   53             return array($sql,false);
   54         }
   55         return $sql;
   56     }
   57     */
   58 
   59 
   60     // from  Edward Jaramilla, improved version - works on pg 7.4
   61     function MetaForeignKeys($table, $owner=false, $upper=false)
   62     {
   63         $sql = 'SELECT t.tgargs as args
   64         FROM
   65         pg_trigger t,pg_class c,pg_proc p
   66         WHERE
   67         t.tgenabled AND
   68         t.tgrelid = c.oid AND
   69         t.tgfoid = p.oid AND
   70         p.proname = \'RI_FKey_check_ins\' AND
   71         c.relname = \''.strtolower($table).'\'
   72         ORDER BY
   73             t.tgrelid';
   74         
   75         $rs =& $this->Execute($sql);
   76         
   77         if (!$rs || $rs->EOF) return false;
   78         
   79         $arr =& $rs->GetArray();
   80         $a = array();
   81         foreach($arr as $v) {
   82             $data = explode(chr(0), $v['args']);
   83             $size = count($data)-1; //-1 because the last node is empty
   84             for($i = 4; $i < $size; $i++) {
   85                 if ($upper) 
   86                     $a[strtoupper($data[2])][] = strtoupper($data[$i].'='.$data[++$i]);
   87                 else 
   88                     $a[$data[2]][] = $data[$i].'='.$data[++$i];
   89             }
   90         }
   91         return $a;
   92     }
   93 
   94     function _query($sql,$inputarr)
   95     {
   96         if (! $this->_bindInputArray) {
   97             // We don't have native support for parameterized queries, so let's emulate it at the parent
   98             return ADODB_postgres64::_query($sql, $inputarr);
   99         }
  100         $this->_errorMsg = false;
  101         // -- added Cristiano da Cunha Duarte
  102         if ($inputarr) {
  103             $sqlarr = explode('?',trim($sql));
  104             $sql = '';
  105             $i = 1;
  106             $last = sizeof($sqlarr)-1;
  107             foreach($sqlarr as $v) {
  108                 if ($last < $i) $sql .= $v;
  109                 else $sql .= $v.' $'.$i;
  110                 $i++;
  111             }
  112             
  113             $rez = pg_query_params($this->_connectionID,$sql, $inputarr);
  114         } else {
  115             $rez = pg_query($this->_connectionID,$sql);
  116         }
  117         // check if no data returned, then no need to create real recordset
  118         if ($rez && pg_numfields($rez) <= 0) {
  119             if (is_resource($this->_resultid) && get_resource_type($this->_resultid) === 'pgsql result') {
  120                 pg_freeresult($this->_resultid);
  121             }
  122             $this->_resultid = $rez;
  123             return true;
  124         }       
  125         return $rez;
  126     }
  127     
  128      // this is a set of functions for managing client encoding - very important if the encodings
  129     // of your database and your output target (i.e. HTML) don't match
  130     //for instance, you may have UNICODE database and server it on-site as WIN1251 etc.
  131     // GetCharSet - get the name of the character set the client is using now
  132     // the functions should work with Postgres 7.0 and above, the set of charsets supported
  133     // depends on compile flags of postgres distribution - if no charsets were compiled into the server
  134     // it will return 'SQL_ANSI' always
  135     function GetCharSet()
  136     {
  137         //we will use ADO's builtin property charSet
  138         $this->charSet = @pg_client_encoding($this->_connectionID);
  139         if (!$this->charSet) {
  140             return false;
  141         } else {
  142             return $this->charSet;
  143         }
  144     }
  145     
  146     // SetCharSet - switch the client encoding
  147     function SetCharSet($charset_name)
  148     {
  149         $this->GetCharSet();
  150         if ($this->charSet !== $charset_name) {
  151             $if = pg_set_client_encoding($this->_connectionID, $charset_name);
  152             if ($if == "0" & $this->GetCharSet() == $charset_name) {
  153                 return true;
  154             } else return false;
  155         } else return true;
  156     }
  157 
  158 }
  159     
  160 /*--------------------------------------------------------------------------------------
  161      Class Name: Recordset
  162 --------------------------------------------------------------------------------------*/
  163 
  164 class ADORecordSet_postgres7 extends ADORecordSet_postgres64{
  165 
  166     var $databaseType = "postgres7";
  167     
  168     
  169     function ADORecordSet_postgres7($queryID,$mode=false) 
  170     {
  171         $this->ADORecordSet_postgres64($queryID,$mode);
  172     }
  173     
  174         // 10% speedup to move MoveNext to child class
  175     function MoveNext() 
  176     {
  177         if (!$this->EOF) {
  178             $this->_currentRow++;
  179             if ($this->_numOfRows < 0 || $this->_numOfRows > $this->_currentRow) {
  180                 $this->fields = @pg_fetch_array($this->_queryID,$this->_currentRow,$this->fetchMode);
  181             
  182                 if (is_array($this->fields)) {
  183                     if ($this->fields && isset($this->_blobArr)) $this->_fixblobs();
  184                     return true;
  185                 }
  186             }
  187             $this->fields = false;
  188             $this->EOF = true;
  189         }
  190         return false;
  191     }       
  192 
  193 }
  194 
  195 class ADORecordSet_assoc_postgres7 extends ADORecordSet_postgres64{
  196 
  197     var $databaseType = "postgres7";
  198     
  199     
  200     function ADORecordSet_assoc_postgres7($queryID,$mode=false) 
  201     {
  202         $this->ADORecordSet_postgres64($queryID,$mode);
  203     }
  204     
  205     function _fetch()
  206     {
  207         if ($this->_currentRow >= $this->_numOfRows && $this->_numOfRows >= 0)
  208             return false;
  209 
  210         $this->fields = @pg_fetch_array($this->_queryID,$this->_currentRow,$this->fetchMode);
  211         
  212         if ($this->fields) {
  213             if (isset($this->_blobArr)) $this->_fixblobs();
  214             $this->_updatefields();
  215         }
  216             
  217         return (is_array($this->fields));
  218     }
  219     
  220         // Create associative array
  221     function _updatefields()
  222     {
  223         if (ADODB_ASSOC_CASE == 2) return; // native
  224     
  225         $arr = array();
  226         $lowercase = (ADODB_ASSOC_CASE == 0);
  227         
  228         foreach($this->fields as $k => $v) {
  229             if (is_integer($k)) $arr[$k] = $v;
  230             else {
  231                 if ($lowercase)
  232                     $arr[strtolower($k)] = $v;
  233                 else
  234                     $arr[strtoupper($k)] = $v;
  235             }
  236         }
  237         $this->fields = $arr;
  238     }
  239     
  240     function MoveNext() 
  241     {
  242         if (!$this->EOF) {
  243             $this->_currentRow++;
  244             if ($this->_numOfRows < 0 || $this->_numOfRows > $this->_currentRow) {
  245                 $this->fields = @pg_fetch_array($this->_queryID,$this->_currentRow,$this->fetchMode);
  246             
  247                 if (is_array($this->fields)) {
  248                     if ($this->fields) {
  249                         if (isset($this->_blobArr)) $this->_fixblobs();
  250                     
  251                         $this->_updatefields();
  252                     }
  253                     return true;
  254                 }
  255             }
  256             
  257             
  258             $this->fields = false;
  259             $this->EOF = true;
  260         }
  261         return false;
  262     }
  263 }
  264 ?>