From bf5c3bf5ae43aab3b6004e831ae95f44bc611bb2 Mon Sep 17 00:00:00 2001 From: leekelleher Date: Fri, 24 Aug 2012 13:56:39 -0100 Subject: [PATCH] Fixes U4-688 - 4.8.1 can't upgrade using SQLCE (Also preparation for resolving U4-677 - SQLCE Medium Trust) --- src/SQLCE4Umbraco/SqlCEHelper.cs | 27 +++++++++++++++---- .../Installer/DefaultInstallerUtility.cs | 20 +++++++------- 2 files changed, 33 insertions(+), 14 deletions(-) diff --git a/src/SQLCE4Umbraco/SqlCEHelper.cs b/src/SQLCE4Umbraco/SqlCEHelper.cs index 665106d58f..3c66f9a5f2 100644 --- a/src/SQLCE4Umbraco/SqlCEHelper.cs +++ b/src/SQLCE4Umbraco/SqlCEHelper.cs @@ -16,7 +16,6 @@ using System.Diagnostics; using umbraco.DataLayer; using umbraco.DataLayer.SqlHelpers.SqlServer; - namespace SqlCE4Umbraco { /// @@ -39,7 +38,7 @@ namespace SqlCE4Umbraco internal void CreateEmptyDatabase() { var localConnection = new SqlCeConnection(ConnectionString); - if (!System.IO.File.Exists(localConnection.Database)) + if (!System.IO.File.Exists(ReplaceDataDirectory(localConnection.Database))) { var sqlCeEngine = new SqlCeEngine(ConnectionString); sqlCeEngine.CreateDatabase(); @@ -52,8 +51,7 @@ namespace SqlCE4Umbraco internal void ClearDatabase() { var localConnection = new SqlCeConnection(ConnectionString); - var dbFile = localConnection.Database; - if (System.IO.File.Exists(dbFile)) + if (!System.IO.File.Exists(ReplaceDataDirectory(localConnection.Database))) { var tables = new List(); using (var reader = ExecuteReader("select table_name from information_schema.tables where TABLE_TYPE <> 'VIEW'")) @@ -80,10 +78,29 @@ namespace SqlCE4Umbraco //this will occur because there is no cascade option, so we just wanna try the next one } } - } + } } } + /// + /// Replaces the data directory with a local path. + /// + /// The path. + /// A local path with the resolved 'DataDirectory' mapping. + private string ReplaceDataDirectory(string path) + { + if (!string.IsNullOrWhiteSpace(path) && path.Contains("|DataDirectory|")) + { + var dataDirectory = AppDomain.CurrentDomain.GetData("DataDirectory") as string; + if (!string.IsNullOrEmpty(dataDirectory)) + { + path = path.Replace("|DataDirectory|", dataDirectory); + } + } + + return path; + } + /// /// Creates a new parameter for use with this specific implementation of ISqlHelper. /// diff --git a/src/umbraco.datalayer/Utility/Installer/DefaultInstallerUtility.cs b/src/umbraco.datalayer/Utility/Installer/DefaultInstallerUtility.cs index 882dbe19fa..16c51bae78 100644 --- a/src/umbraco.datalayer/Utility/Installer/DefaultInstallerUtility.cs +++ b/src/umbraco.datalayer/Utility/Installer/DefaultInstallerUtility.cs @@ -196,17 +196,19 @@ namespace umbraco.DataLayer.Utility.Installer { if(v.ExpectedRows > -1) { - var reader = SqlHelper.ExecuteReader(v.Sql); - var rowCount = 0; - - if(reader.HasRecords) + using (var reader = SqlHelper.ExecuteReader(v.Sql)) { - while (reader.Read()) - rowCount++; - } + var rowCount = 0; - if (v.ExpectedRows != rowCount) - continue; + //if (reader.HasRecords) + //{ + while (reader.Read()) + rowCount++; + //} + + if (v.ExpectedRows != rowCount) + continue; + } } else {