示例#1
0
		public static SelectSubqueryData Create(QueryParts parts, SubqueryParts subquery)
		{
			Contract.Requires(parts != null);
			Contract.Requires(subquery != null);

			var selects = new List<KeyValuePair<IQuerySource, Func<object, BufferedTextReader, object>>>();
			foreach (var s in subquery.Selects)
			{
				var factory = QuerySourceConverterFactory.Create(s.QuerySource, parts);
				selects.Add(new KeyValuePair<IQuerySource, Func<object, BufferedTextReader, object>>(factory.QuerySource, factory.Instancer));
			}

			return new SelectSubqueryData(selects);
		}
示例#2
0
		private string SimplifyConstantExpression(QueryParts query, SubqueryParts parts, string exp, ConstantExpression ce)
		{
			if (ce.Type.IsArray || ce.Value is Array)
			{
				var array = ((Array)ce.Value).Cast<object>().ToArray();
				return FormatInQuery(exp, array, parts);
			}
			else if (ce.Value is IEnumerable)
			{
				var array = ((IEnumerable)ce.Value).Cast<object>().ToArray();
				return FormatInQuery(exp, array, parts);
			}
			return exp + " = " + query.FormatObject(ce.Value);
		}
示例#3
0
		private string FormatInQuery(string exp, object[] array, SubqueryParts query)
		{
			if (array.Length == 0)
				return "false";
			if (array.Length == 1 && array[0] == null)
				return exp + " IS NULL ";

			var qsre = query.Selector as QuerySourceReferenceExpression;
			if (qsre != null && qsre.ReferencedQuerySource.Equals(query.MainFrom)
				&& Revenj.DatabasePersistence.Postgres.NpgsqlTypes.TypeConverter.CanConvert(query.MainFrom.ItemType))
			{
				//TODO: values
				return array.Length == 1
					? exp + " = " + Revenj.DatabasePersistence.Postgres.NpgsqlTypes.TypeConverter.Convert(query.MainFrom.ItemType, array[0])
					: exp + " IN ("
						+ string.Join(
							",",
							array.Select(it => Revenj.DatabasePersistence.Postgres.NpgsqlTypes.TypeConverter.Convert(query.MainFrom.ItemType, it)))
							+ ")";
			}

			return exp + " IN (SELECT " + query.GetSqlExpression(query.Selector)
					+ " FROM unnest(" + query.FormatArray(array) + ") \"" + query.MainFrom.ItemName + "\")";
		}
示例#4
0
		private string SimplifyMemberExpression(QueryParts query, SubqueryParts parts, string exp, MemberExpression ma)
		{
			return exp + " IN (SELECT " + query.GetSqlExpression(parts.Selector)
					+ " FROM unnest(" + query.GetSqlExpression(ma) + ") \"" + query.MainFrom.ItemName + "\")";
		}
 private SubqueryGeneratorQueryModelVisitor(QueryParts parentQuery, bool canQueryInMemory, Expression selector, QueryContext context)
 {
     QueryParts = new SubqueryParts(parentQuery, canQueryInMemory, selector, context);
 }