Skip to content

Commit

Permalink
Add Contains method with StringComparison parameter.
Browse files Browse the repository at this point in the history
  • Loading branch information
microspaze committed Jan 16, 2024
1 parent e8a24a8 commit 545a04c
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/SQLite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4064,6 +4064,9 @@ private SQLiteCommand GenerateCommand (string selectionList)
}
cmdText += " offset " + _offset.Value;
}

//Remove all StringComparison arguments from args, otherwise the created command may unmatch with the real arguments.
args.RemoveAll (x => x is StringComparison);
return Connection.CreateCommand (cmdText, args.ToArray ());
}
}
Expand Down Expand Up @@ -4133,7 +4136,24 @@ 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) {
sqlCall = "(" + args[1].CommandText + " in " + args[0].CommandText + ")";
//Add Contains method with StringComparison parameter.
if (call.Object != null && call.Object.Type == typeof (string) && args[1].Value is StringComparison comparison) {
switch (comparison) {
case StringComparison.Ordinal:
case StringComparison.CurrentCulture:
case StringComparison.InvariantCulture:
sqlCall = "(instr(" + obj.CommandText + "," + args[0].CommandText + ") > 0)";
break;
case StringComparison.OrdinalIgnoreCase:
case StringComparison.CurrentCultureIgnoreCase:
case StringComparison.InvariantCultureIgnoreCase:
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) {
if (call.Object != null && call.Object.Type == typeof (string)) {
Expand Down

0 comments on commit 545a04c

Please sign in to comment.