PageRenderTime 48ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/adodb/drivers/adodb-netezza.inc.php

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