Skip to content

Commit

Permalink
fix create.sql (problems with datetime conversion), not set to NULL
Browse files Browse the repository at this point in the history
DvVersionsManager and DatabaseUpdateProvider now can use different connstring and tabprefix
install wizard execute updateprovider on pigeoncms.core
  • Loading branch information
picce committed Dec 7, 2016
1 parent 17e0ea9 commit ff48c2c
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 20 deletions.
Binary file modified pigeoncms/Bin/PigeonCms.Core.dll
Binary file not shown.
24 changes: 17 additions & 7 deletions pigeoncms/pgn-admin/installation/Default.aspx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -364,13 +364,6 @@ private bool setData()
sResult = Database.ExecuteQuery(myRd, myCmd, sSql);

myTrans.Commit();

//20161201 picce
//upgrade PigeonCms.Core if needed
string upgradeLogResult = "";
var dbManProvider = new PigeonCms.DatabaseUpdateProvider("PigeonCms.Core");
dbManProvider.ApplyPendingUpdates(out upgradeLogResult);

}
catch (SqlException ex)
{
Expand All @@ -385,6 +378,23 @@ private bool setData()
myConn.Dispose();
}

if (res)
{
//20161201 picce
//upgrade PigeonCms.Core if needed
string upgradeLogResult = "";
var dbManProvider = new PigeonCms.DatabaseUpdateProvider("PigeonCms.Core");
dbManProvider.ConnString = getConnString();
dbManProvider.TabPrefix = TxtTablesPrefix.Text;
res = dbManProvider.ApplyPendingUpdates(out upgradeLogResult);

if (!res)
{
LblErr.Text += "Error upgrading PigeonCms.Core database<br />";
LblErr.Text += upgradeLogResult + "<br />";
}
}

