From 508aa787c1203a42d1103617bba122e312bd5088 Mon Sep 17 00:00:00 2001 From: tino Date: Fri, 18 Oct 2013 10:26:05 +0200 Subject: Bugfix on truncate command --- system/database/drivers/sqlsrv/sqlsrv_driver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/database/drivers/sqlsrv/sqlsrv_driver.php b/system/database/drivers/sqlsrv/sqlsrv_driver.php index 400fd31c6..e6f37778c 100644 --- a/system/database/drivers/sqlsrv/sqlsrv_driver.php +++ b/system/database/drivers/sqlsrv/sqlsrv_driver.php @@ -536,7 +536,7 @@ class CI_DB_sqlsrv_driver extends CI_DB { */ function _truncate($table) { - return "TRUNCATE ".$table; + return "TRUNCATE TABLE ".$table; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 6f52325abecad238b4c0a3097b0d849bf685adce Mon Sep 17 00:00:00 2001 From: tino Date: Fri, 18 Oct 2013 11:21:47 +0200 Subject: Fix on sqlsrv_forge drop_table --- system/database/drivers/sqlsrv/sqlsrv_forge.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/system/database/drivers/sqlsrv/sqlsrv_forge.php b/system/database/drivers/sqlsrv/sqlsrv_forge.php index cc88ec5ca..d800c5074 100644 --- a/system/database/drivers/sqlsrv/sqlsrv_forge.php +++ b/system/database/drivers/sqlsrv/sqlsrv_forge.php @@ -60,7 +60,14 @@ class CI_DB_sqlsrv_forge extends CI_DB_forge { */ function _drop_table($table) { - return "DROP TABLE ".$this->db->_escape_identifiers($table); + $sql = ''; + $sql = "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; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 1f71da710a84e6bf2d348bd17ffcc7b5023f13c9 Mon Sep 17 00:00:00 2001 From: blowdoof Date: Fri, 18 Oct 2013 15:58:04 +0200 Subject: Style correction --- system/database/drivers/sqlsrv/sqlsrv_forge.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/system/database/drivers/sqlsrv/sqlsrv_forge.php b/system/database/drivers/sqlsrv/sqlsrv_forge.php index d800c5074..2940beb9b 100644 --- a/system/database/drivers/sqlsrv/sqlsrv_forge.php +++ b/system/database/drivers/sqlsrv/sqlsrv_forge.php @@ -61,12 +61,12 @@ class CI_DB_sqlsrv_forge extends CI_DB_forge { function _drop_table($table) { $sql = ''; - $sql = "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).']'; + $sql = "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; } -- cgit v1.2.3-24-g4f1b From 898683f95b1b1344a9475647cfe2af285af5f163 Mon Sep 17 00:00:00 2001 From: blowdoof Date: Fri, 18 Oct 2013 16:08:08 +0200 Subject: removed unnecessary assignment --- system/database/drivers/sqlsrv/sqlsrv_forge.php | 1 - 1 file changed, 1 deletion(-) diff --git a/system/database/drivers/sqlsrv/sqlsrv_forge.php b/system/database/drivers/sqlsrv/sqlsrv_forge.php index 2940beb9b..a5adcbe95 100644 --- a/system/database/drivers/sqlsrv/sqlsrv_forge.php +++ b/system/database/drivers/sqlsrv/sqlsrv_forge.php @@ -60,7 +60,6 @@ class CI_DB_sqlsrv_forge extends CI_DB_forge { */ function _drop_table($table) { - $sql = ''; $sql = "IF (EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'dbo' -- cgit v1.2.3-24-g4f1b From 84b053906da253dbe2fa63a409c2559f3af8ef69 Mon Sep 17 00:00:00 2001 From: blowdoof Date: Fri, 18 Oct 2013 16:39:58 +0200 Subject: Bugfix on the sqlsrv forge driver create_table function --- system/database/drivers/sqlsrv/sqlsrv_forge.php | 20 +++++++++----------- 1 file 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)'; } } -- cgit v1.2.3-24-g4f1b From 18d6090a7ead8c93d2513e3b034cd1a994ed3c2f Mon Sep 17 00:00:00 2001 From: blowdoof Date: Fri, 18 Oct 2013 16:42:53 +0200 Subject: Bugfix on the sqlsrv forge driver rename_table function --- system/database/drivers/sqlsrv/sqlsrv_forge.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/system/database/drivers/sqlsrv/sqlsrv_forge.php b/system/database/drivers/sqlsrv/sqlsrv_forge.php index 289dfa6ab..e65e46116 100644 --- a/system/database/drivers/sqlsrv/sqlsrv_forge.php +++ b/system/database/drivers/sqlsrv/sqlsrv_forge.php @@ -241,12 +241,10 @@ class CI_DB_sqlsrv_forge extends CI_DB_forge { */ function _rename_table($table_name, $new_table_name) { - // I think this syntax will work, but can find little documentation on renaming tables in MSSQL - $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table_name)." RENAME TO ".$this->db->_protect_identifiers($new_table_name); - return $sql; + return 'EXEC sp_rename '.$this->db->_protect_identifiers($table_name).", ".$this->db->_protect_identifiers($new_table_name); } } -/* End of file mssql_forge.php */ -/* Location: ./system/database/drivers/mssql/mssql_forge.php */ \ No newline at end of file +/* End of file sqlsrv_forge.php */ +/* Location: ./system/database/drivers/sqlsrv/sqlsrv_forge.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 2cfbfc54dc68d9e7ed7c20af4cf7693736bbd447 Mon Sep 17 00:00:00 2001 From: blowdoof Date: Fri, 18 Oct 2013 16:46:09 +0200 Subject: Bugfix on the active record join statement with empty conditions --- system/database/DB_active_rec.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index 129eaa7b6..5bf0d8f1d 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -336,8 +336,12 @@ class CI_DB_active_record extends CI_DB_driver { $cond = $match[1].$match[2].$match[3]; } - // Assemble the JOIN statement - $join = $type.'JOIN '.$this->_protect_identifiers($table, TRUE, NULL, FALSE).' ON '.$cond; + // Assemble the JOIN statement: only use ON if a condition was passed + $join = $type.'JOIN '.$this->_protect_identifiers($table, TRUE, NULL, FALSE); + if ($cond) + { + $join .= ' ON '.$cond; + } $this->ar_join[] = $join; if ($this->ar_caching === TRUE) -- cgit v1.2.3-24-g4f1b From be4ee57160b51a0640a7c8b460f868f594e06ffc Mon Sep 17 00:00:00 2001 From: blowdoof Date: Fri, 18 Oct 2013 20:14:09 +0200 Subject: Revert "Bugfix on the active record join statement with empty conditions" This reverts commit 2cfbfc54dc68d9e7ed7c20af4cf7693736bbd447. --- system/database/DB_active_rec.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index 5bf0d8f1d..b1d56b7ec 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -337,11 +337,7 @@ class CI_DB_active_record extends CI_DB_driver { } // Assemble the JOIN statement: only use ON if a condition was passed - $join = $type.'JOIN '.$this->_protect_identifiers($table, TRUE, NULL, FALSE); - if ($cond) - { - $join .= ' ON '.$cond; - } + $join = $type.'JOIN '.$this->_protect_identifiers($table, TRUE, NULL, FALSE).' ON '.$cond; $this->ar_join[] = $join; if ($this->ar_caching === TRUE) -- cgit v1.2.3-24-g4f1b From 149412915c0ab247cbe84420d52940b1c6b0df7a Mon Sep 17 00:00:00 2001 From: blowdoof Date: Fri, 18 Oct 2013 20:14:09 +0200 Subject: Revert "Bugfix on the active record join statement with empty conditions" This reverts commit 2cfbfc54dc68d9e7ed7c20af4cf7693736bbd447. --- system/database/DB_active_rec.php | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index 5bf0d8f1d..129eaa7b6 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -336,12 +336,8 @@ class CI_DB_active_record extends CI_DB_driver { $cond = $match[1].$match[2].$match[3]; } - // Assemble the JOIN statement: only use ON if a condition was passed - $join = $type.'JOIN '.$this->_protect_identifiers($table, TRUE, NULL, FALSE); - if ($cond) - { - $join .= ' ON '.$cond; - } + // Assemble the JOIN statement + $join = $type.'JOIN '.$this->_protect_identifiers($table, TRUE, NULL, FALSE).' ON '.$cond; $this->ar_join[] = $join; if ($this->ar_caching === TRUE) -- cgit v1.2.3-24-g4f1b From 3a2cceaa54fd4d55eda5fe07bb428350a08e2288 Mon Sep 17 00:00:00 2001 From: blowdoof Date: Fri, 18 Oct 2013 20:31:46 +0200 Subject: Added changelog entries --- user_guide/changelog.html | 1 + 1 file changed, 1 insertion(+) diff --git a/user_guide/changelog.html b/user_guide/changelog.html index e97b472be..f6384fb1a 100644 --- a/user_guide/changelog.html +++ b/user_guide/changelog.html @@ -75,6 +75,7 @@ Change Log
  • Fixed a bug (#2021) - Migrations Library configuration file was mistakenly using Windows style line feeds.
  • Fixed a bug (#1273) - Active Record method set_update_batch() was using the incorrect variables and would cause an error.
  • Fixed a bug (#2337) - Email Library method print_debugger() was not using htmlspecialchars() when being shown in the browser.
  • +
  • Fixed a bug (#2689) - Database Forge Class methods create_table(), drop_table() and rename_table() were incorrect using the sqlsrv driver.
  • -- cgit v1.2.3-24-g4f1b