Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Contains method with StringComparison parameter. #806

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions nuget/SQLite-net-base/SQLite-net-base.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
<Compile Include="..\..\src\SQLiteAsync.cs">
<Link>SQLiteAsync.cs</Link>
</Compile>
<Compile Include="..\..\src\StringContainsExtension.cs">
<Link>StringContainsExtension.cs</Link>
</Compile>
</ItemGroup>
<ItemGroup>
<PackageReference Include="SQLitePCLRaw.core" Version="1.1.13" />
Expand Down
3 changes: 3 additions & 0 deletions nuget/SQLite-net-sqlcipher/SQLite-net-sqlcipher.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,8 @@
<Compile Include="..\..\src\SQLiteAsync.cs">
<Link>SQLiteAsync.cs</Link>
</Compile>
<Compile Include="..\..\src\StringContainsExtension.cs">
<Link>StringContainsExtension.cs</Link>
</Compile>
</ItemGroup>
</Project>
3 changes: 3 additions & 0 deletions nuget/SQLite-net-std/SQLite-net-std.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,8 @@
<Compile Include="..\..\src\SQLiteAsync.cs">
<Link>SQLiteAsync.cs</Link>
</Compile>
<Compile Include="..\..\src\StringContainsExtension.cs">
<Link>StringContainsExtension.cs</Link>
</Compile>
</ItemGroup>
</Project>
8 changes: 6 additions & 2 deletions nuget/SQLite-net/SQLite-net.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugSymbols>false</DebugSymbols>
<DebugType></DebugType>
<DebugType>
</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>RELEASE;USE_SQLITEPCL_RAW</DefineConstants>
Expand All @@ -51,6 +52,9 @@
<Compile Include="..\..\src\SQLiteAsync.cs">
<Link>SQLiteAsync.cs</Link>
</Compile>
<Compile Include="..\..\src\StringContainsExtension.cs">
<Link>StringContainsExtension.cs</Link>
</Compile>
</ItemGroup>
<ItemGroup>
<Folder Include="Properties\" />
Expand Down Expand Up @@ -78,4 +82,4 @@
</Target>
-->
<Import Project="..\..\packages\NuGet.Build.Packaging.0.2.2\build\NuGet.Build.Packaging.targets" Condition="Exists('..\..\packages\NuGet.Build.Packaging.0.2.2\build\NuGet.Build.Packaging.targets')" />
</Project>
</Project>
14 changes: 14 additions & 0 deletions src/SQLite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3561,6 +3561,20 @@ private CompileResult CompileExpr (Expression expr, List<object> queryArgs)
sqlCall = "(" + args[0].CommandText + " like " + args[1].CommandText + ")";
}
else if (call.Method.Name == "Contains" && args.Length == 2) {
if (call.Object != null && call.Object.Type == typeof(string)) {
var startsWithCmpOp = (StringComparison)args[1].Value;
switch (startsWithCmpOp) {
case StringComparison.Ordinal:
case StringComparison.CurrentCulture:
sqlCall = "( instr(" + obj.CommandText + "," + args[0].CommandText + ") >0 )";
break;
case StringComparison.OrdinalIgnoreCase:
case StringComparison.CurrentCultureIgnoreCase:
sqlCall = "(" + obj.CommandText + " like ( '%' || " + args[0].CommandText + " || '%'))";
break;
}
}
else
sqlCall = "(" + args[1].CommandText + " in " + args[0].CommandText + ")";
}
else if (call.Method.Name == "Contains" && args.Length == 1) {
Expand Down
26 changes: 26 additions & 0 deletions src/StringContainsExtension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SQLite_net
{
/// <summary>
/// Class for Contains extension with StringComparison option
/// </summary>
public static class StringContainsExtension
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please rename to SQLiteStringExtensions and move it into the file SQLite.cs. Please delete this file.

{
/// <summary>
/// Contains extension with StringComparison option
/// </summary>
/// <param name="source"></param>
/// <param name="value"></param>
/// <param name="comparisonType"></param>
/// <returns></returns>
public static bool Contains (this string source, string value, StringComparison comparisonType)
{
throw new NotImplementedException ("Method not implemented: for sqlite purpose only");
}
}
}