Details
-
Type:
Bug
-
Status:
Patch Needs Work
-
Priority:
Major
-
Resolution: Unresolved
-
Affects Version/s: 3.0.10
-
Fix Version/s: 3.0.13-RC1
-
Component/s: Database Abstraction Layer (DBAL)
-
Labels:None
-
GitHub Pull Request URL:
Description
The ACP statistics try to list the database size retrieved with 'SELECT ((SUM(size) * 8.0) * 1024.0) as dbsize FROM sysfiles' which does not work on Azure.
Relevant code from phpBB/includes/functions_admin.php:
case 'mssql': case 'mssql_odbc': case 'mssqlnative': $sql = 'SELECT ((SUM(size) * 8.0) * 1024.0) as dbsize FROM sysfiles'; $result = $db->sql_query($sql, 7200); $database_size = ($row = $db->sql_fetchrow($result)) ? $row['dbsize'] : false; $db->sql_freeresult($result); break;


sysfiles is not available in SQL Azure, but we can calculate the database size in SQL Azure using the following SQL query
SELECT ((SUM(reserved_page_count) * 8.0) * 1024.0) as dbsize FROM sys.dm_db_partition_stats;
So the fix is to check the particular SQL Server version and use the appropriate SQL Query.
Replace line no: 3079 - 3080 of includes/functions_admin.php with the below code:
$sql_version = ($row = $db->sql_fetchrow($db->sql_query('SELECT @@version as version'))) ? $row['version'] : false;
$sql = (strpos($sql_version, 'SQL Azure') !== false) ? 'SELECT ((SUM(reserved_page_count) * 8.0) * 1024.0) as dbsize FROM sys.dm_db_partition_stats' : 'SELECT ((SUM(size) * 8.0) * 1024.0) as dbsize FROM sysfiles';