summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrey Andreev <narf@devilix.net>2013-10-18 21:00:58 +0200
committerAndrey Andreev <narf@devilix.net>2013-10-18 21:00:58 +0200
commit0704ff23c246828118a61551d51387a1e3275a4b (patch)
tree24b260f146ac17c83f123ad3ad81f132bfbbf3ff
parent533bf8f526be37954a2987e09df2be1c40ba49ba (diff)
parent3a2cceaa54fd4d55eda5fe07bb428350a08e2288 (diff)
Merge pull request #2689 from blowdoof/upstream_21
Bugfix 2.1 sqlsrv driver
-rw-r--r--system/database/drivers/sqlsrv/sqlsrv_driver.php2
-rw-r--r--system/database/drivers/sqlsrv/sqlsrv_forge.php26
-rw-r--r--user_guide/changelog.html1
3 files changed, 16 insertions, 13 deletions
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;
}
// --------------------------------------------------------------------
diff --git a/system/database/drivers/sqlsrv/sqlsrv_forge.php b/system/database/drivers/sqlsrv/sqlsrv_forge.php
index cc88ec5ca..e65e46116 100644
--- a/system/database/drivers/sqlsrv/sqlsrv_forge.php
+++ b/system/database/drivers/sqlsrv/sqlsrv_forge.php
@@ -60,7 +60,10 @@ class CI_DB_sqlsrv_forge extends CI_DB_forge {
*/
function _drop_table($table)
{
- return "DROP TABLE ".$this->db->_escape_identifiers($table);
+ return = "IF (EXISTS (SELECT *
+ FROM INFORMATION_SCHEMA.TABLES
+ WHERE TABLE_SCHEMA = 'dbo'
+ AND TABLE_NAME = '".$table."')) DROP TABLE [dbo].[".$table."]";
}
// --------------------------------------------------------------------
@@ -78,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)
@@ -131,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)';
}
}
@@ -237,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
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
<li>Fixed a bug (#2021) - <a href="libraries/migration.html">Migrations Library</a> configuration file was mistakenly using Windows style line feeds.</li>
<li>Fixed a bug (#1273) - <a href="database/active_record.html">Active Record</a> method <samp>set_update_batch()</samp> was using the incorrect variables and would cause an error.</li>
<li>Fixed a bug (#2337) - <a href="libraries/email.html">Email Library</a> method <samp>print_debugger()</samp> was not using <samp>htmlspecialchars()</samp> when being shown in the browser.</li>
+ <li>Fixed a bug (#2689) - <a href="database/forge.html">Database Forge Class</a> methods <samp>create_table()</samp>, <samp>drop_table()</samp> and <samp>rename_table()</samp> were incorrect using the sqlsrv driver.</li>
</ul>