47 if ($length !==
null) {
48 return "SUBSTR($value, $position, $length)";
51 return "SUBSTR($value, $position)";
71 return 'TO_CHAR(CURRENT_TIMESTAMP, \'YYYY-MM-DD HH24:MI:SS\')';
85 if ($startPos ==
false) {
86 return 'INSTR('.$str.
', '.$substr.
')';
88 return 'INSTR('.$str.
', '.$substr.
', '.$startPos.
')';
116 return 'CREATE SEQUENCE ' . $sequence->getQuotedName($this) .
117 ' START WITH ' . $sequence->getInitialValue() .
118 ' MINVALUE ' . $sequence->getInitialValue() .
119 ' INCREMENT BY ' . $sequence->getAllocationSize();
130 return 'SELECT ' . $sequenceName .
'.nextval FROM DUAL';
147 case \Doctrine\DBAL\Connection::TRANSACTION_READ_UNCOMMITTED:
148 return 'READ UNCOMMITTED';
149 case \Doctrine\DBAL\Connection::TRANSACTION_READ_COMMITTED:
150 return 'READ COMMITTED';
151 case \Doctrine\DBAL\Connection::TRANSACTION_REPEATABLE_READ:
152 case \Doctrine\DBAL\Connection::TRANSACTION_SERIALIZABLE:
153 return 'SERIALIZABLE';
155 return parent::_getTransactionIsolationLevelSQL($level);
196 return 'TIMESTAMP(0)';
204 return 'TIMESTAMP(0) WITH TIME ZONE';
239 if ( ! isset($field[
'length'])) {
240 if (array_key_exists(
'default', $field)) {
243 $field[
'length'] =
false;
248 $fixed = (isset($field[
'fixed'])) ? $field[
'fixed'] :
false;
250 return $fixed ? ($length ?
'CHAR(' . $length .
')' :
'CHAR(2000)')
251 : ($length ?
'VARCHAR2(' . $length .
')' :
'VARCHAR2(4000)');
262 return 'SELECT username FROM all_users';
267 return "SELECT sequence_name, min_value, increment_by FROM sys.all_sequences ".
268 "WHERE SEQUENCE_OWNER = '".strtoupper($database).
"'";
280 $indexes = isset($options[
'indexes']) ? $options[
'indexes'] : array();
281 $options[
'indexes'] = array();
282 $sql = parent::_getCreateTableSQL($table, $columns, $options);
284 foreach ($columns as $name => $column) {
285 if (isset($column[
'sequence'])) {
289 if (isset($column[
'autoincrement']) && $column[
'autoincrement'] ||
290 (isset($column[
'autoinc']) && $column[
'autoinc'])) {
295 if (isset($indexes) && ! empty($indexes)) {
296 foreach ($indexes as $indexName => $index) {
312 $table = strtoupper($table);
314 return "SELECT uind.index_name AS name, " .
315 " uind.index_type AS type, " .
316 " decode( uind.uniqueness, 'NONUNIQUE', 0, 'UNIQUE', 1 ) AS is_unique, " .
317 " uind_col.column_name AS column_name, " .
318 " uind_col.column_position AS column_pos, " .
319 " (SELECT ucon.constraint_type FROM user_constraints ucon WHERE ucon.constraint_name = uind.index_name) AS is_primary ".
320 "FROM user_indexes uind, user_ind_columns uind_col " .
321 "WHERE uind.index_name = uind_col.index_name AND uind_col.table_name = '$table' ORDER BY uind_col.column_position ASC";
326 return 'SELECT * FROM sys.user_tables';
331 return 'SELECT view_name, text FROM sys.user_views';
336 return 'CREATE VIEW ' . $name .
' AS ' . $sql;
341 return 'DROP VIEW '. $name;
346 $table = strtoupper($table);
349 $indexName = $table .
'_AI_PK';
352 'columns' => array($name =>
true),
355 $idx = new \Doctrine\DBAL\Schema\Index($indexName, array($name),
true,
true);
358 constraints_Count NUMBER;
360 SELECT COUNT(CONSTRAINT_NAME) INTO constraints_Count FROM USER_CONSTRAINTS WHERE TABLE_NAME = \''.$table.
'\' AND CONSTRAINT_TYPE = \
'P\';
361 IF constraints_Count = 0 OR constraints_Count = \'\' THEN
362 EXECUTE IMMEDIATE \''.$this->getCreateConstraintSQL($idx, $table).
'\';
366 $sequenceName = $table . '_SEQ
';
367 $sequence = new \Doctrine\DBAL\Schema\Sequence($sequenceName, $start);
368 $sql[] = $this->getCreateSequenceSQL($sequence);
370 $triggerName = $table . '_AI_PK
';
371 $sql[] = 'CREATE TRIGGER
' . $triggerName . '
376 last_Sequence NUMBER;
377 last_InsertID NUMBER;
379 SELECT
' . $sequenceName . '.NEXTVAL INTO :NEW.
' . $name . ' FROM DUAL;
380 IF (:NEW.
' . $name . ' IS NULL OR :NEW.
'.$name.' = 0) THEN
381 SELECT
' . $sequenceName . '.NEXTVAL INTO :NEW.
' . $name . ' FROM DUAL;
383 SELECT NVL(Last_Number, 0) INTO last_Sequence
385 WHERE Sequence_Name = \
'' . $sequenceName .
'\';
386 SELECT :NEW.
' . $name . ' INTO last_InsertID FROM DUAL;
387 WHILE (last_InsertID > last_Sequence) LOOP
388 SELECT
' . $sequenceName . '.NEXTVAL INTO last_Sequence FROM DUAL;
395 public function getDropAutoincrementSql($table)
397 $table = strtoupper($table);
398 $trigger = $table . '_AI_PK
';
401 $sql[] = 'DROP TRIGGER
' . $trigger;
402 $sql[] = $this->getDropSequenceSQL($table.'_SEQ
');
404 $indexName = $table . '_AI_PK
';
405 $sql[] = $this->getDropConstraintSQL($indexName, $table);
411 public function getListTableForeignKeysSQL($table)
413 $table = strtoupper($table);
415 return "SELECT alc.constraint_name,
417 alc.search_condition,
418 cols.column_name \"local_column\",
420 r_alc.table_name \"references_table\",
421 r_cols.column_name \"foreign_column\"
422 FROM all_cons_columns cols
423LEFT JOIN all_constraints alc
424 ON alc.constraint_name = cols.constraint_name
425 AND alc.owner = cols.owner
426LEFT JOIN all_constraints r_alc
427 ON alc.r_constraint_name = r_alc.constraint_name
428 AND alc.r_owner = r_alc.owner
429LEFT JOIN all_cons_columns r_cols
430 ON r_alc.constraint_name = r_cols.constraint_name
431 AND r_alc.owner = r_cols.owner
432 AND cols.position = r_cols.position
433 WHERE alc.constraint_name = cols.constraint_name
434 AND alc.constraint_type = 'R
'
435 AND alc.table_name = '".$table."'";
438 public function getListTableConstraintsSQL($table)
440 $table = strtoupper($table);
441 return 'SELECT * FROM user_constraints WHERE table_name = \
'' . $table .
'\'';
446 $table = strtoupper($table);
447 return "SELECT * FROM all_tab_columns WHERE table_name = '" . $table .
"' ORDER BY column_name";
457 if ($sequence instanceof \Doctrine\DBAL\Schema\Sequence) {
458 $sequence = $sequence->getQuotedName($this);
461 return 'DROP SEQUENCE ' . $sequence;
472 $foreignKey = $foreignKey->getQuotedName($this);
475 if ($table instanceof \Doctrine\DBAL\Schema\
Table) {
476 $table = $table->getQuotedName($this);
479 return 'ALTER TABLE ' . $table .
' DROP CONSTRAINT ' . $foreignKey;
484 return 'DROP USER ' . $database .
' CASCADE';
504 foreach ($diff->addedColumns AS $column) {
507 if (count($fields)) {
508 $sql[] =
'ALTER TABLE ' . $diff->name .
' ADD (' . implode(
', ', $fields) .
')';
512 foreach ($diff->changedColumns AS $columnDiff) {
513 $column = $columnDiff->column;
516 if (count($fields)) {
517 $sql[] =
'ALTER TABLE ' . $diff->name .
' MODIFY (' . implode(
', ', $fields) .
')';
520 foreach ($diff->renamedColumns AS $oldColumnName => $column) {
521 $sql[] =
'ALTER TABLE ' . $diff->name .
' RENAME COLUMN ' . $oldColumnName .
' TO ' . $column->getQuotedName($this);
525 foreach ($diff->removedColumns AS $column) {
526 $fields[] = $column->getQuotedName($this);
528 if (count($fields)) {
529 $sql[] =
'ALTER TABLE ' . $diff->name .
' DROP COLUMN ' . implode(
', ', $fields);
532 if ($diff->newName !==
false) {
533 $sql[] =
'ALTER TABLE ' . $diff->name .
' RENAME TO ' . $diff->newName;
571 $limit = (int) $limit;
572 $offset = (int) $offset;
573 if (preg_match(
'/^\s*SELECT/i', $query)) {
574 if ( ! preg_match(
'/\sFROM\s/i', $query)) {
575 $query .=
" FROM dual";
578 $max = $offset + $limit;
582 $query =
'SELECT b.'.$column.
' FROM ('.
583 'SELECT a.*, ROWNUM AS doctrine_rownum FROM ('
586 'WHERE doctrine_rownum BETWEEN ' . $min .
' AND ' . $max;
588 $query =
'SELECT a.'.$column.
' FROM (' . $query .
') a WHERE ROWNUM <= ' . $max;
605 return strtoupper($column);
610 return "CREATE GLOBAL TEMPORARY TABLE";
615 return 'Y-m-d H:i:sP';
620 return 'Y-m-d 00:00:00';
625 return '1900-01-01 H:i:s';
630 if (strlen($schemaElementName) > 30) {
632 return substr($schemaElementName, 0, 30);
634 return $schemaElementName;
677 return 'TRUNCATE TABLE '.$tableName;
687 return 'SELECT 1 FROM DUAL';
692 $this->doctrineTypeMapping = array(
693 'integer' =>
'integer',
694 'number' =>
'integer',
695 'pls_integer' =>
'boolean',
696 'binary_integer' =>
'boolean',
697 'varchar' =>
'string',
698 'varchar2' =>
'string',
699 'nvarchar2' =>
'string',
702 'date' =>
'datetime',
703 'timestamp' =>
'datetime',
704 'timestamptz' =>
'datetimetz',