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

FTS extensions #1649

Merged
merged 29 commits into from
Apr 13, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
edf4ff1
Fixes #386
MaceWindu Feb 17, 2019
831adac
Merge branch 'master' into issue_386
sdanyliv Feb 20, 2019
ccfd43a
Refactored FreeTextTableExpressionAttribute. Added possibly to genera…
sdanyliv Feb 20, 2019
d4bf48d
Improve custom query generation. Added a lot of ways to create dynami…
sdanyliv Feb 21, 2019
7a0970e
Merge remote-tracking branch 'origin/master' into issue_386
MaceWindu Mar 3, 2019
231d163
Merge branch 'master' into issue_386
MaceWindu Mar 10, 2019
96fa92b
fix tests build
MaceWindu Mar 10, 2019
40b4ac4
Merge branch 'master' into issue_386
MaceWindu Mar 10, 2019
4e37295
new FREETEXTTABLE extension, CONTAINSTABLE extension
MaceWindu Mar 16, 2019
fde7666
add more tests
MaceWindu Mar 16, 2019
62699a5
FREETEXT predicate
MaceWindu Mar 17, 2019
a59a491
disable FTS T4 generation by default
MaceWindu Mar 17, 2019
3033c6b
CONTAINS predicate (without PROPERTY support)
MaceWindu Mar 17, 2019
1697caf
CONTAINS(PROPERTY) extension and parameters inlining tests
MaceWindu Mar 17, 2019
1aa6115
SQLite FTS-related extensions part 1 (untested)
MaceWindu Mar 17, 2019
7cb5c9c
SQLite FTS3/4/5 support (except commands)
MaceWindu Mar 23, 2019
0c37411
SQLite FTS commands support
MaceWindu Mar 23, 2019
acd6cd6
mysql FTS extensions
MaceWindu Mar 24, 2019
47d23bd
move mysql extensions to Sql.Ext.MySql() endpoint
MaceWindu Mar 24, 2019
3456501
move sqlite extensions to sql.ext
MaceWindu Mar 24, 2019
3f224ee
move sqlserver extensions to sql.ext, fix northwind script
MaceWindu Mar 24, 2019
c1cca63
update fts obsolete messages
MaceWindu Mar 24, 2019
740b1ab
disable another test for netstandard1.6
MaceWindu Mar 24, 2019
f35fb8e
fix ITableMutable* implementation
MaceWindu Mar 24, 2019
d9b3efa
add tests failing over linqservice
MaceWindu Mar 24, 2019
191427a
hide new extensions for now
MaceWindu Mar 24, 2019
798669d
Merge branch 'master' into fts_extensions_v2
MaceWindu Apr 6, 2019
5ce931f
serialize SqlField.Table for remote service
MaceWindu Apr 6, 2019
d6b9722
move test attribute to proper method
MaceWindu Apr 6, 2019
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
Prev Previous commit
Next Next commit
Improve custom query generation. Added a lot of ways to create dynami…
…c queries safely.
  • Loading branch information
