summaryrefslogtreecommitdiffstats
path: root/system
diff options
context:
space:
mode:
authorblowdoof <blowdoof@gmail.com>2013-10-18 16:39:58 +0200
committerblowdoof <blowdoof@gmail.com>2013-10-18 16:39:58 +0200
commit84b053906da253dbe2fa63a409c2559f3af8ef69 (patch)
treedd02c7fcdb3dc274c4eb7ce8c27c983cc4b6e4a8 /system
parent898683f95b1b1344a9475647cfe2af285af5f163 (diff)
Bugfix on the sqlsrv forge driver create_table function
Diffstat (limited to 'system')
-rw-r--r--system/database/drivers/sqlsrv/sqlsrv_forge.php20
1 files changed, 9 insertions, 11 deletions
diff --git a/system/database/drivers/sqlsrv/sqlsrv_forge.php b/system/database/drivers/sqlsrv/sqlsrv_forge.php
index a5adcbe95..289dfa6ab 100644
--- a/system/database/drivers/sqlsrv/sqlsrv_forge.php
+++ b/system/database/drivers/sqlsrv/sqlsrv_forge.php
@@ -60,13 +60,10 @@ class CI_DB_sqlsrv_forge extends CI_DB_forge {
*/
function _drop_table($table)
{
- $sql = "IF (EXISTS (SELECT *
+ return = "IF (EXISTS (SELECT *
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = 'dbo'
- AND TABLE_NAME = '";
- $sql .= $this->db->_escape_identifiers($table)."')) DROP TABLE [dbo].[";
- $sql .= $this->db->_escape_identifiers($table).']';
- return $sql;
+ AND TABLE_NAME = '".$table."')) DROP TABLE [dbo].[".$table."]";
}
// --------------------------------------------------------------------
@@ -84,14 +81,15 @@ class CI_DB_sqlsrv_forge extends CI_DB_forge {
*/
function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists)
{
- $sql = 'CREATE TABLE ';
-
+ $sql = '';
if ($if_not_exists === TRUE)
{
- $sql .= 'IF NOT EXISTS ';
+ $sql = "IF (NOT EXISTS (SELECT *
+ FROM INFORMATION_SCHEMA.TABLES
+ WHERE TABLE_SCHEMA = 'dbo'
+ AND TABLE_NAME = ";
}
-
- $sql .= $this->db->_escape_identifiers($table)." (";
+ $sql .= $this->db->_escape_identifiers($table).")) CREATE TABLE ".$this->db->_escape_identifiers($table)." (";
$current_field_count = 0;
foreach ($fields as $field=>$attributes)
@@ -137,7 +135,7 @@ class CI_DB_sqlsrv_forge extends CI_DB_forge {
if (array_key_exists('AUTO_INCREMENT', $attributes) && $attributes['AUTO_INCREMENT'] === TRUE)
{
- $sql .= ' AUTO_INCREMENT';
+ $sql .= ' IDENTITY(1,1)';
}
}