summaryrefslogtreecommitdiffstats
path: root/system
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 /system
parent533bf8f526be37954a2987e09df2be1c40ba49ba (diff)
parent3a2cceaa54fd4d55eda5fe07bb428350a08e2288 (diff)
Merge pull request #2689 from blowdoof/upstream_21
Bugfix 2.1 sqlsrv driver
Diffstat (limited to 'system')
-rw-r--r--system/database/drivers/sqlsrv/sqlsrv_driver.php2
-rw-r--r--system/database/drivers/sqlsrv/sqlsrv_forge.php26
2 files changed, 15 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