Fixes U4-688 - 4.8.1 can't upgrade using SQLCE

(Also preparation for resolving U4-677 - SQLCE Medium Trust)
This commit is contained in:
leekelleher
2012-08-24 13:56:39 -01:00
parent e9e598d32c
commit bf5c3bf5ae
2 changed files with 33 additions and 14 deletions

View File

@@ -16,7 +16,6 @@ using System.Diagnostics;
using umbraco.DataLayer;
using umbraco.DataLayer.SqlHelpers.SqlServer;
namespace SqlCE4Umbraco
{
/// <summary>
@@ -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<string>();
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
}
}
}
}
}
}
/// <summary>
/// Replaces the data directory with a local path.
/// </summary>
/// <param name="path">The path.</param>
/// <returns>A local path with the resolved 'DataDirectory' mapping.</returns>
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;
}
/// <summary>
/// Creates a new parameter for use with this specific implementation of ISqlHelper.
/// </summary>