//set custom data with direct sql because web.config settings reload at next request
if (res)
{
Expand Down
Binary file modified pigeoncms/pgn-admin/installation/sql/create.sql
Binary file not shown.
50 changes: 40 additions & 10 deletions projects/PigeonCms.Core/DAL/DbVersionsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,36 @@ public class DbVersionsManager :
{
private string componentFullName = "";

private string _connString = "";
public string ConnString {
get
{
if (string.IsNullOrEmpty(_connString))
_connString = Database.ConnString;

return _connString;
}

set { _connString = value; }
}

private string _tabPrefix = "";
public string TabPrefix
{
get
{
if (string.IsNullOrEmpty(_tabPrefix))
_tabPrefix = Config.TabPrefix;

return _tabPrefix;
}

set
{
_tabPrefix = value;
}
}

[DebuggerStepThrough()]
public DbVersionsManager(string componentFullName)
{
Expand All @@ -35,7 +65,7 @@ public DbVersionsManager(string componentFullName)

try
{
myConn.ConnectionString = Database.ConnString;
myConn.ConnectionString = this.ConnString;
myConn.Open();

if (!string.IsNullOrEmpty(componentFullName))
Expand Down Expand Up @@ -65,7 +95,7 @@ public DbVersionsManager(string componentFullName)
}

result = (List<PigeonCms.DbVersion>)myConn.Query
<PigeonCms.DbVersion>(Database.ParseSql(sSql), p);
<PigeonCms.DbVersion>(Database.ParseSql(sSql, this.TabPrefix), p);
}
finally
{
Expand All @@ -83,15 +113,15 @@ public int GetLastVersionId()

try
{
myConn.ConnectionString = Database.ConnString;
myConn.ConnectionString = this.ConnString;
myConn.Open();

string sSql = "SELECT MAX(versionId)maxVersion "
+ " FROM [" + this.TableName + "] "
+ " WHERE ComponentFullName=@ComponentFullName ";

p.Add("ComponentFullName", componentFullName, null, null, null);
res = (int)myConn.ExecuteScalar<decimal>(Database.ParseSql(sSql), p, null, null, null);
res = (int)myConn.ExecuteScalar<decimal>(Database.ParseSql(sSql, this.TabPrefix), p, null, null, null);
}
finally
{
Expand Down Expand Up @@ -135,7 +165,7 @@ public override int Update(DbVersion theObj)

try
{
myConn.ConnectionString = Database.ConnString;
myConn.ConnectionString = this.ConnString;
myConn.Open();

sSql = "UPDATE [" + this.TableName + "] "
Expand All @@ -154,7 +184,7 @@ public override int Update(DbVersion theObj)
p.Add("DateUpdated", theObj.DateUpdated, null, null, null);
p.Add("UserUpdated", theObj.UserUpdated, null, null, null);

result = myConn.Execute(Database.ParseSql(sSql), p);
result = myConn.Execute(Database.ParseSql(sSql, this.TabPrefix), p);
}
finally
{
Expand All @@ -176,7 +206,7 @@ public override DbVersion Insert(DbVersion theObj)

try
{
myConn.ConnectionString = Database.ConnString;
myConn.ConnectionString = this.ConnString;
myConn.Open();

sSql = "INSERT INTO [" + this.TableName + "]"
Expand All @@ -193,7 +223,7 @@ public override DbVersion Insert(DbVersion theObj)
p.Add("DateUpdated", theObj.DateUpdated, null, null, null);
p.Add("UserUpdated", theObj.UserUpdated, null, null, null);

int count = myConn.Execute(Database.ParseSql(sSql), p);
int count = myConn.Execute(Database.ParseSql(sSql, this.TabPrefix), p);
}
finally
{
Expand All @@ -215,7 +245,7 @@ public override int DeleteById(int versionId)
{
var currObj = this.GetByKey(versionId);

myConn.ConnectionString = Database.ConnString;
myConn.ConnectionString = this.ConnString;
myConn.Open();

sSql = "DELETE FROM [" + this.TableName + "] "
Expand All @@ -224,7 +254,7 @@ public override int DeleteById(int versionId)
p.Add("ComponentFullName", componentFullName, null, null, null);
p.Add("VersionId", versionId, null, null, null);

myConn.Execute(Database.ParseSql(sSql), p);
myConn.Execute(Database.ParseSql(sSql, this.TabPrefix), p);
}
finally
{
Expand Down
58 changes: 55 additions & 3 deletions projects/PigeonCms.Core/Providers/DatabaseUpdateProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,47 @@ public class DatabaseUpdateProvider
private DbVersionsManager dbVersionMan;
private PigeonCms.Module fakeModule;

//writeLog is =false if DatabaseUpdateProvider is called during installation wizard to avoid sql error
private bool writeLog = true;

private string _connString = "";
public string ConnString
{
get
{
if (string.IsNullOrEmpty(_connString))
_connString = Database.ConnString;

return _connString;
}

set
{
_connString = value;
dbVersionMan.ConnString = this.ConnString;
writeLog = false;
}
}

private string _tabPrefix = "";
public string TabPrefix
{
get
{
if (string.IsNullOrEmpty(_tabPrefix))
_tabPrefix = Config.TabPrefix;

return _tabPrefix;
}

set
{
_tabPrefix = value;
dbVersionMan.TabPrefix = this.TabPrefix;
writeLog = false;
}
}


private string componentFullName = "";
public string ComponentFullName
Expand Down Expand Up @@ -93,6 +134,14 @@ public DatabaseUpdateProvider(string componentFullName = "PigeonCms.Core")

this.componentFullName = componentFullName;


//this.connString = Database.ConnString;
//if (!string.IsNullOrEmpty(connString))
//{
// //connstring as parameter to allow updates during installation wizard (we still dont have saved connstring)
// this.connString = connString;
//}

dbVersionMan = new DbVersionsManager(this.ComponentFullName);

fakeModule = new PigeonCms.Module();
Expand Down Expand Up @@ -146,7 +195,7 @@ public bool ApplyPendingUpdates(out string logResult)
try
{
//execute sql with transation
myConn.ConnectionString = Database.ConnString;
myConn.ConnectionString = this.ConnString;
myConn.Open();
myCmd.Connection = myConn;

Expand Down Expand Up @@ -187,8 +236,11 @@ public bool ApplyPendingUpdates(out string logResult)
.Replace("[[res]]", res.ToString())
.Replace("[[summary]]", qryResult);

LogProvider.Write(fakeModule, logResult,
(res ? TracerItemType.Info : TracerItemType.Error));
if (writeLog)
{
LogProvider.Write(fakeModule, logResult,
(res ? TracerItemType.Info : TracerItemType.Error));
}

return res;
}
Expand Down

0 comments on commit ff48c2c

Please sign in to comment.