mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-09-18 09:44:20 +08:00
Corrected 4000 chars clob limit in SqlCe with NHibernate
- Created a new class overriding the default type resolution for SqlCe, in the Provider class - Added some unit tests for this bug --HG-- branch : dev
This commit is contained in:
@@ -33,7 +33,8 @@ namespace Orchard.Tests.ContentManagement {
|
||||
typeof(ContentItemVersionRecord),
|
||||
typeof(GammaRecord),
|
||||
typeof(DeltaRecord),
|
||||
typeof(EpsilonRecord));
|
||||
typeof(EpsilonRecord),
|
||||
typeof(MegaRecord));
|
||||
}
|
||||
|
||||
[TestFixtureTearDown]
|
||||
@@ -172,6 +173,23 @@ namespace Orchard.Tests.ContentManagement {
|
||||
Assert.That(types, Has.Some.With.Property("Name").EqualTo("delta"));
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void BigStringsShouldNotBeTruncated() {
|
||||
var megaRepository = _container.Resolve<IRepository<MegaRecord>>();
|
||||
var mega = new MegaRecord() { BigStuff = new string('x', 4000) };
|
||||
megaRepository.Create(mega);
|
||||
_session.Flush();
|
||||
}
|
||||
|
||||
[Test, ExpectedException]
|
||||
public void StandardStringsShouldNotHaveAStandardSize() {
|
||||
var megaRepository = _container.Resolve<IRepository<MegaRecord>>();
|
||||
var mega = new MegaRecord() { SmallStuff = new string('x', 256) };
|
||||
megaRepository.Create(mega);
|
||||
_session.Flush();
|
||||
}
|
||||
|
||||
private ContentItemRecord CreateModelRecord(string contentType) {
|
||||
var contentTypeRepository = _container.Resolve<IRepository<ContentTypeRecord>>();
|
||||
var contentItemRepository = _container.Resolve<IRepository<ContentItemRecord>>();
|
||||
|
13
src/Orchard.Tests/ContentManagement/Records/MegaRecord.cs
Normal file
13
src/Orchard.Tests/ContentManagement/Records/MegaRecord.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using Orchard.ContentManagement.Records;
|
||||
using Orchard.Data.Conventions;
|
||||
|
||||
namespace Orchard.Tests.ContentManagement.Records {
|
||||
public class MegaRecord {
|
||||
public virtual int Id { get; set; }
|
||||
|
||||
[StringLengthMax]
|
||||
public virtual string BigStuff { get; set; }
|
||||
public virtual string SmallStuff { get; set; }
|
||||
|
||||
}
|
||||
}
|
@@ -172,6 +172,7 @@
|
||||
<Compile Include="ContentManagement\Handlers\Coordinators\ContentPartDriverCoordinatorTests.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="ContentManagement\Records\MegaRecord.cs" />
|
||||
<Compile Include="ContentManagement\Records\DeltaRecord.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
|
@@ -1,6 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using FluentNHibernate.Cfg.Db;
|
||||
using NHibernate.Driver;
|
||||
using NHibernate.SqlTypes;
|
||||
|
||||
namespace Orchard.Data.Providers {
|
||||
public class SqlCeDataServicesProvider : AbstractDataServicesProvider {
|
||||
@@ -36,6 +41,7 @@ namespace Orchard.Data.Providers {
|
||||
}
|
||||
|
||||
persistence = persistence.ConnectionString(localConnectionString);
|
||||
persistence = persistence.Driver(typeof(OrchardSqlServerCeDriver).AssemblyQualifiedName);
|
||||
return persistence;
|
||||
}
|
||||
|
||||
@@ -64,5 +70,35 @@ namespace Orchard.Data.Providers {
|
||||
engine.GetType().GetMethod("Dispose").Invoke(engine, null);
|
||||
}
|
||||
|
||||
public class OrchardSqlServerCeDriver : SqlServerCeDriver {
|
||||
private PropertyInfo _dbParamSqlDbTypeProperty;
|
||||
|
||||
public override void Configure(IDictionary<string, string> settings) {
|
||||
base.Configure(settings);
|
||||
using ( var cmd = CreateCommand() ) {
|
||||
var dbParam = cmd.CreateParameter();
|
||||
_dbParamSqlDbTypeProperty = dbParam.GetType().GetProperty("SqlDbType");
|
||||
}
|
||||
}
|
||||
|
||||
protected override void InitializeParameter(IDbDataParameter dbParam, string name, SqlType sqlType) {
|
||||
base.InitializeParameter(dbParam, name, sqlType);
|
||||
if (sqlType.Length <= 4000) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch(sqlType.DbType) {
|
||||
case DbType.String:
|
||||
_dbParamSqlDbTypeProperty.SetValue(dbParam, SqlDbType.NText, null);
|
||||
break;
|
||||
case DbType.AnsiString:
|
||||
_dbParamSqlDbTypeProperty.SetValue(dbParam, SqlDbType.Text, null);
|
||||
break;
|
||||
case DbType.Byte:
|
||||
_dbParamSqlDbTypeProperty.SetValue(dbParam, SqlDbType.Image, null);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user