d7444bfc |
1 | <?php // $Id$ |
2 | |
3 | /////////////////////////////////////////////////////////////////////////// |
4 | // // |
5 | // NOTICE OF COPYRIGHT // |
6 | // // |
7 | // Moodle - Modular Object-Oriented Dynamic Learning Environment // |
8 | // http://moodle.com // |
9 | // // |
10 | // Copyright (C) 2001-3001 Martin Dougiamas http://dougiamas.com // |
11 | // (C) 2001-3001 Eloy Lafuente (stronk7) http://contiento.com // |
12 | // // |
13 | // This program is free software; you can redistribute it and/or modify // |
14 | // it under the terms of the GNU General Public License as published by // |
15 | // the Free Software Foundation; either version 2 of the License, or // |
16 | // (at your option) any later version. // |
17 | // // |
18 | // This program is distributed in the hope that it will be useful, // |
19 | // but WITHOUT ANY WARRANTY; without even the implied warranty of // |
20 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
21 | // GNU General Public License for more details: // |
22 | // // |
23 | // http://www.gnu.org/copyleft/gpl.html // |
24 | // // |
25 | /////////////////////////////////////////////////////////////////////////// |
26 | |
27 | /// This class generate SQL code to be used against Oracle |
28 | /// It extends XMLDBgenerator so everything can be |
29 | /// overriden as needed to generate correct SQL. |
30 | |
31 | class XMLDBoci8po extends XMLDBgenerator { |
32 | |
33 | /// Only set values that are different from the defaults present in XMLDBgenerator |
34 | |
0513f3bf |
35 | var $statement_end = "\n/"; // String to be automatically added at the end of each statement |
36 | // Using "/" because the standard ";" isn't good for stored procedures (triggers) |
37 | |
d7444bfc |
38 | var $number_type = 'NUMBER'; // Proper type for NUMBER(x) in this DB |
39 | |
40 | var $unsigned_allowed = false; // To define in the generator must handle unsigned information |
2efaf3f8 |
41 | var $default_for_char = ' '; // To define the default to set for NOT NULLs CHARs without default (null=do nothing) |
42 | // Using this whitespace here because Oracle doesn't distinguish empty and null! :-( |
d7444bfc |
43 | |
812e363a |
44 | var $drop_default_clause_required = true; //To specify if the generator must use some DEFAULT clause to drop defaults |
45 | var $drop_default_clause = 'NULL'; //The DEFAULT clause required to drop defaults |
46 | |
f075bac4 |
47 | var $default_after_null = false; //To decide if the default clause of each field must go after the null clause |
48 | |
d7444bfc |
49 | var $sequence_extra_code = true; //Does the generator need to add extra code to generate the sequence fields |
50 | var $sequence_name = ''; //Particular name for inline sequences in this generator |
51 | |
20c559dd |
52 | var $drop_table_extra_code = true; //Does the generator need to add code after table drop |
53 | |
54 | var $rename_table_extra_code = true; //Does the generator need to add code after table rename |
3a8c55c3 |
55 | |
c562997f |
56 | var $rename_column_extra_code = true; //Does the generator need to add code after field rename |
57 | |
d7444bfc |
58 | var $enum_inline_code = false; //Does the generator need to add inline code in the column definition |
59 | |
19c8321e |
60 | var $alter_column_sql = 'ALTER TABLE TABLENAME MODIFY (COLUMNSPECS)'; //The SQL template to alter columns |
61 | |
d7444bfc |
62 | /** |
20c559dd |
63 | * Creates one new XMLDBoci8po |
d7444bfc |
64 | */ |
65 | function XMLDBoci8po() { |
66 | parent::XMLDBgenerator(); |
67 | $this->prefix = ''; |
68 | $this->reserved_words = $this->getReservedWords(); |
69 | } |
70 | |
71 | /** |
72 | * Given one XMLDB Type, lenght and decimals, returns the DB proper SQL type |
73 | */ |
74 | function getTypeSQL ($xmldb_type, $xmldb_length=null, $xmldb_decimals=null) { |
75 | |
76 | switch ($xmldb_type) { |
77 | case XMLDB_TYPE_INTEGER: // From http://www.postgresql.org/docs/7.4/interactive/datatype.html |
78 | if (empty($xmldb_length)) { |
79 | $xmldb_length = 10; |
80 | } |
81 | $dbtype = 'NUMBER(' . $xmldb_length . ')'; |
82 | break; |
83 | case XMLDB_TYPE_NUMBER: |
84 | $dbtype = $this->number_type; |
4782a1f8 |
85 | /// 38 is the max allowed |
86 | if ($xmldb_length > 38) { |
87 | $xmldb_length = 38; |
88 | } |
d7444bfc |
89 | if (!empty($xmldb_length)) { |
90 | $dbtype .= '(' . $xmldb_length; |
91 | if (!empty($xmldb_decimals)) { |
92 | $dbtype .= ',' . $xmldb_decimals; |
93 | } |
94 | $dbtype .= ')'; |
95 | } |
96 | break; |
97 | case XMLDB_TYPE_FLOAT: |
98 | $dbtype = 'NUMBER'; |
99 | break; |
100 | case XMLDB_TYPE_CHAR: |
101 | $dbtype = 'VARCHAR2'; |
102 | if (empty($xmldb_length)) { |
103 | $xmldb_length='255'; |
104 | } |
105 | $dbtype .= '(' . $xmldb_length . ')'; |
106 | break; |
107 | case XMLDB_TYPE_TEXT: |
108 | $dbtype = 'CLOB'; |
109 | break; |
110 | case XMLDB_TYPE_BINARY: |
111 | $dbtype = 'BLOB'; |
112 | break; |
113 | case XMLDB_TYPE_DATETIME: |
114 | $dbtype = 'DATE'; |
115 | break; |
116 | } |
117 | return $dbtype; |
118 | } |
119 | |
eef868d1 |
120 | /** |
d7444bfc |
121 | * Returns the code needed to create one enum for the xmldb_table and xmldb_field passes |
eef868d1 |
122 | */ |
d7444bfc |
123 | function getEnumExtraSQL ($xmldb_table, $xmldb_field) { |
eef868d1 |
124 | |
d7444bfc |
125 | $sql = 'CONSTRAINT ' . $this->getNameForObject($xmldb_table->getName(), $xmldb_field->getName(), 'ck'); |
0dd87cfa |
126 | $sql.= ' CHECK (' . $this->getEncQuoted($xmldb_field->getName()) . ' IN (' . implode(', ', $xmldb_field->getEnumValues()) . '))'; |
d7444bfc |
127 | |
128 | return $sql; |
129 | } |
130 | |
131 | /** |
132 | * Returns the code needed to create one sequence for the xmldb_table and xmldb_field passes |
133 | */ |
134 | function getCreateSequenceSQL ($xmldb_table, $xmldb_field) { |
135 | |
20c559dd |
136 | $results = array(); |
137 | |
465a8029 |
138 | $sequence_name = $this->getNameForObject($xmldb_table->getName(), $xmldb_field->getName(), 'seq'); |
eef868d1 |
139 | |
465a8029 |
140 | $sequence = "CREATE SEQUENCE " . $sequence_name; |
d7444bfc |
141 | $sequence.= "\n START WITH 1"; |
142 | $sequence.= "\n INCREMENT BY 1"; |
9dcc6300 |
143 | $sequence.= "\n NOMAXVALUE"; |
d7444bfc |
144 | |
20c559dd |
145 | $results[] = $sequence; |
146 | |
147 | $results = array_merge($results, $this->getCreateTriggerSQL ($xmldb_table, $xmldb_field)); |
148 | |
149 | return $results; |
150 | } |
151 | |
152 | /** |
153 | * Returns the code needed to create one trigger for the xmldb_table and xmldb_field passed |
154 | */ |
155 | function getCreateTriggerSQL ($xmldb_table, $xmldb_field) { |
156 | |
d7444bfc |
157 | $trigger_name = $this->getNameForObject($xmldb_table->getName(), $xmldb_field->getName(), 'trg'); |
20c559dd |
158 | $sequence_name = $this->getNameForObject($xmldb_table->getName(), $xmldb_field->getName(), 'seq'); |
eef868d1 |
159 | |
1d5071a5 |
160 | $trigger = "CREATE TRIGGER " . $trigger_name; |
d7444bfc |
161 | $trigger.= "\n BEFORE INSERT"; |
9af19c72 |
162 | $trigger.= "\nON " . $this->getTableName($xmldb_table); |
d7444bfc |
163 | $trigger.= "\n FOR EACH ROW"; |
164 | $trigger.= "\nBEGIN"; |
4782a1f8 |
165 | $trigger.= "\n IF :new." . $this->getEncQuoted($xmldb_field->getName()) . ' IS NULL THEN'; |
b8851b80 |
166 | $trigger.= "\n SELECT " . $sequence_name . '.nextval INTO :new.' . $this->getEncQuoted($xmldb_field->getName()) . " FROM dual;"; |
167 | $trigger.= "\n END IF;"; |
0513f3bf |
168 | $trigger.= "\nEND;"; |
20c559dd |
169 | |
170 | return array($trigger); |
d7444bfc |
171 | } |
172 | |
3a8c55c3 |
173 | /** |
174 | * Returns the code needed to drop one sequence for the xmldb_table and xmldb_field passed |
175 | * Can, optionally, specify if the underlying trigger will be also dropped |
176 | */ |
177 | function getDropSequenceSQL ($xmldb_table, $xmldb_field, $include_trigger=false) { |
178 | |
179 | $sequence_name = $this->getNameForObject($xmldb_table->getName(), $xmldb_field->getName(), 'seq'); |
eef868d1 |
180 | |
3a8c55c3 |
181 | $sequence = "DROP SEQUENCE " . $sequence_name; |
182 | |
183 | $trigger_name = $this->getNameForObject($xmldb_table->getName(), $xmldb_field->getName(), 'trg'); |
eef868d1 |
184 | |
3a8c55c3 |
185 | $trigger = "DROP TRIGGER " . $trigger_name; |
186 | |
187 | if ($include_trigger) { |
188 | $result = array($sequence, $trigger); |
189 | } else { |
190 | $result = array($sequence); |
191 | } |
192 | return $result; |
193 | } |
194 | |
195 | /** |
196 | * Returns the code (in array) needed to add one comment to the table |
197 | */ |
198 | function getCommentSQL ($xmldb_table) { |
199 | |
9af19c72 |
200 | $comment = "COMMENT ON TABLE " . $this->getTableName($xmldb_table); |
3a8c55c3 |
201 | $comment.= " IS '" . substr($xmldb_table->getComment(), 0, 250) . "'"; |
d7444bfc |
202 | |
3a8c55c3 |
203 | return array($comment); |
204 | } |
d7444bfc |
205 | |
c562997f |
206 | /** |
207 | * Returns the code (array of statements) needed to execute extra statements on field rename |
208 | */ |
209 | function getRenameFieldExtraSQL ($xmldb_table, $xmldb_field, $newname) { |
210 | |
211 | $results = array(); |
212 | |
213 | /// If the field is enum, drop and re-create the check constraint |
214 | if ($xmldb_field->getEnum()) { |
215 | /// Drop the current enum |
216 | $results = array_merge($results, $this->getDropEnumSQL($xmldb_table, $xmldb_field)); |
217 | /// Change field name |
218 | $xmldb_field->setName($newname); |
219 | /// Recreate the enum |
220 | $results = array_merge($results, $this->getCreateEnumSQL($xmldb_table, $xmldb_field)); |
221 | } |
222 | |
223 | return $results; |
224 | } |
225 | |
3a8c55c3 |
226 | /** |
227 | * Returns the code (array of statements) needed to execute extra statements on table drop |
228 | */ |
229 | function getDropTableExtraSQL ($xmldb_table) { |
230 | $xmldb_field = new XMLDBField('id'); // Fields having sequences should be exclusively, id. |
231 | return $this->getDropSequenceSQL($xmldb_table, $xmldb_field, false); |
232 | } |
d7444bfc |
233 | |
20c559dd |
234 | /** |
235 | * Returns the code (array of statements) needed to execute extra statements on table rename |
236 | */ |
237 | function getRenameTableExtraSQL ($xmldb_table, $newname) { |
238 | |
239 | $results = array(); |
240 | |
241 | $xmldb_field = new XMLDBField('id'); // Fields having sequences should be exclusively, id. |
242 | |
243 | $oldseqname = $this->getNameForObject($xmldb_table->getName(), $xmldb_field->getName(), 'seq'); |
244 | $newseqname = $this->getNameForObject($newname, $xmldb_field->getName(), 'seq'); |
245 | |
246 | /// Rename de sequence |
247 | $results[] = 'RENAME ' . $oldseqname . ' TO ' . $newseqname; |
248 | |
249 | $oldtriggername = $this->getNameForObject($xmldb_table->getName(), $xmldb_field->getName(), 'trg'); |
250 | $newtriggername = $this->getNameForObject($newname, $xmldb_field->getName(), 'trg'); |
251 | |
252 | /// Drop old trigger |
253 | $results[] = "DROP TRIGGER " . $oldtriggername; |
254 | |
bb7e5c47 |
255 | $newt = new XMLDBTable($newname); /// Temp table for trigger code generation |
20c559dd |
256 | |
257 | /// Create new trigger |
bb7e5c47 |
258 | $results = array_merge($results, $this->getCreateTriggerSQL($newt, $xmldb_field)); |
259 | |
260 | /// Rename all the check constraints in the table |
261 | $oldtablename = $this->getTableName($xmldb_table); |
262 | $newtablename = $this->getTableName($newt); |
263 | |
264 | $oldconstraintprefix = $this->getNameForObject($xmldb_table->getName(), ''); |
265 | $newconstraintprefix = $this->getNameForObject($newt->getName(), '', ''); |
266 | |
267 | if ($constraints = $this->getCheckConstraintsFromDB($xmldb_table)) { |
268 | foreach ($constraints as $constraint) { |
269 | /// Drop the old constraint |
270 | $results[] = 'ALTER TABLE ' . $newtablename . ' DROP CONSTRAINT ' . $constraint->name; |
271 | /// Calculate the new constraint name |
272 | $newconstraintname = str_replace($oldconstraintprefix, $newconstraintprefix, $constraint->name); |
273 | /// Add the new constraint |
274 | $results[] = 'ALTER TABLE ' . $newtablename . ' ADD CONSTRAINT ' . $newconstraintname . |
275 | ' CHECK (' . $constraint->description . ')'; |
276 | } |
277 | } |
20c559dd |
278 | |
279 | return $results; |
280 | } |
281 | |
19c8321e |
282 | /** |
283 | * Given one XMLDBTable and one XMLDBField, return the SQL statements needded to alter the field in the table |
284 | * Oracle has some severe limits: |
285 | * - clob and blob fields doesn't allow type to be specified |
286 | * - error is dropped if the null/not null clause is specified and hasn't changed |
11b75afe |
287 | * - changes in precision/decimals of numeric fields drop an ORA-1440 error |
19c8321e |
288 | */ |
289 | function getAlterFieldSQL($xmldb_table, $xmldb_field) { |
290 | |
11b75afe |
291 | global $db; |
292 | |
293 | $results = array(); /// To store all the needed SQL commands |
294 | |
295 | /// Get the quoted name of the table and field |
9af19c72 |
296 | $tablename = $this->getTableName($xmldb_table); |
11b75afe |
297 | $fieldname = $this->getEncQuoted($xmldb_field->getName()); |
298 | |
299 | /// Take a look to field metadata |
300 | $meta = array_change_key_case($db->MetaColumns($tablename)); |
301 | $metac = $meta[$fieldname]; |
302 | $oldtype = strtolower($metac->type); |
303 | $oldmetatype = column_type($xmldb_table->getName(), $fieldname); |
304 | $oldlength = $metac->max_length; |
305 | /// To calculate the oldlength if the field is numeric, we need to perform one extra query |
306 | /// because ADOdb has one bug here. http://phplens.com/lens/lensforum/msgs.php?id=15883 |
307 | if ($oldmetatype == 'N') { |
308 | $uppertablename = strtoupper($tablename); |
309 | $upperfieldname = strtoupper($fieldname); |
310 | if ($col = get_record_sql("SELECT cname, precision |
311 | FROM col |
312 | WHERE tname = '$uppertablename' |
313 | AND cname = '$upperfieldname'")) { |
314 | $oldlength = $col->precision; |
315 | } |
316 | } |
317 | $olddecimals = empty($metac->scale) ? null : $metac->scale; |
318 | $oldnotnull = empty($metac->not_null) ? false : $metac->not_null; |
812e363a |
319 | $olddefault = empty($metac->default_value) || strtoupper($metac->default_value) == 'NULL' ? null : $metac->default_value; |
11b75afe |
320 | |
321 | $typechanged = true; //By default, assume that the column type has changed |
322 | $precisionchanged = true; //By default, assume that the column precision has changed |
323 | $decimalchanged = true; //By default, assume that the column decimal has changed |
324 | $defaultchanged = true; //By default, assume that the column default has changed |
325 | $notnullchanged = true; //By default, assume that the column notnull has changed |
326 | |
327 | $from_temp_fields = false; //By default don't assume we are going to use temporal fields |
328 | |
329 | /// Detect if we are changing the type of the column |
330 | if (($xmldb_field->getType() == XMLDB_TYPE_INTEGER && substr($oldmetatype, 0, 1) == 'I') || |
331 | ($xmldb_field->getType() == XMLDB_TYPE_NUMBER && $oldmetatype == 'N') || |
332 | ($xmldb_field->getType() == XMLDB_TYPE_FLOAT && $oldmetatype == 'F') || |
333 | ($xmldb_field->getType() == XMLDB_TYPE_CHAR && substr($oldmetatype, 0, 1) == 'C') || |
334 | ($xmldb_field->getType() == XMLDB_TYPE_TEXT && substr($oldmetatype, 0, 1) == 'X') || |
335 | ($xmldb_field->getType() == XMLDB_TYPE_BINARY && $oldmetatype == 'B')) { |
336 | $typechanged = false; |
337 | } |
338 | /// Detect if precision has changed |
339 | if (($xmldb_field->getType() == XMLDB_TYPE_TEXT) || |
340 | ($xmldb_field->getType() == XMLDB_TYPE_BINARY) || |
341 | ($oldlength == -1) || |
342 | ($xmldb_field->getLength() == $oldlength)) { |
343 | $precisionchanged = false; |
344 | } |
345 | /// Detect if decimal has changed |
346 | if (($xmldb_field->getType() == XMLDB_TYPE_INTEGER) || |
347 | ($xmldb_field->getType() == XMLDB_TYPE_CHAR) || |
348 | ($xmldb_field->getType() == XMLDB_TYPE_TEXT) || |
349 | ($xmldb_field->getType() == XMLDB_TYPE_BINARY) || |
350 | (!$xmldb_field->getDecimals()) || |
351 | (!$olddecimals) || |
352 | ($xmldb_field->getDecimals() == $olddecimals)) { |
353 | $decimalchanged = false; |
354 | } |
355 | /// Detect if we are changing the default |
356 | if (($xmldb_field->getDefault() === null && $olddefault === null) || |
357 | ($xmldb_field->getDefault() === $olddefault) || //Check both equality and |
358 | ("'" . $xmldb_field->getDefault() . "'" === $olddefault)) { //Equality with quotes because ADOdb returns the default with quotes |
359 | $defaultchanged = false; |
360 | } |
812e363a |
361 | |
11b75afe |
362 | /// Detect if we are changing the nullability |
363 | if (($xmldb_field->getNotnull() === $oldnotnull)) { |
364 | $notnullchanged = false; |
365 | } |
366 | |
367 | /// If type has changed or precision or decimal has changed and we are in one numeric field |
368 | /// - create one temp column with the new specs |
369 | /// - fill the new column with the values from the old one |
370 | /// - drop the old column |
371 | /// - rename the temp column to the original name |
372 | if (($typechanged) || ($oldmetatype == 'N' && ($precisionchanged || $decimalchanged))) { |
373 | $tempcolname = $xmldb_field->getName() . '_alter_column_tmp'; |
374 | /// Prevent temp field to have both NULL/NOT NULL and DEFAULT constraints |
375 | $this->alter_column_skip_notnull = true; |
376 | $this->alter_column_skip_default = true; |
377 | $xmldb_field->setName($tempcolname); |
378 | /// Create the temporal column |
379 | $results = array_merge($results, $this->getAddFieldSQL($xmldb_table, $xmldb_field)); |
380 | /// Copy contents from original col to the temporal one |
381 | $results[] = 'UPDATE ' . $tablename . ' SET ' . $tempcolname . ' = ' . $fieldname; |
382 | /// Drop the old column |
383 | $xmldb_field->setName($fieldname); //Set back the original field name |
384 | $results = array_merge($results, $this->getDropFieldSQL($xmldb_table, $xmldb_field)); |
385 | /// Rename the temp column to the original one |
386 | $results[] = 'ALTER TABLE ' . $tablename . ' RENAME COLUMN ' . $tempcolname . ' TO ' . $fieldname; |
387 | /// Mark we have performed one change based in temp fields |
388 | $from_temp_fields = true; |
389 | /// Re-enable the notnull and default sections so the general AlterFieldSQL can use it |
390 | $this->alter_column_skip_notnull = false; |
391 | $this->alter_column_skip_default = false; |
812e363a |
392 | /// Dissable the type section because we have done it with the temp field |
11b75afe |
393 | $this->alter_column_skip_type = true; |
599caff8 |
394 | /// If new field is nullable, nullability hasn't changed |
395 | if (!$xmldb_field->getNotnull()) { |
396 | $notnullchanged = false; |
397 | } |
398 | /// If new field hasn't default, default hasn't changed |
399 | if ($xmldb_field->getDefault() === null) { |
400 | $defaultchanged = false; |
401 | } |
11b75afe |
402 | } |
403 | |
404 | /// If type and precision and decimals hasn't changed, prevent the type clause |
405 | if (!$typechanged && !$precisionchanged && !$decimalchanged) { |
406 | $this->alter_column_skip_type = true; |
407 | } |
408 | |
409 | /// If NULL/NOT NULL hasn't changed |
410 | /// prevent null clause to be specified |
411 | if (!$notnullchanged) { |
412 | $this->alter_column_skip_notnull = true; /// Initially, prevent the notnull clause |
413 | /// But, if we have used the temp field and the new field is not null, then enforce the not null clause |
414 | if ($from_temp_fields && $xmldb_field->getNotnull()) { |
415 | $this->alter_column_skip_notnull = false; |
416 | } |
417 | } |
418 | /// If default hasn't changed |
419 | /// prevent default clause to be specified |
420 | if (!$defaultchanged) { |
421 | $this->alter_column_skip_default = true; /// Initially, prevent the default clause |
422 | /// But, if we have used the temp field and the new field has default clause, then enforce the default clause |
423 | if ($from_temp_fields && $default_clause = $this->getDefaultClause($xmldb_field)) { |
424 | $this->alter_column_skip_default = false; |
425 | } |
426 | } |
427 | |
428 | /// If arriving here, something is not being skiped (type, notnull, default), calculate the standar AlterFieldSQL |
429 | if (!$this->alter_column_skip_type || !$this->alter_column_skip_notnull || !$this->alter_column_skip_default) { |
430 | $results = array_merge($results, parent::getAlterFieldSQL($xmldb_table, $xmldb_field)); |
431 | return $results; |
432 | } |
433 | |
434 | /// Finally return results |
435 | return $results; |
19c8321e |
436 | } |
437 | |
b899d9bf |
438 | /** |
439 | * Given one XMLDBTable and one XMLDBField, return the SQL statements needded to create its enum |
440 | * (usually invoked from getModifyEnumSQL() |
441 | */ |
442 | function getCreateEnumSQL($xmldb_table, $xmldb_field) { |
443 | /// All we have to do is to create the check constraint |
444 | return array('ALTER TABLE ' . $this->getTableName($xmldb_table) . |
445 | ' ADD ' . $this->getEnumExtraSQL($xmldb_table, $xmldb_field)); |
446 | } |
447 | |
448 | /** |
449 | * Given one XMLDBTable and one XMLDBField, return the SQL statements needded to drop its enum |
450 | * (usually invoked from getModifyEnumSQL() |
451 | */ |
452 | function getDropEnumSQL($xmldb_table, $xmldb_field) { |
453 | /// All we have to do is to drop the check constraint |
454 | return array('ALTER TABLE ' . $this->getTableName($xmldb_table) . |
455 | ' DROP CONSTRAINT ' . $this->getNameForObject($xmldb_table->getName(), $xmldb_field->getName(), 'ck')); |
456 | } |
457 | |
812e363a |
458 | /** |
459 | * Given one XMLDBTable and one XMLDBField, return the SQL statements needded to create its default |
460 | * (usually invoked from getModifyDefaultSQL() |
461 | */ |
462 | function getCreateDefaultSQL($xmldb_table, $xmldb_field) { |
463 | /// Just a wrapper over the getAlterFieldSQL() function for Oracle that |
464 | /// is capable of handling defaults |
465 | return $this->getAlterFieldSQL($xmldb_table, $xmldb_field); |
466 | } |
467 | |
468 | /** |
469 | * Given one XMLDBTable and one XMLDBField, return the SQL statements needded to drop its default |
470 | * (usually invoked from getModifyDefaultSQL() |
471 | */ |
472 | function getDropDefaultSQL($xmldb_table, $xmldb_field) { |
473 | /// Just a wrapper over the getAlterFieldSQL() function for Oracle that |
474 | /// is capable of handling defaults |
475 | return $this->getAlterFieldSQL($xmldb_table, $xmldb_field); |
476 | } |
477 | |
bb7e5c47 |
478 | /** |
479 | * Given one XMLDBTable returns one array with all the check constrainsts |
480 | * in the table (fetched from DB) |
481 | * Each element contains the name of the constraint and its description |
482 | * If no check constraints are found, returns an empty array |
483 | */ |
484 | function getCheckConstraintsFromDB($xmldb_table) { |
485 | |
486 | $results = array(); |
487 | |
488 | $tablename = strtoupper($this->getTableName($xmldb_table)); |
489 | |
490 | if ($constraints = get_records_sql("SELECT lower(c.constraint_name) AS name, c.search_condition AS description |
491 | FROM user_constraints c |
492 | WHERE c.table_name = '{$tablename}' |
493 | AND c.constraint_type = 'C' |
494 | AND c.constraint_name not like 'SYS%'")) { |
495 | foreach ($constraints as $constraint) { |
496 | $results[$constraint->name] = $constraint; |
497 | } |
498 | } |
499 | |
500 | return $results; |
501 | } |
502 | |
d7444bfc |
503 | /** |
504 | * Returns an array of reserved words (lowercase) for this DB |
505 | */ |
506 | function getReservedWords() { |
6aa7885e |
507 | /// This file contains the reserved words for Oracle databases |
508 | /// from http://download-uk.oracle.com/docs/cd/B10501_01/server.920/a96540/ap_keywd.htm |
d7444bfc |
509 | $reserved_words = array ( |
510 | 'access', 'add', 'all', 'alter', 'and', 'any', |
511 | 'as', 'asc', 'audit', 'between', 'by', 'char', |
512 | 'check', 'cluster', 'column', 'comment', |
513 | 'compress', 'connect', 'create', 'current', |
514 | 'date', 'decimal', 'default', 'delete', 'desc', |
515 | 'distinct', 'drop', 'else', 'exclusive', 'exists', |
516 | 'file', 'float', 'for', 'from', 'grant', 'group', |
517 | 'having', 'identified', 'immediate', 'in', |
518 | 'increment', 'index', 'initial', 'insert', |
519 | 'integer', 'intersect', 'into', 'is', 'level', |
520 | 'like', 'lock', 'long', 'maxextents', 'minus', |
521 | 'mlslabel', 'mode', 'modify', 'noaudit', |
522 | 'nocompress', 'not', 'nowait', 'null', 'number', |
523 | 'of', 'offline', 'on', 'online', 'option', 'or', |
524 | 'order', 'pctfree', 'prior', 'privileges', |
525 | 'public', 'raw', 'rename', 'resource', 'revoke', |
526 | 'row', 'rowid', 'rownum', 'rows', 'select', |
527 | 'session', 'set', 'share', 'size', 'smallint', |
528 | 'start', 'successful', 'synonym', 'sysdate', |
529 | 'table', 'then', 'to', 'trigger', 'uid', 'union', |
530 | 'unique', 'update', 'user', 'validate', 'values', |
531 | 'varchar', 'varchar2', 'view', 'whenever', |
532 | 'where', 'with' |
eef868d1 |
533 | ); |
d7444bfc |
534 | return $reserved_words; |
535 | } |
536 | } |
537 | |
538 | ?> |