[!!!][TASK] Doctrine: Remove ext:dbal
[Packages/TYPO3.CMS.git] / typo3 / sysext / adodb / adodb / datadict / datadict-oci8.inc.php
1 <?php
2
3 /**
4 @version v5.20.3 01-Jan-2016
5 @copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved.
6 @copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community
7 Released under both BSD license and Lesser GPL library license.
8 Whenever there is any discrepancy between the two licenses,
9 the BSD license will take precedence.
10
11 Set tabs to 4 for best viewing.
12
13 */
14
15 // security - hide paths
16 if (!defined('ADODB_DIR')) die();
17
18 class ADODB2_oci8 extends ADODB_DataDict {
19
20 var $databaseType = 'oci8';
21 var $seqField = false;
22 var $seqPrefix = 'SEQ_';
23 var $dropTable = "DROP TABLE %s CASCADE CONSTRAINTS";
24 var $trigPrefix = 'TRIG_';
25 var $alterCol = ' MODIFY ';
26 var $typeX = 'VARCHAR(4000)';
27 var $typeXL = 'CLOB';
28
29 function MetaType($t, $len=-1, $fieldobj=false)
30 {
31 if (is_object($t)) {
32 $fieldobj = $t;
33 $t = $fieldobj->type;
34 $len = $fieldobj->max_length;
35 }
36 switch (strtoupper($t)) {
37 case 'VARCHAR':
38 case 'VARCHAR2':
39 case 'CHAR':
40 case 'VARBINARY':
41 case 'BINARY':
42 if (isset($this) && $len <= $this->blobSize) return 'C';
43 return 'X';
44
45 case 'NCHAR':
46 case 'NVARCHAR2':
47 case 'NVARCHAR':
48 if (isset($this) && $len <= $this->blobSize) return 'C2';
49 return 'X2';
50
51 case 'NCLOB':
52 case 'CLOB':
53 return 'XL';
54
55 case 'LONG RAW':
56 case 'LONG VARBINARY':
57 case 'BLOB':
58 return 'B';
59
60 case 'TIMESTAMP':
61 return 'TS';
62
63 case 'DATE':
64 return 'T';
65
66 case 'INT':
67 case 'SMALLINT':
68 case 'INTEGER':
69 return 'I';
70
71 default:
72 return 'N';
73 }
74 }
75
76 function ActualType($meta)
77 {
78 switch($meta) {
79 case 'C': return 'VARCHAR';
80 case 'X': return $this->typeX;
81 case 'XL': return $this->typeXL;
82
83 case 'C2': return 'NVARCHAR2';
84 case 'X2': return 'NVARCHAR2(4000)';
85
86 case 'B': return 'BLOB';
87
88 case 'TS':
89 return 'TIMESTAMP';
90
91 case 'D':
92 case 'T': return 'DATE';
93 case 'L': return 'NUMBER(1)';
94 case 'I1': return 'NUMBER(3)';
95 case 'I2': return 'NUMBER(5)';
96 case 'I':
97 case 'I4': return 'NUMBER(10)';
98
99 case 'I8': return 'NUMBER(20)';
100 case 'F': return 'NUMBER';
101 case 'N': return 'NUMBER';
102 case 'R': return 'NUMBER(20)';
103 default:
104 return $meta;
105 }
106 }
107
108 function CreateDatabase($dbname, $options=false)
109 {
110 $options = $this->_Options($options);
111 $password = isset($options['PASSWORD']) ? $options['PASSWORD'] : 'tiger';
112 $tablespace = isset($options["TABLESPACE"]) ? " DEFAULT TABLESPACE ".$options["TABLESPACE"] : '';
113 $sql[] = "CREATE USER ".$dbname." IDENTIFIED BY ".$password.$tablespace;
114 $sql[] = "GRANT CREATE SESSION, CREATE TABLE,UNLIMITED TABLESPACE,CREATE SEQUENCE TO $dbname";
115
116 return $sql;
117 }
118
119 function AddColumnSQL($tabname, $flds)
120 {
121 $tabname = $this->TableName($tabname);
122 $f = array();
123 list($lines,$pkey) = $this->_GenFields($flds);
124 $s = "ALTER TABLE $tabname ADD (";
125 foreach($lines as $v) {
126 $f[] = "\n $v";
127 }
128
129 $s .= implode(', ',$f).')';
130 $sql[] = $s;
131 return $sql;
132 }
133
134 function AlterColumnSQL($tabname, $flds, $tableflds='', $tableoptions='')
135 {
136 $tabname = $this->TableName($tabname);
137 $f = array();
138 list($lines,$pkey) = $this->_GenFields($flds);
139 $s = "ALTER TABLE $tabname MODIFY(";
140 foreach($lines as $v) {
141 $f[] = "\n $v";
142 }
143 $s .= implode(', ',$f).')';
144 $sql[] = $s;
145 return $sql;
146 }
147
148 function DropColumnSQL($tabname, $flds, $tableflds='', $tableoptions='')
149 {
150 if (!is_array($flds)) $flds = explode(',',$flds);
151 foreach ($flds as $k => $v) $flds[$k] = $this->NameQuote($v);
152
153 $sql = array();
154 $s = "ALTER TABLE $tabname DROP(";
155 $s .= implode(', ',$flds).') CASCADE CONSTRAINTS';
156 $sql[] = $s;
157 return $sql;
158 }
159
160 function _DropAutoIncrement($t)
161 {
162 if (strpos($t,'.') !== false) {
163 $tarr = explode('.',$t);
164 return "drop sequence ".$tarr[0].".seq_".$tarr[1];
165 }
166 return "drop sequence seq_".$t;
167 }
168
169 // return string must begin with space
170 function _CreateSuffix($fname,&$ftype,$fnotnull,$fdefault,$fautoinc,$fconstraint,$funsigned)
171 {
172 $suffix = '';
173
174 if ($fdefault == "''" && $fnotnull) {// this is null in oracle
175 $fnotnull = false;
176 if ($this->debug) ADOConnection::outp("NOT NULL and DEFAULT='' illegal in Oracle");
177 }
178
179 if (strlen($fdefault)) $suffix .= " DEFAULT $fdefault";
180 if ($fnotnull) $suffix .= ' NOT NULL';
181
182 if ($fautoinc) $this->seqField = $fname;
183 if ($fconstraint) $suffix .= ' '.$fconstraint;
184
185 return $suffix;
186 }
187
188 /*
189 CREATE or replace TRIGGER jaddress_insert
190 before insert on jaddress
191 for each row
192 begin
193 select seqaddress.nextval into :new.A_ID from dual;
194 end;
195 */
196 function _Triggers($tabname,$tableoptions)
197 {
198 if (!$this->seqField) return array();
199
200 $sequenceTriggerTableName = trim($tabname, $this->connection->nameQuote);
201 if ($this->schema) {
202 $t = strpos($tabname, '.');
203 if ($t !== FALSE) {
204 $tab = substr($sequenceTriggerTableName, $t + 1);
205 } else {
206 $tab = $sequenceTriggerTableName;
207 }
208 $seqname = $this->schema . '.' . $this->seqPrefix . $tab;
209 $trigname = $this->schema . '.' . $this->trigPrefix . $tab;
210 } else {
211 $seqname = $this->seqPrefix . $sequenceTriggerTableName;
212 $trigname = $this->trigPrefix . $sequenceTriggerTableName;
213 }
214
215 if (strlen($seqname) > 30) {
216 $seqname = $this->seqPrefix.uniqid('');
217 } // end if
218 if (strlen($trigname) > 30) {
219 $trigname = $this->trigPrefix.uniqid('');
220 } // end if
221
222 if (isset($tableoptions['REPLACE'])) $sql[] = "DROP SEQUENCE $seqname";
223 $seqCache = '';
224 if (isset($tableoptions['SEQUENCE_CACHE'])){$seqCache = $tableoptions['SEQUENCE_CACHE'];}
225 $seqIncr = '';
226 if (isset($tableoptions['SEQUENCE_INCREMENT'])){$seqIncr = ' INCREMENT BY '.$tableoptions['SEQUENCE_INCREMENT'];}
227 $seqStart = '';
228 if (isset($tableoptions['SEQUENCE_START'])){$seqIncr = ' START WITH '.$tableoptions['SEQUENCE_START'];}
229 $sql[] = "CREATE SEQUENCE $seqname $seqStart $seqIncr $seqCache";
230 $sql[] = "CREATE OR REPLACE TRIGGER $trigname BEFORE insert ON $tabname FOR EACH ROW WHEN (NEW.$this->seqField IS NULL OR NEW.$this->seqField = 0) BEGIN select $seqname.nextval into :new.$this->seqField from dual; END;";
231
232 $this->seqField = false;
233 return $sql;
234 }
235
236 /*
237 CREATE [TEMPORARY] TABLE [IF NOT EXISTS] tbl_name [(create_definition,...)]
238 [table_options] [select_statement]
239 create_definition:
240 col_name type [NOT NULL | NULL] [DEFAULT default_value] [AUTO_INCREMENT]
241 [PRIMARY KEY] [reference_definition]
242 or PRIMARY KEY (index_col_name,...)
243 or KEY [index_name] (index_col_name,...)
244 or INDEX [index_name] (index_col_name,...)
245 or UNIQUE [INDEX] [index_name] (index_col_name,...)
246 or FULLTEXT [INDEX] [index_name] (index_col_name,...)
247 or [CONSTRAINT symbol] FOREIGN KEY [index_name] (index_col_name,...)
248 [reference_definition]
249 or CHECK (expr)
250 */
251
252
253
254 function _IndexSQL($idxname, $tabname, $flds,$idxoptions)
255 {
256 $sql = array();
257
258 if ( isset($idxoptions['REPLACE']) || isset($idxoptions['DROP']) ) {
259 $sql[] = sprintf ($this->dropIndex, $idxname, $tabname);
260 if ( isset($idxoptions['DROP']) )
261 return $sql;
262 }
263
264 if ( empty ($flds) ) {
265 return $sql;
266 }
267
268 if (isset($idxoptions['BITMAP'])) {
269 $unique = ' BITMAP';
270 } elseif (isset($idxoptions['UNIQUE'])) {
271 $unique = ' UNIQUE';
272 } else {
273 $unique = '';
274 }
275
276 if ( is_array($flds) )
277 $flds = implode(', ',$flds);
278 $s = 'CREATE' . $unique . ' INDEX ' . $idxname . ' ON ' . $tabname . ' (' . $flds . ')';
279
280 if ( isset($idxoptions[$this->upperName]) )
281 $s .= $idxoptions[$this->upperName];
282
283 if (isset($idxoptions['oci8']))
284 $s .= $idxoptions['oci8'];
285
286
287 $sql[] = $s;
288
289 return $sql;
290 }
291
292 function GetCommentSQL($table,$col)
293 {
294 $table = $this->connection->qstr($table);
295 $col = $this->connection->qstr($col);
296 return "select comments from USER_COL_COMMENTS where TABLE_NAME=$table and COLUMN_NAME=$col";
297 }
298
299 function SetCommentSQL($table,$col,$cmt)
300 {
301 $cmt = $this->connection->qstr($cmt);
302 return "COMMENT ON COLUMN $table.$col IS $cmt";
303 }
304 }