sdanyliv committed Feb 21, 2019
commit d4bf48d1b8ffd9f8a08662ae832611b436c6f810
2 changes: 1 addition & 1 deletion Source/LinqToDB/Linq/Builder/AggregationBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ protected override IBuildContext BuildMethodCall(ExpressionBuilder builder, Meth

if (attr != null)
{
sqlExpression = attr.GetExpression(builder.MappingSchema, sequence.SelectQuery, methodCall, e =>
sqlExpression = attr.GetExpression(builder.DataContext, sequence.SelectQuery, methodCall, e =>
{
var ex = e.Unwrap();

Expand Down
24 changes: 19 additions & 5 deletions Source/LinqToDB/Linq/Builder/ExpressionBuilder.SqlBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,7 @@ public ISqlExpression ConvertToSql(IBuildContext context, Expression expression,

if (attr != null)
{
var converted = attr.GetExpression(MappingSchema, context.SelectQuery, ma,
var converted = attr.GetExpression(DataContext, context.SelectQuery, ma,
e => ConvertToSql(context, e));

if (converted == null)
Expand Down Expand Up @@ -944,7 +944,7 @@ public ISqlExpression ConvertToSql(IBuildContext context, Expression expression,
if (attr.InlineParameters)
DataContext.InlineParameters = true;

var sqlExpression = attr.GetExpression(MappingSchema, context.SelectQuery, e, _ => ConvertToSql(context, _));
var sqlExpression = attr.GetExpression(DataContext, context.SelectQuery, e, _ => ConvertToSql(context, _));
if (sqlExpression != null)
return Convert(context, sqlExpression);

Expand Down Expand Up @@ -1032,6 +1032,13 @@ public ISqlExpression ConvertToSql(IBuildContext context, Expression expression,
return ConvertToSql(context, expression.Reduce());
break;
}
case ExpressionType.Constant:
{
var cnt = (ConstantExpression)expression;
if (cnt.Value is ISqlExpression sql)
return sql;
break;
}
}

if (expression.Type == typeof(bool) && _convertedPredicates.Add(expression))
Expand Down Expand Up @@ -1243,7 +1250,7 @@ bool CanBeCompiled(Expression expr)

var allowedParams = new HashSet<Expression> { ParametersParam };

var result = expr.NodeType == ExpressionType.Quote || null == expr.Find(ex =>
var result = null == expr.Find(ex =>
{
if (IsServerSideOnly(ex))
return true;
Expand All @@ -1267,6 +1274,13 @@ bool CanBeCompiled(Expression expr)
}
break;
}
case ExpressionType.Constant :
{
var cnt = (ConstantExpression)ex;
if (cnt.Value is ISqlExpression)
return true;
break;
}
}

return false;
Expand Down Expand Up @@ -1516,7 +1530,7 @@ ISqlPredicate ConvertPredicate(IBuildContext context, Expression expression)

var attr = GetExpressionAttribute(e.Method);

if (attr != null && attr.IsPredicate)
if (attr != null && attr.GetIsPredicate(expression))
break;

return ConvertPredicate(context, AddEqualTrue(expression));
Expand All @@ -1543,7 +1557,7 @@ ISqlPredicate ConvertPredicate(IBuildContext context, Expression expression)

var attr = GetExpressionAttribute(e.Member);

if (attr != null && attr.IsPredicate)
if (attr != null && attr.GetIsPredicate(expression))
break;

return ConvertPredicate(context, AddEqualTrue(expression));
Expand Down
2 changes: 1 addition & 1 deletion Source/LinqToDB/Linq/Builder/GroupByBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ ISqlExpression ConvertEnumerable(MethodCallExpression call)

if (attribute != null)
{
var expr = attribute.GetExpression(Builder.MappingSchema, SelectQuery, call, e =>
var expr = attribute.GetExpression(Builder.DataContext, SelectQuery, call, e =>
{
var ex = e.Unwrap();

Expand Down
37 changes: 18 additions & 19 deletions Source/LinqToDB/Linq/Builder/TableBuilder.RawSqlContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@ namespace LinqToDB.Linq.Builder

partial class TableBuilder
{
#if !NET45
private static MethodInfo _getArgumentMethodInfo =
MemberHelper.MethodOf(() => ((FormattableString)null).GetArgument(0));
#endif
private static MethodInfo _asSqlMethodInfo =
MemberHelper.MethodOf(() => Sql.AsSql(""));

static IBuildContext BuildRawSqlTable(ExpressionBuilder builder, BuildInfo buildInfo)
{
Expand All @@ -24,36 +22,41 @@ static IBuildContext BuildRawSqlTable(ExpressionBuilder builder, BuildInfo build
if (builder.MappingSchema.IsScalarType(methodCall.Method.GetGenericArguments()[0]))
throw new LinqToDBException("Selection of scalar types not supported by FromSql method. Use mapping class with one column for scalar values");

string format;
IEnumerable<Expression> arguments;
PrepareRawSqlArguments(methodCall.Arguments[1],
methodCall.Arguments.Count > 2 ? methodCall.Arguments[2] : null,
out var format, out var arguments);

var sqlArguments = arguments.Select(a => builder.ConvertToSql(buildInfo.Parent, a)).ToArray();

var sqlExpr = methodCall.Arguments[1];
return new RawSqlContext(builder, buildInfo, methodCall.Method.GetGenericArguments()[0], format, sqlArguments);
}

public static void PrepareRawSqlArguments(Expression fromatArg, Expression parametersArg, out string format, out IEnumerable<Expression> arguments)
{
// Consider that FormattableString is used
if (sqlExpr.NodeType == ExpressionType.Call)
if (fromatArg.NodeType == ExpressionType.Call)
{
var mc = (MethodCallExpression)sqlExpr;
var mc = (MethodCallExpression)fromatArg;

format = (string)mc.Arguments[0].EvaluateExpression();
format = (string)mc.Arguments[0].EvaluateExpression();
arguments = ((NewArrayExpression)mc.Arguments[1]).Expressions;

}
else
{
var evaluatedSql = sqlExpr.EvaluateExpression();
var evaluatedSql = fromatArg.EvaluateExpression();
#if !NET45
if (evaluatedSql is FormattableString formattable)
{
format = formattable.Format;
format = formattable.Format;
arguments = formattable.GetArguments().Select(Expression.Constant);
}
else
#endif
{
var rawSqlString = (RawSqlString)evaluatedSql;

format = rawSqlString.Format;
var arrayExpr = methodCall.Arguments[2];
format = rawSqlString.Format;
var arrayExpr = parametersArg;

if (arrayExpr.NodeType == ExpressionType.NewArrayInit)
arguments = ((NewArrayExpression)arrayExpr).Expressions;
Expand All @@ -64,10 +67,6 @@ static IBuildContext BuildRawSqlTable(ExpressionBuilder builder, BuildInfo build
}
}
}

var sqlArguments = arguments.Select(a => builder.ConvertToSql(buildInfo.Parent, a)).ToArray();

return new RawSqlContext(builder, buildInfo, methodCall.Method.GetGenericArguments()[0], format, sqlArguments);
}

class RawSqlContext : TableContext
Expand Down
5 changes: 4 additions & 1 deletion Source/LinqToDB/Sql/Sql.ExpressionAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,13 @@ public virtual ISqlExpression GetExpression(MemberInfo member, params ISqlExpres
};
}

public virtual ISqlExpression GetExpression(MappingSchema mapping, SelectQuery query, Expression expression, Func<Expression, ISqlExpression> converter)
public virtual ISqlExpression GetExpression(IDataContext dataContext, SelectQuery query,
Expression expression, Func<Expression, ISqlExpression> converter)
{
return null;
}

public virtual bool GetIsPredicate(Expression expression) => IsPredicate;
}
}
}
Loading