123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151 |
- <?php
- defined('BASEPATH') OR exit('No direct script access allowed');
- class CI_DB_mssql_forge extends CI_DB_forge {
-
- protected $_create_table_if = "IF NOT EXISTS (SELECT * FROM sysobjects WHERE ID = object_id(N'%s') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)\nCREATE TABLE";
-
- protected $_drop_table_if = "IF EXISTS (SELECT * FROM sysobjects WHERE ID = object_id(N'%s') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)\nDROP TABLE";
-
- protected $_unsigned = array(
- 'TINYINT' => 'SMALLINT',
- 'SMALLINT' => 'INT',
- 'INT' => 'BIGINT',
- 'REAL' => 'FLOAT'
- );
-
-
- protected function _alter_table($alter_type, $table, $field)
- {
- if (in_array($alter_type, array('ADD', 'DROP'), TRUE))
- {
- return parent::_alter_table($alter_type, $table, $field);
- }
- $sql = 'ALTER TABLE '.$this->db->escape_identifiers($table).' ALTER COLUMN ';
- $sqls = array();
- for ($i = 0, $c = count($field); $i < $c; $i++)
- {
- $sqls[] = $sql.$this->_process_column($field[$i]);
- }
- return $sqls;
- }
-
-
- protected function _attr_type(&$attributes)
- {
- if (isset($attributes['CONSTRAINT']) && strpos($attributes['TYPE'], 'INT') !== FALSE)
- {
- unset($attributes['CONSTRAINT']);
- }
- switch (strtoupper($attributes['TYPE']))
- {
- case 'MEDIUMINT':
- $attributes['TYPE'] = 'INTEGER';
- $attributes['UNSIGNED'] = FALSE;
- return;
- case 'INTEGER':
- $attributes['TYPE'] = 'INT';
- return;
- default: return;
- }
- }
-
-
- protected function _attr_auto_increment(&$attributes, &$field)
- {
- if ( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE && stripos($field['type'], 'int') !== FALSE)
- {
- $field['auto_increment'] = ' IDENTITY(1,1)';
- }
- }
- }
|