Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.2.x will end 22 April 2024 (12 months).
  • Bug fixes for security issues in 4.2.x will end 7 October 2024 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.1.x is supported too.

Differences Between: [Versions 310 and 402] [Versions 311 and 402] [Versions 39 and 402]

   1  <?php
   2  /**
   3   * Netezza Driver
   4   *
   5   * @link https://www.ibm.com/products/netezza
   6   * Based on the previous postgres drivers. Major Additions/Changes:
   7   * - MetaDatabasesSQL, MetaTablesSQL, MetaColumnsSQL
   8   *   Note: You have to have admin privileges to access the system tables
   9   * - Removed non-working keys code (Netezza has no concept of keys)
  10   * - Fixed the way data types and lengths are returned in MetaColumns()
  11   *   as well as added the default lengths for certain types
  12   * - Updated public variables for Netezza
  13   * TODO: Still need to remove blob functions, as Netezza doesn't support blob
  14   *
  15   * This file is part of ADOdb, a Database Abstraction Layer library for PHP.
  16   *
  17   * @package ADOdb
  18   * @link https://adodb.org Project's web site and documentation
  19   * @link https://github.com/ADOdb/ADOdb Source code and issue tracker
  20   *
  21   * The ADOdb Library is dual-licensed, released under both the BSD 3-Clause
  22   * and the GNU Lesser General Public Licence (LGPL) v2.1 or, at your option,
  23   * any later version. This means you can use it in proprietary products.
  24   * See the LICENSE.md file distributed with this source code for details.
  25   * @license BSD-3-Clause
  26   * @license LGPL-2.1-or-later
  27   *
  28   * @copyright 2000-2013 John Lim
  29   * @copyright 2014 Damien Regad, Mark Newnham and the ADOdb community
  30   * @author Josh Eldridge <joshuae74@hotmail.com>
  31   */
  32  
  33  // security - hide paths
  34  if (!defined('ADODB_DIR')) die();
  35  
  36  include_once(ADODB_DIR.'/drivers/adodb-postgres64.inc.php');
  37  
  38  class ADODB_netezza extends ADODB_postgres64 {
  39      var $databaseType = 'netezza';
  40  	 var $dataProvider = 'netezza';
  41  	 var $hasInsertID = false;
  42  	 var $_resultid = false;
  43    	 var $concat_operator='||';
  44    	 var $random = 'random';
  45  	 var $metaDatabasesSQL = "select objname from _v_object_data where objtype='database' order by 1";
  46      var $metaTablesSQL = "select objname from _v_object_data where objtype='table' order by 1";
  47  	 var $isoDates = true; // accepts dates in ISO format
  48  	 var $sysDate = "CURRENT_DATE";
  49  	 var $sysTimeStamp = "CURRENT_TIMESTAMP";
  50  	 var $blobEncodeType = 'C';
  51  	 var $metaColumnsSQL = "SELECT attname, atttype FROM _v_relation_column_def WHERE name = '%s' AND attnum > 0 ORDER BY attnum";
  52  	 var $metaColumnsSQL1 = "SELECT attname, atttype FROM _v_relation_column_def WHERE name = '%s' AND attnum > 0 ORDER BY attnum";
  53  	 // netezza doesn't have keys. it does have distributions, so maybe this is
  54  	 // something that can be pulled from the system tables
  55  	 var $metaKeySQL = "";
  56  	 var $hasAffectedRows = true;
  57  	 var $hasLimit = true;
  58  	 var $true = 't';	 	 // string that represents TRUE for a database
  59  	 var $false = 'f';	 	 // string that represents FALSE for a database
  60  	 var $fmtDate = "'Y-m-d'";	 // used by DBDate() as the default date format used by the database
  61  	 var $fmtTimeStamp = "'Y-m-d G:i:s'"; // used by DBTimeStamp as the default timestamp fmt.
  62  	 var $ansiOuter = true;
  63  	 var $autoRollback = true; // apparently pgsql does not autorollback properly before 4.3.4
  64  	 	 	 	 	 	 	 // http://bugs.php.net/bug.php?id=25404
  65  
  66  
  67  	function MetaColumns($table,$upper=true)
  68  	 {
  69  
  70  	 // Changed this function to support Netezza which has no concept of keys
  71  	 // could posisbly work on other things from the system table later.
  72  
  73  	 global $ADODB_FETCH_MODE;
  74  
  75  	 	 $table = strtolower($table);
  76  
  77  	 	 $save = $ADODB_FETCH_MODE;
  78  	 	 $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
  79  	 	 if ($this->fetchMode !== false) $savem = $this->SetFetchMode(false);
  80  
  81  	 	 $rs = $this->Execute(sprintf($this->metaColumnsSQL,$table,$table));
  82  	 	 if (isset($savem)) $this->SetFetchMode($savem);
  83  	 	 $ADODB_FETCH_MODE = $save;
  84  
  85  	 	 if ($rs === false) return false;
  86  
  87  	 	 $retarr = array();
  88  	 	 while (!$rs->EOF) {
  89  	 	 	 $fld = new ADOFieldObject();
  90  	 	 	 $fld->name = $rs->fields[0];
  91  
  92  	 	 	 // since we're returning type and length as one string,
  93  	 	 	 // split them out here.
  94  
  95  	 	 	 if ($first = strstr($rs->fields[1], "(")) {
  96  	 	 	  $fld->max_length = trim($first, "()");
  97  	 	 	 } else {
  98  	 	 	  $fld->max_length = -1;
  99  	 	 	 }
 100  
 101  	 	 	 if ($first = strpos($rs->fields[1], "(")) {
 102  	 	 	  $fld->type = substr($rs->fields[1], 0, $first);
 103  	 	 	 } else {
 104  	 	 	  $fld->type = $rs->fields[1];
 105  	 	 	 }
 106  
 107  	 	 	 switch ($fld->type) {
 108  	 	 	  case "byteint":
 109  	 	 	  case "boolean":
 110  	 	 	  $fld->max_length = 1;
 111  	 	 	  break;
 112  	 	 	  case "smallint":
 113  	 	 	  $fld->max_length = 2;
 114  	 	 	  break;
 115  	 	 	  case "integer":
 116  	 	 	  case "numeric":
 117  	 	 	  case "date":
 118  	 	 	  $fld->max_length = 4;
 119  	 	 	  break;
 120  	 	 	  case "bigint":
 121  	 	 	  case "time":
 122  	 	 	  case "timestamp":
 123  	 	 	  $fld->max_length = 8;
 124  	 	 	  break;
 125  	 	 	  case "timetz":
 126  	 	 	  case "time with time zone":
 127  	 	 	  $fld->max_length = 12;
 128  	 	 	  break;
 129  	 	 	 }
 130  
 131  	 	 	 if ($ADODB_FETCH_MODE == ADODB_FETCH_NUM) $retarr[] = $fld;
 132  	 	 	 else $retarr[($upper) ? strtoupper($fld->name) : $fld->name] = $fld;
 133  
 134  	 	 	 $rs->MoveNext();
 135  	 	 }
 136  	 	 $rs->Close();
 137  	 	 return $retarr;
 138  
 139  	 }
 140  
 141  
 142  }
 143  
 144  /*--------------------------------------------------------------------------------------
 145  	  Class Name: Recordset
 146  --------------------------------------------------------------------------------------*/
 147  
 148  class ADORecordSet_netezza extends ADORecordSet_postgres64
 149  {
 150  	 var $databaseType = "netezza";
 151  	 var $canSeek = true;
 152  
 153  	 // _initrs modified to disable blob handling
 154  	function _initrs()
 155  	 {
 156  	 global $ADODB_COUNTRECS;
 157  	 	 $this->_numOfRows = ($ADODB_COUNTRECS)? @pg_num_rows($this->_queryID):-1;
 158  	 	 $this->_numOfFields = @pg_num_fields($this->_queryID);
 159  	 }
 160  
 161  }