Skip to content

Commit

Permalink
fix ParseByParams
Browse files Browse the repository at this point in the history
  • Loading branch information
Victor Qu authored and Victor Qu committed Oct 31, 2024
1 parent db78c9e commit 93e1a2c
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
2 changes: 1 addition & 1 deletion ProjectCommon.targets
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VersionSuffix>$(VersionSuffix)</VersionSuffix>
<Version>0.0.2.11</Version>
<Version>0.0.2.12</Version>
<AssemblyVersion>$(Version)</AssemblyVersion>
<FileVersion>$(Version)</FileVersion>
<Version Condition=" '$(VersionSuffix)' != '' ">$(Version)$(VersionSuffix)</Version>
Expand Down
2 changes: 1 addition & 1 deletion src/SV.Db.Sloth/From.Params.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ private static ConditionStatement ParseOperaterStatement(string key, string v)
throw new NotSupportedException($"Field {key} can not be empty");
var op = v.Length < OperatorLength || !v.StartsWith("{{") ? "{{eq}}" : v[0..OperatorLength];
var vv = v;
if (op.StartsWith("{{") && v.Length >= OperatorLength)
if (v.StartsWith("{{") && v.Length >= OperatorLength)
{
vv = v[OperatorLength..];
}
Expand Down
17 changes: 12 additions & 5 deletions test/UT/SQLite/BuildConditionTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,33 @@ public void TestCases()
Build<BuildConditionTestData>(new Dictionary<string, StringValues>(StringComparer.OrdinalIgnoreCase)
{
{ "NAME", "33" }
}));
}, out var cmd));

Assert.Equal("where Name = false ",
Build<BuildConditionTestData>(new Dictionary<string, StringValues>(StringComparer.OrdinalIgnoreCase)
{
{ "NAME", "false" }
}));
}, out cmd));

Assert.Equal("where Name = @P_0 ",
Build<BuildConditionTestData>(new Dictionary<string, StringValues>(StringComparer.OrdinalIgnoreCase)
{
{ "NAME", "fsse" }
}));
}, out cmd));

Assert.Equal("where Name = @P_0 ",
Build<BuildConditionTestData>(new Dictionary<string, StringValues>(StringComparer.OrdinalIgnoreCase)
{
{ "NAME", "Pending" }
}, out cmd));
Assert.Equal("Pending", cmd.Parameters[0].Value);
}

public string Build<T>(Dictionary<string, StringValues> ps)
public string Build<T>(Dictionary<string, StringValues> ps, out TestDbCommand cmd)
{
var factory = new ConnectionStringProviders(new IConnectionStringProvider[] { DictionaryConnectionStringProvider.Instance }, null, null);
var statement = factory.ParseByParams<T>(ps, out var info);
var cmd = new TestDbCommand();
cmd = new TestDbCommand();
return SQLiteConnectionProvider.BuildCondition(cmd, info, statement.Where.Condition);
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/UT/TestData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public override void RemoveAt(string parameterName)

protected override DbParameter GetParameter(int index)
{
throw new NotImplementedException();
return Params[index] as DbParameter;
}

protected override DbParameter GetParameter(string parameterName)
Expand Down

0 comments on commit 93e1a2c

Please sign in to comment.