blob: a0efa95ea8f124ee683a9015ba58c91847de8a50 [file] [log] [blame]
Andrey Andreevc5536aa2012-11-01 17:33:58 +02001<?php
Derek Allard2067d1a2008-11-13 22:59:24 +00002/**
3 * CodeIgniter
4 *
Phil Sturgeon07c1ac82012-03-09 17:03:37 +00005 * An open source application development framework for PHP 5.2.4 or newer
Derek Allard2067d1a2008-11-13 22:59:24 +00006 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -05007 * NOTICE OF LICENSE
Andrey Andreev24abcb92012-01-05 20:40:15 +02008 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -05009 * Licensed under the Open Software License version 3.0
Andrey Andreev24abcb92012-01-05 20:40:15 +020010 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -050011 * This source file is subject to the Open Software License (OSL 3.0) that is
Andrey Andreev342a4662012-01-24 15:24:00 +020012 * bundled with this package in the files license.txt / license.rst. It is
Derek Jonesf4a4bd82011-10-20 12:18:42 -050013 * also available through the world wide web at this URL:
14 * http://opensource.org/licenses/OSL-3.0
15 * If you did not receive a copy of the license and are unable to obtain it
16 * through the world wide web, please send an email to
17 * licensing@ellislab.com so we can send you a copy immediately.
18 *
Derek Allard2067d1a2008-11-13 22:59:24 +000019 * @package CodeIgniter
Derek Jonesf4a4bd82011-10-20 12:18:42 -050020 * @author EllisLab Dev Team
Greg Aker0defe5d2012-01-01 18:46:41 -060021 * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
Derek Jonesf4a4bd82011-10-20 12:18:42 -050022 * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
Derek Allard2067d1a2008-11-13 22:59:24 +000023 * @link http://codeigniter.com
24 * @since Version 1.0
25 * @filesource
26 */
Andrey Andreevc5536aa2012-11-01 17:33:58 +020027defined('BASEPATH') OR exit('No direct script access allowed');
Derek Allard2067d1a2008-11-13 22:59:24 +000028
Derek Allard2067d1a2008-11-13 22:59:24 +000029/**
30 * Oracle Forge Class
31 *
32 * @category Database
Derek Jonesf4a4bd82011-10-20 12:18:42 -050033 * @author EllisLab Dev Team
Derek Allard2067d1a2008-11-13 22:59:24 +000034 * @link http://codeigniter.com/user_guide/database/
35 */
36class CI_DB_oci8_forge extends CI_DB_forge {
37
Andrey Andreevc98e93a2012-11-02 02:04:59 +020038 /**
39 * CREATE DATABASE statement
40 *
41 * @var string
42 */
Andrey Andreevd947eba2012-04-09 14:58:28 +030043 protected $_create_database = FALSE;
Andrey Andreevc98e93a2012-11-02 02:04:59 +020044
45 /**
46 * DROP DATABASE statement
47 *
48 * @var string
49 */
Andrey Andreevd947eba2012-04-09 14:58:28 +030050 protected $_drop_database = FALSE;
Andrey Andreevc98e93a2012-11-02 02:04:59 +020051
52 /**
Andrey Andreeva287a342012-11-05 23:19:59 +020053 * DROP TABLE IF statement
Andrey Andreevc98e93a2012-11-02 02:04:59 +020054 *
55 * @var string
56 */
Andrey Andreeva287a342012-11-05 23:19:59 +020057 protected $_drop_table_if = FALSE;
58
59 /**
60 * UNSIGNED support
61 *
62 * @var bool|array
63 */
64 protected $_unsigned = FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +000065
Andrey Andreevc98e93a2012-11-02 02:04:59 +020066 // --------------------------------------------------------------------
67
Derek Allard2067d1a2008-11-13 22:59:24 +000068 /**
Andrey Andreeva287a342012-11-05 23:19:59 +020069 * ALTER TABLE
Derek Allard2067d1a2008-11-13 22:59:24 +000070 *
Andrey Andreeva287a342012-11-05 23:19:59 +020071 * @param string $alter_type ALTER type
72 * @param string $table Table name
73 * @param mixed $field Column definition
74 * @return string|string[]
Derek Allard2067d1a2008-11-13 22:59:24 +000075 */
Andrey Andreeva287a342012-11-05 23:19:59 +020076 protected function _alter_table($alter_type, $table, $field)
Derek Allard2067d1a2008-11-13 22:59:24 +000077 {
Andrey Andreeva287a342012-11-05 23:19:59 +020078 if ($alter_type === 'DROP')
Derek Allard2067d1a2008-11-13 22:59:24 +000079 {
Andrey Andreeva287a342012-11-05 23:19:59 +020080 return parent::_alter_table($alter_type, $table, $field);
81 }
82 elseif ($alter_type === 'CHANGE')
83 {
84 $alter_type = 'MODIFY';
Derek Allard2067d1a2008-11-13 22:59:24 +000085 }
Barry Mienydd671972010-10-04 16:33:58 +020086
Andrey Andreeva287a342012-11-05 23:19:59 +020087 $sql = 'ALTER TABLE '.$this->db->escape_identifiers($table);
88 $sqls = array();
89 for ($i = 0, $c = count($field); $i < $c; $i++)
Derek Allard2067d1a2008-11-13 22:59:24 +000090 {
Andrey Andreeva287a342012-11-05 23:19:59 +020091 if ($field[$i]['_literal'] !== FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +000092 {
Andrey Andreeva287a342012-11-05 23:19:59 +020093 $field[$i] = "\n\t".$field[$i]['_literal'];
Derek Allard2067d1a2008-11-13 22:59:24 +000094 }
95 else
96 {
Andrey Andreeva287a342012-11-05 23:19:59 +020097 $field[$i]['_literal'] = "\n\t".$this->_process_column($field[$i]);
98 if ($alter_type === 'MODIFY' && ! empty($field[$i]['new_name']))
Andrey Andreev5ef194d2012-06-08 01:12:54 +030099 {
Andrey Andreeva287a342012-11-05 23:19:59 +0200100 $sqls[] = $sql.' RENAME COLUMN '.$this->db->escape_identifiers($field[$i]['name'])
101 .' '.$this->db->escape_identifiers($field[$i]['new_name']);
Andrey Andreev5ef194d2012-06-08 01:12:54 +0300102 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000103 }
104 }
105
Andrey Andreeva287a342012-11-05 23:19:59 +0200106 $sql .= ' '.$alter_type.' ';
107 $sql .= (count($field) === 1)
Andrey Andreev7ade8b72012-11-22 13:12:22 +0200108 ? $field[0]
Andrey Andreeva287a342012-11-05 23:19:59 +0200109 : '('.implode(',', $field).')';
Derek Allard2067d1a2008-11-13 22:59:24 +0000110
Andrey Andreeva287a342012-11-05 23:19:59 +0200111 // RENAME COLUMN must be executed after MODIFY
112 array_unshift($sqls, $sql);
113 return $sql;
Derek Allard2067d1a2008-11-13 22:59:24 +0000114 }
115
116 // --------------------------------------------------------------------
117
118 /**
Andrey Andreeva287a342012-11-05 23:19:59 +0200119 * Field attribute AUTO_INCREMENT
Derek Allard2067d1a2008-11-13 22:59:24 +0000120 *
Andrey Andreeva287a342012-11-05 23:19:59 +0200121 * @param array &$attributes
122 * @param array &$field
123 * @return void
Derek Allard2067d1a2008-11-13 22:59:24 +0000124 */
Andrey Andreeva287a342012-11-05 23:19:59 +0200125 protected function _attr_auto_increment(&$attributes, &$field)
Derek Allard2067d1a2008-11-13 22:59:24 +0000126 {
Andrey Andreeva287a342012-11-05 23:19:59 +0200127 // Not supported - sequences and triggers must be used instead
Derek Allard2067d1a2008-11-13 22:59:24 +0000128 }
129
Derek Allard2067d1a2008-11-13 22:59:24 +0000130}
131
132/* End of file oci8_forge.php */
Timothy Warren215890b2012-03-20 09:38:16 -0400133/* Location: ./system/database/drivers/oci8/oci8_forge.php */