From c2eeff6e47cdad4c8842dfcf383d544c14c1ddbf Mon Sep 17 00:00:00 2001 From: Stephan Date: Thu, 8 Sep 2016 10:37:03 +0200 Subject: [PATCH 1/3] U4-8954 - fix WhereIn issue with non-value-types --- .../Persistence/PetaPocoSqlExtensions.cs | 34 ++++++++++-------- .../Persistence/PetaPocoExpresionsTests.cs | 36 +++++++++++++++++++ src/Umbraco.Tests/Umbraco.Tests.csproj | 1 + .../config/umbracoSettings.config | 7 ++-- 4 files changed, 59 insertions(+), 19 deletions(-) create mode 100644 src/Umbraco.Tests/Persistence/PetaPocoExpresionsTests.cs diff --git a/src/Umbraco.Core/Persistence/PetaPocoSqlExtensions.cs b/src/Umbraco.Core/Persistence/PetaPocoSqlExtensions.cs index 04f4147155..f5c0e0e616 100644 --- a/src/Umbraco.Core/Persistence/PetaPocoSqlExtensions.cs +++ b/src/Umbraco.Core/Persistence/PetaPocoSqlExtensions.cs @@ -34,11 +34,27 @@ namespace Umbraco.Core.Persistence return sql.Where(whereExpression, expresionist.GetSqlParameters()); } + private static string GetFieldName(Expression> fieldSelector, ISqlSyntaxProvider sqlSyntax) + { + var field = ExpressionHelper.FindProperty(fieldSelector) as PropertyInfo; + var fieldName = field.GetColumnName(); + + var type = typeof(T); + var tableName = type.GetTableName(); + + return sqlSyntax.GetQuotedTableName(tableName) + "." + sqlSyntax.GetQuotedColumnName(fieldName); + } + + [Obsolete("Use the overload specifying ISqlSyntaxProvider instead")] public static Sql WhereIn(this Sql sql, Expression> fieldSelector, IEnumerable values) { - var expresionist = new PocoToSqlExpressionHelper(); - var fieldExpression = expresionist.Visit(fieldSelector); - return sql.Where(fieldExpression + " IN (@values)", new {@values = values}); + return sql.WhereIn(fieldSelector, values, SqlSyntaxContext.SqlSyntaxProvider); + } + + public static Sql WhereIn(this Sql sql, Expression> fieldSelector, IEnumerable values, ISqlSyntaxProvider sqlSyntax) + { + var fieldName = GetFieldName(fieldSelector, sqlSyntax); + return sql.Where(fieldName + " IN (@values)", new { values }); } [Obsolete("Use the overload specifying ISqlSyntaxProvider instead")] @@ -49,17 +65,7 @@ namespace Umbraco.Core.Persistence public static Sql OrderBy(this Sql sql, Expression> columnMember, ISqlSyntaxProvider sqlSyntax) { - var column = ExpressionHelper.FindProperty(columnMember) as PropertyInfo; - var columnName = column.GetColumnName(); - - var type = typeof(TColumn); - var tableName = type.GetTableName(); - - //need to ensure the order by is in brackets, see: https://github.com/toptensoftware/PetaPoco/issues/177 - var syntax = string.Format("({0}.{1})", - sqlSyntax.GetQuotedTableName(tableName), - sqlSyntax.GetQuotedColumnName(columnName)); - + var syntax = "(" + GetFieldName(columnMember, sqlSyntax) + ")"; return sql.OrderBy(syntax); } diff --git a/src/Umbraco.Tests/Persistence/PetaPocoExpresionsTests.cs b/src/Umbraco.Tests/Persistence/PetaPocoExpresionsTests.cs new file mode 100644 index 0000000000..e788a833bc --- /dev/null +++ b/src/Umbraco.Tests/Persistence/PetaPocoExpresionsTests.cs @@ -0,0 +1,36 @@ +using NUnit.Framework; +using Umbraco.Core.Models.Rdbms; +using Umbraco.Core.Persistence; +using Umbraco.Core.Persistence.SqlSyntax; + +namespace Umbraco.Tests.Persistence +{ + [TestFixture] + public class PetaPocoExpresionsTests + { + [Test] + public void WhereInValueFieldTest() + { + var syntax = SqlSyntaxContext.SqlSyntaxProvider = new SqlCeSyntaxProvider(); + var sql = new Sql() + .Select("*") + .From(syntax) + .WhereIn(x => x.NodeId, new[] { 1, 2, 3 }, syntax); + Assert.AreEqual("SELECT *\nFROM [umbracoNode]\nWHERE ([umbracoNode].[id] IN (@0,@1,@2))", sql.SQL); + } + + [Test] + public void WhereInObjectFieldTest() + { + // this test used to fail because x => x.Text was evaluated as a lambda + // and returned "[umbracoNode].[text] = @0"... had to fix WhereIn. + + var syntax = SqlSyntaxContext.SqlSyntaxProvider = new SqlCeSyntaxProvider(); + var sql = new Sql() + .Select("*") + .From(syntax) + .WhereIn(x => x.Text, new[] { "a", "b", "c" }, syntax); + Assert.AreEqual("SELECT *\nFROM [umbracoNode]\nWHERE ([umbracoNode].[text] IN (@0,@1,@2))", sql.SQL); + } + } +} \ No newline at end of file diff --git a/src/Umbraco.Tests/Umbraco.Tests.csproj b/src/Umbraco.Tests/Umbraco.Tests.csproj index a38e951434..9ccbe1ce6b 100644 --- a/src/Umbraco.Tests/Umbraco.Tests.csproj +++ b/src/Umbraco.Tests/Umbraco.Tests.csproj @@ -177,6 +177,7 @@ + diff --git a/src/Umbraco.Web.UI/config/umbracoSettings.config b/src/Umbraco.Web.UI/config/umbracoSettings.config index dd47cd5570..fb402fcc68 100644 --- a/src/Umbraco.Web.UI/config/umbracoSettings.config +++ b/src/Umbraco.Web.UI/config/umbracoSettings.config @@ -1,4 +1,4 @@ - + @@ -310,10 +310,7 @@ Configure it here if you need anything specific. Needs to be a complete url with scheme and umbraco path, eg http://mysite.com/umbraco. NOT just "mysite.com" or "mysite.com/umbraco" or "http://mysite.com". --> - + \ No newline at end of file From 5afeb315ba9312d35ce2a31a496b8c550910ac93 Mon Sep 17 00:00:00 2001 From: Stephan Date: Thu, 8 Sep 2016 10:39:56 +0200 Subject: [PATCH 2/3] U4-8954 - rename file --- .../{PetaPocoExpresionsTests.cs => PetaPocoExpressionsTests.cs} | 2 +- src/Umbraco.Tests/Umbraco.Tests.csproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename src/Umbraco.Tests/Persistence/{PetaPocoExpresionsTests.cs => PetaPocoExpressionsTests.cs} (96%) diff --git a/src/Umbraco.Tests/Persistence/PetaPocoExpresionsTests.cs b/src/Umbraco.Tests/Persistence/PetaPocoExpressionsTests.cs similarity index 96% rename from src/Umbraco.Tests/Persistence/PetaPocoExpresionsTests.cs rename to src/Umbraco.Tests/Persistence/PetaPocoExpressionsTests.cs index e788a833bc..4412c25e5f 100644 --- a/src/Umbraco.Tests/Persistence/PetaPocoExpresionsTests.cs +++ b/src/Umbraco.Tests/Persistence/PetaPocoExpressionsTests.cs @@ -6,7 +6,7 @@ using Umbraco.Core.Persistence.SqlSyntax; namespace Umbraco.Tests.Persistence { [TestFixture] - public class PetaPocoExpresionsTests + public class PetaPocoExpressionsTests { [Test] public void WhereInValueFieldTest() diff --git a/src/Umbraco.Tests/Umbraco.Tests.csproj b/src/Umbraco.Tests/Umbraco.Tests.csproj index 9ccbe1ce6b..c2c6e785ec 100644 --- a/src/Umbraco.Tests/Umbraco.Tests.csproj +++ b/src/Umbraco.Tests/Umbraco.Tests.csproj @@ -177,7 +177,7 @@ - + From 8091d9a098f426fd5a026387ebab8ec780d130b0 Mon Sep 17 00:00:00 2001 From: Warren Buckley Date: Fri, 16 Sep 2016 11:04:50 +0100 Subject: [PATCH 3/3] Resetting UmbracoSettings file in this PR back to what it was previously - seems to have been committed by mistake --- .../config/umbracoSettings.config | 633 +++++++++--------- 1 file changed, 318 insertions(+), 315 deletions(-) diff --git a/src/Umbraco.Web.UI/config/umbracoSettings.config b/src/Umbraco.Web.UI/config/umbracoSettings.config index fb402fcc68..9eb3f135e9 100644 --- a/src/Umbraco.Web.UI/config/umbracoSettings.config +++ b/src/Umbraco.Web.UI/config/umbracoSettings.config @@ -1,316 +1,319 @@ - - - - - - jpeg,jpg,gif,bmp,png,tiff,tif - - src,alt,border,class,style,align,id,name,onclick,usemap - - - - umbracoWidth - umbracoHeight - umbracoBytes - umbracoExtension - - - - - - - /scripts - - js,xml - - false - - - - True - - - - - 1 - 1079 - 1080 - - - - - your@email.here - - - - True - - - False - - - UTF8 - - - false - - - - true - - - True - - - True - - - False - - - False - - - text - - - - In Preview Mode - click to end - ]]> - - - - 1800 - - - - - false - - - throw - - - ashx,aspx,ascx,config,cshtml,vbhtml,asmx,air,axd,swf,xml,html,htm,svg,php,htaccess - - - Textstring - - - - - - true - - - false - - - true - - - - - - false - - true - - - - - - - - - - - - - plus - star - - - ae - oe - aa - ae - oe - ue - ss - ae - oe - - - - - - - - - - - true - - - - Mvc - - - - - - - cs - vb - - - - - - - - p - div - ul - span - - - - - - - - - - - - - true - true - - - - - - - - - - - - - - - - - - 0 - - - - - - - - - - - - - - - - - - - - - - UsersMembershipProvider - - - - - - - - - - - - - + + + + + + jpeg,jpg,gif,bmp,png,tiff,tif + + src,alt,border,class,style,align,id,name,onclick,usemap + + + + umbracoWidth + umbracoHeight + umbracoBytes + umbracoExtension + + + + + + + /scripts + + js,xml + + false + + + + True + + + + + 1 + 1079 + 1080 + + + + + your@email.here + + + + True + + + False + + + UTF8 + + + false + + + + true + + + True + + + True + + + False + + + False + + + text + + + + In Preview Mode - click to end + ]]> + + + + 1800 + + + + + false + + + throw + + + ashx,aspx,ascx,config,cshtml,vbhtml,asmx,air,axd,swf,xml,html,htm,svg,php,htaccess + + + Textstring + + + + + + true + + + false + + + true + + + + + + false + + true + + - + + + + + + + + + + plus + star + + + ae + oe + aa + ae + oe + ue + ss + ae + oe + - + + + + + + + + + true + + + + Mvc + + + + + + + cs + vb + + + + + + + + p + div + ul + span + + + + + + + + + + + + + true + true + + + + + + + + + + + + + + + + + + 0 + + + + + + + + + + + + + + + + + + + + + + UsersMembershipProvider + + + + + + + + + + + + + \ No newline at end of file