aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes/acp/acp_database.php
diff options
context:
space:
mode:
authorNils Adermann <naderman@naderman.de>2010-02-11 00:02:51 +0000
committerNils Adermann <naderman@naderman.de>2010-02-11 00:02:51 +0000
commit1802b9ff9286a7fc24493e71b3432816cbdbfcd8 (patch)
tree886dc576cb5a2be1d700372732446291479d483a /phpBB/includes/acp/acp_database.php
parent6c321c53a1ebd495518738157dc3a2bf8c0701e1 (diff)
downloadforums-1802b9ff9286a7fc24493e71b3432816cbdbfcd8.tar
forums-1802b9ff9286a7fc24493e71b3432816cbdbfcd8.tar.gz
forums-1802b9ff9286a7fc24493e71b3432816cbdbfcd8.tar.bz2
forums-1802b9ff9286a7fc24493e71b3432816cbdbfcd8.tar.xz
forums-1802b9ff9286a7fc24493e71b3432816cbdbfcd8.zip
Support for Microsoft's Native SQL Server Driver for PHP - Patch by Chris Pucci at Microsoft [Bug #57055]
If you are using SQL Server, please try to test this new dbal so we can safely include it in 3.0.8. If you want to try it on a current phpBB version you can apply the latest version of the patch to your board which you can find attached to the bug tracker ticket (look in the comments for the latest version, the one in the ticket itself is outdated): http://www.phpbb.com/bugs/phpbb3/ticket.php?ticket_id=57055 git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@10489 89ea8834-ac86-4346-8a33-228a782c2dd0
Diffstat (limited to 'phpBB/includes/acp/acp_database.php')
-rw-r--r--phpBB/includes/acp/acp_database.php102
1 files changed, 102 insertions, 0 deletions
diff --git a/phpBB/includes/acp/acp_database.php b/phpBB/includes/acp/acp_database.php
index 7b734da2af..abfad2b90b 100644
--- a/phpBB/includes/acp/acp_database.php
+++ b/phpBB/includes/acp/acp_database.php
@@ -109,6 +109,7 @@ class acp_database
case 'mssql':
case 'mssql_odbc':
+ case 'mssqlnative':
$extractor = new mssql_extractor($download, $store, $format, $filename, $time);
break;
@@ -138,6 +139,7 @@ class acp_database
case 'mssql':
case 'mssql_odbc':
+ case 'mssqlnative':
$extractor->flush('TRUNCATE TABLE ' . $table_name . "GO\n");
break;
@@ -1509,6 +1511,10 @@ class mssql_extractor extends base_extractor
{
$this->write_data_mssql($table_name);
}
+ else if($db->sql_layer === 'mssqlnative')
+ {
+ $this->write_data_mssqlnative($table_name);
+ }
else
{
$this->write_data_odbc($table_name);
@@ -1608,7 +1614,103 @@ class mssql_extractor extends base_extractor
}
$this->flush($sql_data);
}
+
+ function write_data_mssqlnative($table_name)
+ {
+ global $db;
+ $ary_type = $ary_name = $meta_array = array();
+ $ident_set = false;
+ $sql_data = '';
+
+ // Grab all of the data from current table.
+ $sql = "SELECT * FROM $table_name";
+ $result = $db->sql_query($sql);
+
+ $retrieved_data = $db->mssqlnative_num_rows($result);
+
+ $meta_array = sqlsrv_field_metadata($result);
+ $i_num_fields = sqlsrv_num_fields($result);
+
+ for ($i = 0; $i < $i_num_fields; $i++)
+ {
+ $info = $db->mssqlnative_fieldInfo($table_name, $meta_array[$i]['Name']);
+ $ary_type[$i] = $info->type();
+ $ary_name[$i] = $info->name();
+ }
+
+ if ($retrieved_data)
+ {
+ $sql = "SELECT 1 as has_identity
+ FROM INFORMATION_SCHEMA.COLUMNS
+ WHERE COLUMNPROPERTY(object_id('$table_name'), COLUMN_NAME, 'IsIdentity') = 1";
+ $result2 = $db->sql_query($sql);
+ $row2 = $db->sql_fetchrow($result2);
+
+ if (!empty($row2['has_identity']))
+ {
+ $sql_data .= "\nSET IDENTITY_INSERT $table_name ON\nGO\n";
+ $ident_set = true;
+ }
+ $db->sql_freeresult($result2);
+ }
+
+ while ($row = $db->sql_fetchrow($result))
+ {
+ $schema_vals = $schema_fields = array();
+ // Build the SQL statement to recreate the data.
+ for ($i = 0; $i < $i_num_fields; $i++)
+ {
+ $str_val = $row[$ary_name[$i]];
+
+ if (preg_match('#char|text|bool|varbinary#i', $ary_type[$i]))
+ {
+ $str_quote = '';
+ $str_empty = "''";
+ $str_val = sanitize_data_mssql(str_replace("'", "''", $str_val));
+ }
+ else if (preg_match('#date|timestamp#i', $ary_type[$i]))
+ {
+ if (empty($str_val))
+ {
+ $str_quote = '';
+ }
+ else
+ {
+ $str_quote = "'";
+ }
+ }
+ else
+ {
+ $str_quote = '';
+ $str_empty = 'NULL';
+ }
+
+ if (empty($str_val) && $str_val !== '0' && !(is_int($str_val) || is_float($str_val)))
+ {
+ $str_val = $str_empty;
+ }
+
+ $schema_vals[$i] = $str_quote . $str_val . $str_quote;
+ $schema_fields[$i] = $ary_name[$i];
+ }
+
+ // Take the ordered fields and their associated data and build it
+ // into a valid sql statement to recreate that field in the data.
+ $sql_data .= "INSERT INTO $table_name (" . implode(', ', $schema_fields) . ') VALUES (' . implode(', ', $schema_vals) . ");\nGO\n";
+
+ $this->flush($sql_data);
+ $sql_data = '';
+ }
+ $db->sql_freeresult($result);
+
+ if ($retrieved_data && $ident_set)
+ {
+ $sql_data .= "\nSET IDENTITY_INSERT $table_name OFF\nGO\n";
+ }
+ $this->flush($sql_data);
+ }
+
function write_data_odbc($table_name)
{
global $db;