Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

Differences Between: [Versions 310 and 311] [Versions 311 and 400] [Versions 311 and 401] [Versions 311 and 402] [Versions 311 and 403] [Versions 39 and 311]

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