Пример #1
0
		public void Compile(ObjectExpression oe)
		{
			_maps = oe.Mappings;
			_provider = oe.Mappings.provider;

			_nextAliasIndex = 0;
			_parameterTable = new OPathParameterTable();

			// generate the database-specific query statement (and the parameter table at the same time)
			using( StringWriter writer = new StringWriter(new StringBuilder(500)) )
			{
				WriteSqlQuery(writer, oe.Expression);
				writer.Write(_provider.LineTerminator);
				_sqlQuery = writer.ToString();
			}

			SetParameterOrder(oe);

			// all or none of the parameters have to be provided
			if( _parameterTable != null )
			{
				if( _parameterTable.Count != oe.ParameterCount )
				{
					throw new Exception("Number of parameters in the expression does not match number of parameters in the OPathQuery.");
				}
			}

#if DEBUG
			//Debug.WriteLine(_sqlQuery);
			//Debug.WriteLine("");
#endif
		}
Пример #2
0
		internal static ObjectExpression Parse(OPathQuery query, Mappings maps)
		{
			OPath opath = new OPath(maps);

			int paramCount;
			Expression exp = opath.Parse(query.ObjectType, query.WhereExpression, query.SortExpression, out paramCount);
			ObjectExpression oe = new ObjectExpression(query.ObjectType, exp, maps, paramCount);
			oe.baseQuery = query;

			return oe;
		}
Пример #3
0
		internal CompiledQuery(ObjectExpression oe)
		{
			_objectExpression = oe;
			_objectType = oe.ObjectType;
			this.baseQuery = oe.baseQuery;
			this.parameterCount = oe.ParameterCount;

			OPathCompiler compiler = new OPathCompiler();
			compiler.Compile(oe);

			_sqlQuery = compiler.SqlQuery;
			this.parameterTable = compiler.ParameterTable;
		}
Пример #4
0
		private void SetParameterOrder(ObjectExpression oe)
		{
			if( oe.ParameterCount == 0 ) return;
			
			if( _provider.Provider == Provider.Access || _provider.Provider == Provider.OleDb )
			{
				// the OleDb driver expects the order of parameters to be specified in "subquery major" order (which I consider a *major* design flaw).
				// in other words, the order is driven by a post traversal of the select statements (filters), with standard left-to-right order within a given select.
				Expression.EnumNodesCallBack postCallback = new Expression.EnumNodesCallBack(this.OleDbSetParameterOrder);
				Expression.EnumNodes(oe.Expression, null, postCallback, 0);
			}
			else // not an OleDb provider
			{
				// use standard right-to-left order (which the parameters are already in)
				for( int i = _parameterTable.Count - 1; i >= 0; i-- )
				{
					_parameterTable[i].Ordinal = i;
				}
			}
		}