adodb-netezza.inc.php 4.7 KB

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