Skip to content

Commit c5c4f00

Browse files
committed
Fixed issue ThatRendle#148
1 parent deb4693 commit c5c4f00

8 files changed

Lines changed: 33 additions & 7 deletions

File tree

CommonAssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@
1919
// COM, set the ComVisible attribute to true on that type.
2020
[assembly: ComVisible(false)]
2121

22-
[assembly: AssemblyVersion("0.14.0.3")]
23-
[assembly: AssemblyFileVersion("0.14.0.3")]
22+
[assembly: AssemblyVersion("1.0.0.1")]
23+
[assembly: AssemblyFileVersion("1.0.0.1")]
2424

Simple.Data.Ado/GenericDbParameterFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public IDbDataParameter CreateParameter(string name, Column column)
2929
var parameter = _command.CreateParameter();
3030
parameter.ParameterName = name;
3131
parameter.DbType = column.DbType;
32-
parameter.Size = column.MaxLength;
32+
parameter.Size = column.DbType == DbType.StringFixedLength || column.DbType == DbType.AnsiStringFixedLength ? 0 : column.MaxLength;
3333
parameter.SourceColumn = column.ActualName;
3434
return parameter;
3535
}

Simple.Data.SqlCe40/SqlCeDbParameterFactory.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626

2727
 public IDbDataParameter CreateParameter(string name, DbType dbType, int maxLength)
2828
 {
29-
 IDbDataParameter parameter = new SqlCeParameter
29+
if (dbType == DbType.AnsiStringFixedLength || dbType == DbType.StringFixedLength) maxLength = 0;
30+
 IDbDataParameter parameter = new SqlCeParameter
3031
 {
3132
 ParameterName = name,
3233
 Size = maxLength

Simple.Data.SqlServer/Simple.Data.SqlServer.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
<DependentUpon>Resources.resx</DependentUpon>
6060
</Compile>
6161
<Compile Include="SqlBulkInserter.cs" />
62-
<Compile Include="SqlCeDbParameterFactory.cs" />
62+
<Compile Include="SqlDbParameterFactory.cs" />
6363
<Compile Include="SqlColumn.cs" />
6464
<Compile Include="SqlCommandOptimizer.cs" />
6565
<Compile Include="SqlConnectionProvider.cs" />

Simple.Data.SqlServer/SqlCeDbParameterFactory.cs renamed to Simple.Data.SqlServer/SqlDbParameterFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
 public IDbDataParameter CreateParameter(string name, Column column)
2121
 {
2222
 var sqlColumn = (SqlColumn) column;
23-
 return new SqlParameter(name, sqlColumn.SqlDbType, column.MaxLength, column.ActualName);
23+
 return new SqlParameter(name, sqlColumn.SqlDbType, sqlColumn.SqlDbType == SqlDbType.Char || sqlColumn.SqlDbType == SqlDbType.NChar ? 0 : column.MaxLength, column.ActualName);
2424
 }
2525

2626
 public IDbDataParameter CreateParameter(string name, DbType dbType, int maxLength)

Simple.Data.SqlTest/FindTests.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,14 @@ public void TestFindAllByPartialName()
7272
Assert.AreEqual(1, users.Count());
7373
}
7474

75+
[Test]
76+
public void TestFindAllByPartialNameOnChar()
77+
{
78+
var db = DatabaseHelper.Open();
79+
IEnumerable<User> users = db.UsersWithChar.FindAll(db.UsersWithChar.Name.Like("Bob%")).ToList<User>();
80+
Assert.AreEqual(1, users.Count());
81+
}
82+
7583
[Test]
7684
public void TestFindAllByExcludedPartialName()
7785
{

Simple.Data.SqlTest/Resources/DatabaseReset.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ BEGIN
3838
DROP TABLE [dbo].[Employee];
3939
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Users]') AND type in (N'U'))
4040
DROP TABLE [dbo].[Users];
41+
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UsersWithChar]') AND type in (N'U'))
42+
DROP TABLE [dbo].[UsersWithChar];
4143
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[OrderItems]') AND type in (N'U'))
4244
DROP TABLE [dbo].[OrderItems];
4345
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Orders]') AND type in (N'U'))
@@ -69,6 +71,16 @@ BEGIN
6971
ALTER TABLE [dbo].[Users]
7072
ADD CONSTRAINT [PK_Users] PRIMARY KEY CLUSTERED ([Id] ASC) WITH (ALLOW_PAGE_LOCKS = ON, ALLOW_ROW_LOCKS = ON, PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF, STATISTICS_NORECOMPUTE = OFF);
7173

74+
CREATE TABLE [dbo].[UsersWithChar] (
75+
[Id] INT IDENTITY (1, 1) NOT NULL,
76+
[Name] NCHAR (100) NOT NULL,
77+
[Password] NCHAR (100) NOT NULL,
78+
[Age] INT NOT NULL
79+
);
80+
81+
ALTER TABLE [dbo].[UsersWithChar]
82+
ADD CONSTRAINT [PK_UsersWithChar] PRIMARY KEY CLUSTERED ([Id] ASC) WITH (ALLOW_PAGE_LOCKS = ON, ALLOW_ROW_LOCKS = ON, PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF, STATISTICS_NORECOMPUTE = OFF);
83+
7284
CREATE TABLE [dbo].[Employee](
7385
[Id] [int] IDENTITY(1,1) NOT NULL,
7486
[Name] [nvarchar](50) NOT NULL,
@@ -170,6 +182,11 @@ BEGIN
170182
INSERT INTO [dbo].[Users] ([Id], [Name], [Password], [Age]) VALUES (2,'Charlie','Charlie',49)
171183
INSERT INTO [dbo].[Users] ([Id], [Name], [Password], [Age]) VALUES (3,'Dave','Dave',12)
172184
SET IDENTITY_INSERT [dbo].[Users] OFF
185+
SET IDENTITY_INSERT [dbo].[UsersWithChar] ON
186+
INSERT INTO [dbo].[UsersWithChar] ([Id], [Name], [Password], [Age]) VALUES (1,'Bob','Bob',32)
187+
INSERT INTO [dbo].[UsersWithChar] ([Id], [Name], [Password], [Age]) VALUES (2,'Charlie','Charlie',49)
188+
INSERT INTO [dbo].[UsersWithChar] ([Id], [Name], [Password], [Age]) VALUES (3,'Dave','Dave',12)
189+
SET IDENTITY_INSERT [dbo].[UsersWithChar] OFF
173190
SET IDENTITY_INSERT [dbo].[Employee] ON
174191
INSERT INTO [dbo].[Employee] ([Id], [Name], [ManagerId]) VALUES (1, 'Alice', NULL)
175192
INSERT INTO [dbo].[Employee] ([Id], [Name], [ManagerId]) VALUES (2, 'Bob', 1)

Simple.Data/Commands/GetCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public object Execute(DataStrategy dataStrategy, SimpleQuery query, InvokeMember
3131
query = query.Where(ExpressionHelper.CriteriaDictionaryToExpression(query.TableName, dict)).Take(1);
3232
var result = query.FirstOrDefault();
3333
if (result == null) return null;
34-
return binder.Name == "get" ? result : ((IDictionary<string, object>) result).First().Value;
34+
return binder.Name.Equals("get", StringComparison.OrdinalIgnoreCase) ? result : ((IDictionary<string, object>) result).First().Value;
3535
}
3636

3737
public Func<object[], object> CreateDelegate(DataStrategy dataStrategy, DynamicTable table, InvokeMemberBinder binder, object[] args)

0 commit comments

Comments
 (0)