Orchard CMS中的NHibernate.Hql.Ast.ANTLR.QuerySyntaxException

时间:2015-01-24 10:53:41

标签: nhibernate unicode orchardcms

使用Orchard.Projections模块,无法搜索Unicode文本。例如,结果查询为Select ... From ... Where ... Col Like '%term%',但我们希望在Select ... From ... Where ... Col Like N'%term%'之后包含NLike)。在代码中查找,我们在 Orchard.ContentManagement.HqlRestrictions 中找到public static BinaryExpression Like()。通过添加N并将value = "'%" + FormatValue(value, false) + "%'";更改为value = "N'%" + FormatValue(value, false) + "%'";,我们会收到此错误:

NHibernate.Hql.Ast.ANTLR.QuerySyntaxException was caught
  HResult=-2146232832
  Message=Exception of type 'Antlr.Runtime.MismatchedTokenException' was thrown. near line 9, column 61
  Source=NHibernate
  StackTrace:
       at NHibernate.Hql.Ast.ANTLR.ErrorCounter.ThrowQueryException() in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Hql\Ast\ANTLR\ErrorCounter.cs:line 73
       at NHibernate.Hql.Ast.ANTLR.HqlParseEngine.Parse() in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Hql\Ast\ANTLR\QueryTranslatorImpl.cs:line 479
       at NHibernate.Hql.Ast.ANTLR.ASTQueryTranslatorFactory.CreateQueryTranslators(String queryString, String collectionRole, Boolean shallow, IDictionary`2 filters, ISessionFactoryImplementor factory) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Hql\Ast\ANTLR\ASTQueryTranslatorFactory.cs:line 19
       at NHibernate.Engine.Query.HQLStringQueryPlan.CreateTranslators(String hql, String collectionRole, Boolean shallow, IDictionary`2 enabledFilters, ISessionFactoryImplementor factory) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Engine\Query\HQLStringQueryPlan.cs:line 24
       at NHibernate.Engine.Query.HQLStringQueryPlan..ctor(String hql, String collectionRole, Boolean shallow, IDictionary`2 enabledFilters, ISessionFactoryImplementor factory) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Engine\Query\HQLStringQueryPlan.cs:line 16
       at NHibernate.Engine.Query.HQLStringQueryPlan..ctor(String hql, Boolean shallow, IDictionary`2 enabledFilters, ISessionFactoryImplementor factory) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Engine\Query\HQLStringQueryPlan.cs:line 14
       at NHibernate.Engine.Query.QueryPlanCache.GetHQLQueryPlan(String queryString, Boolean shallow, IDictionary`2 enabledFilters) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Engine\Query\QueryPlanCache.cs:line 62
       at NHibernate.Impl.AbstractSessionImpl.GetHQLQueryPlan(String query, Boolean shallow) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Impl\AbstractSessionImpl.cs:line 310
       at NHibernate.Impl.AbstractSessionImpl.CreateQuery(String queryString) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Impl\AbstractSessionImpl.cs:line 289
       at Orchard.ContentManagement.DefaultHqlQuery.Slice(Int32 skip, Int32 count) in d:\Projects\...\src\Orchard\ContentManagement\DefaultHqlQuery.cs:line 188
       at Orchard.Projections.Services.ProjectionManager.GetContentItems(Int32 queryId, Int32 skip, Int32 count)
       at Orchard.Projections.Drivers.ProjectionPartDriver.<>c__DisplayClass2e.<Display>b__1e(Object shape)
       at Orchard.ContentManagement.Drivers.ContentPartDriver`1.<>c__DisplayClass12.<ContentShape>b__11(BuildShapeContext ctx) in d:\Projects\...\src\Orchard\ContentManagement\Drivers\ContentPartDriver.cs:line 135
       at Orchard.ContentManagement.Drivers.ContentPartDriver`1.<>c__DisplayClass15.<ContentShapeImplementation>b__14(BuildShapeContext ctx) in d:\Projects\...\src\Orchard\ContentManagement\Drivers\ContentPartDriver.cs:line 140
       at Orchard.ContentManagement.Drivers.ContentShapeResult.ApplyImplementation(BuildShapeContext context, String displayType) in d:\Projects\...\src\Orchard\ContentManagement\Drivers\ContentShapeResult.cs:line 45
       at Orchard.ContentManagement.Drivers.ContentShapeResult.Apply(BuildDisplayContext context) in d:\Projects\...\src\Orchard\ContentManagement\Drivers\ContentShapeResult.cs:line 21
       at Orchard.ContentManagement.Drivers.CombinedResult.Apply(BuildDisplayContext context) in d:\Projects\...\src\Orchard\ContentManagement\Drivers\CombinedResult.cs:line 28
       at Orchard.ContentManagement.Drivers.Coordinators.ContentPartDriverCoordinator.<>c__DisplayClassa.<BuildDisplay>b__9(IContentPartDriver driver) in d:\Projects\...\src\Orchard\ContentManagement\Drivers\Coordinators\ContentPartDriverCoordinator.cs:line 49
       at Orchard.InvokeExtensions.Invoke[TEvents](IEnumerable`1 events, Action`1 dispatch, ILogger logger) in d:\Projects\...\src\Orchard\InvokeExtensions.cs:line 17
  InnerException: 

第9行,第61栏表示&#39; N&#39;的位置。

有什么想法吗? 我们如何使用此模块在不更改数据库归类的情况下搜索unicode文本?

Orchard版本为1.8.1

1 个答案:

答案 0 :(得分:0)

快速修复。我直接更改了数据库的整理设置