Core/src/Database/drivers/oci8/oci8_forge.php

147 lines
3.5 KiB
PHP

<?php
/**
* FuzeWorks.
*
* The FuzeWorks MVC PHP FrameWork
*
* Copyright (C) 2015 TechFuze
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @author TechFuze
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
*
* @link http://techfuze.net/fuzeworks
* @since Version 0.0.1
*
* @version Version 1.0.0
*/
/**
* Oracle Forge Class
*
* Converted from CodeIgniter.
*
* @package FuzeWorks
* @category Database
* @author EllisLab Dev Team
* @link https://codeigniter.com/user_guide/database/
* @license http://opensource.org/licenses/MIT MIT License
*/
class FW_DB_oci8_forge extends FW_DB_forge {
/**
* CREATE DATABASE statement
*
* @var string
*/
protected $_create_database = FALSE;
/**
* DROP DATABASE statement
*
* @var string
*/
protected $_drop_database = FALSE;
/**
* DROP TABLE IF statement
*
* @var string
*/
protected $_drop_table_if = FALSE;
/**
* UNSIGNED support
*
* @var bool|array
*/
protected $_unsigned = FALSE;
// --------------------------------------------------------------------
/**
* ALTER TABLE
*
* @param string $alter_type ALTER type
* @param string $table Table name
* @param mixed $field Column definition
* @return string|string[]
*/
protected function _alter_table($alter_type, $table, $field)
{
if ($alter_type === 'DROP')
{
return parent::_alter_table($alter_type, $table, $field);
}
elseif ($alter_type === 'CHANGE')
{
$alter_type = 'MODIFY';
}
$sql = 'ALTER TABLE '.$this->db->escape_identifiers($table);
$sqls = array();
for ($i = 0, $c = count($field); $i < $c; $i++)
{
if ($field[$i]['_literal'] !== FALSE)
{
$field[$i] = "\n\t".$field[$i]['_literal'];
}
else
{
$field[$i]['_literal'] = "\n\t".$this->_process_column($field[$i]);
if ( ! empty($field[$i]['comment']))
{
$sqls[] = 'COMMENT ON COLUMN '
.$this->db->escape_identifiers($table).'.'.$this->db->escape_identifiers($field[$i]['name'])
.' IS '.$field[$i]['comment'];
}
if ($alter_type === 'MODIFY' && ! empty($field[$i]['new_name']))
{
$sqls[] = $sql.' RENAME COLUMN '.$this->db->escape_identifiers($field[$i]['name'])
.' '.$this->db->escape_identifiers($field[$i]['new_name']);
}
}
}
$sql .= ' '.$alter_type.' ';
$sql .= (count($field) === 1)
? $field[0]
: '('.implode(',', $field).')';
// RENAME COLUMN must be executed after MODIFY
array_unshift($sqls, $sql);
return $sql;
}
// --------------------------------------------------------------------
/**
* Field attribute AUTO_INCREMENT
*
* @param array &$attributes
* @param array &$field
* @return void
*/
protected function _attr_auto_increment(&$attributes, &$field)
{
// Not supported - sequences and triggers must be used instead
}
}