Zikula 1.0.1
[ class tree: Zikula 1.0.1 ] [ index: Zikula 1.0.1 ] [ all elements ]

Source for file adodb-postgres7.inc.php

Documentation is available at adodb-postgres7.inc.php

  1. <?php
  2. /*
  3.  V4.97 22 Jan 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->EOFreturn 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.  
  165.     var $databaseType = "postgres7";
  166.     
  167.     
  168.     function ADORecordSet_postgres7($queryID,$mode=false
  169.     {
  170.         $this->ADORecordSet_postgres64($queryID,$mode);
  171.     }
  172.     
  173.          // 10% speedup to move MoveNext to child class
  174.     function MoveNext(
  175.     {
  176.         if (!$this->EOF{
  177.             $this->_currentRow++;
  178.             if ($this->_numOfRows < || $this->_numOfRows > $this->_currentRow{
  179.                 $this->fields = @pg_fetch_array($this->_queryID,$this->_currentRow,$this->fetchMode);
  180.             
  181.                 if (is_array($this->fields)) {
  182.                     if ($this->fields && isset($this->_blobArr)) $this->_fixblobs();
  183.                     return true;
  184.                 }
  185.             }
  186.             $this->fields = false;
  187.             $this->EOF = true;
  188.         }
  189.         return false;
  190.     }        
  191.  
  192. }
  193.  
  194.  
  195.     var $databaseType = "postgres7";
  196.     
  197.     
  198.     function ADORecordSet_assoc_postgres7($queryID,$mode=false
  199.     {
  200.         $this->ADORecordSet_postgres64($queryID,$mode);
  201.     }
  202.     
  203.     function _fetch()
  204.     {
  205.         if ($this->_currentRow >= $this->_numOfRows && $this->_numOfRows >= 0)
  206.             return false;
  207.  
  208.         $this->fields = @pg_fetch_array($this->_queryID,$this->_currentRow,$this->fetchMode);
  209.         
  210.         if ($this->fields{
  211.             if (isset($this->_blobArr)) $this->_fixblobs();
  212.             $this->_updatefields();
  213.         }
  214.             
  215.         return (is_array($this->fields));
  216.     }
  217.     
  218.         // Create associative array
  219.     function _updatefields()
  220.     {
  221.         if (ADODB_ASSOC_CASE == 2return// native
  222.     
  223.         $arr array();
  224.         $lowercase (ADODB_ASSOC_CASE == 0);
  225.         
  226.         foreach($this->fields as $k => $v{
  227.             if (is_integer($k)) $arr[$k$v;
  228.             else {
  229.                 if ($lowercase)
  230.                     $arr[strtolower($k)$v;
  231.                 else
  232.                     $arr[strtoupper($k)$v;
  233.             }
  234.         }
  235.         $this->fields = $arr;
  236.     }
  237.     
  238.     function MoveNext(
  239.     {
  240.         if (!$this->EOF{
  241.             $this->_currentRow++;
  242.             if ($this->_numOfRows < || $this->_numOfRows > $this->_currentRow{
  243.                 $this->fields = @pg_fetch_array($this->_queryID,$this->_currentRow,$this->fetchMode);
  244.             
  245.                 if (is_array($this->fields)) {
  246.                     if ($this->fields{
  247.                         if (isset($this->_blobArr)) $this->_fixblobs();
  248.                     
  249.                         $this->_updatefields();
  250.                     }
  251.                     return true;
  252.                 }
  253.             }
  254.             
  255.             
  256.             $this->fields = false;
  257.             $this->EOF = true;
  258.         }
  259.         return false;
  260.     }
  261. }
  262. ?>

Documentation generated on Fri, 18 Jul 2008 21:41:33 +0200 by phpDocumentor 1.4.1