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