Exemplo n.º 1
0
		/// <summary>
		/// Create a new Expression phrase.
		/// </summary>
		/// <param name="expr">SQL Expression.</param>
		public APSqlExprPhrase(APSqlExpr expr)
		{
			if (Object.Equals(expr, null))
				throw new ArgumentNullException("expr");

			_expr = expr;
		}
Exemplo n.º 2
0
        /// <summary>
        /// Create a new condition phrase.
        /// </summary>
        /// <param name="expr">SQL Expression.</param>
        /// <param name="conditionOperator">Condition operator.</param>
        /// <param name="value">Value.</param>
        /// <param name="paramName">Parameter name.</param>
        public APSqlConditionPhrase(APSqlOperateExpr expr, APSqlConditionOperator conditionOperator, object value, string paramName)
        {
            if (Object.Equals(expr, null))
            {
                throw new ArgumentNullException("columnDef");
            }
            if (conditionOperator == APSqlConditionOperator.Exists || conditionOperator == APSqlConditionOperator.NotExists)
            {
                throw new ArgumentException(APResource.APDB_OperatorExists, "conditionOperator");
            }

            _expr      = expr;
            _paramName = paramName;
            if (String.IsNullOrEmpty(paramName))
            {
                _paramName = expr.ParamName;
            }

            if (value is String)
            {
                value = APSqlExpr.TryFitStringToRawExpr((string)value);
            }

            _value             = value;
            _conditionOperator = conditionOperator;
        }
Exemplo n.º 3
0
		/// <summary>
		/// Create a new 'SELECT' phrase.
		/// </summary>
		/// <param name="expr">SQL 'SELECT' Expression.</param>
		/// <param name="alias">Alias.</param>
		public APSqlSelectPhrase(APSqlOperateExpr expr, string alias)
		{
			if (Object.Equals(expr, null))
				throw new ArgumentNullException("expr");

			_expr = expr;
			_alias = alias;
		}
Exemplo n.º 4
0
        /// <summary>
        /// Create a new 'SELECT' phrase.
        /// </summary>
        /// <param name="expr">SQL 'SELECT' Expression.</param>
        public APSqlSelectPhrase(APSqlExpr expr)
        {
            if (Object.Equals(expr, null))
            {
                throw new ArgumentNullException("expr");
            }

            _expr = expr;
        }
Exemplo n.º 5
0
        /// <summary>
        /// Create a new 'SELECT' phrase.
        /// </summary>
        /// <param name="expr">SQL 'SELECT' Expression.</param>
        /// <param name="alias">Alias.</param>
        public APSqlSelectPhrase(APSqlOperateExpr expr, string alias)
        {
            if (Object.Equals(expr, null))
            {
                throw new ArgumentNullException("expr");
            }

            _expr  = expr;
            _alias = alias;
        }
Exemplo n.º 6
0
        private void WriteSelectExpression(ParserWriter writer, APSqlExpr selectExpr)
        {
            if (selectExpr is APSqlAggregationExpr)
            {
                APSqlAggregationExpr expr = selectExpr as APSqlAggregationExpr;
                writer.Write(expr.AggregationType.ToString());
                writer.Write("(");
                if (expr.SelectMode == APSqlSelectMode.DISTINCT)
                {
                    writer.Write("DISTINCT");
                }

                if (expr.RowSelectExpr is APSqlAsteriskExpr)
                {
                    writer.Write("*");
                }
                else
                {
                    WriteSelectExpression(writer, expr.RowSelectExpr);
                }

                writer.Write(")");
            }
            else if (selectExpr is APSqlDateGroupExpr)
            {
                APSqlDateGroupExpr expr = selectExpr as APSqlDateGroupExpr;

                string datepart = "";
                switch (expr.DateGroupMode)
                {
                case APSqlDateGroupMode.Day: datepart = "yyyy-mm-dd"; break;

                case APSqlDateGroupMode.Week: datepart = "yyyy-IW"; break;

                case APSqlDateGroupMode.Month: datepart = "yyyy-mm"; break;

                case APSqlDateGroupMode.Quarter: datepart = "yyyy-Q"; break;

                case APSqlDateGroupMode.Year: datepart = "yyyy"; break;
                }
                writer.Write("to_char(");
                WriteSelectExpression(writer, expr.RawExpr);
                writer.Write(", '{0}')", datepart);
            }
            else
            {
                writer.Write(selectExpr.SelectExpr);
            }
        }
Exemplo n.º 7
0
        private void WriteSelectExpression(ParserWriter writer, APSqlExpr selectExpr)
        {
            if (selectExpr is APSqlAggregationExpr)
            {
                APSqlAggregationExpr expr = selectExpr as APSqlAggregationExpr;
                writer.Write(expr.AggregationType.ToString());
                writer.Write("(");
                if (expr.SelectMode == APSqlSelectMode.DISTINCT)
                {
                    writer.Write("DISTINCT");
                }

                if (expr.RowSelectExpr is APSqlAsteriskExpr)
                {
                    writer.Write("*");
                }
                else
                {
                    WriteSelectExpression(writer, expr.RowSelectExpr);
                }

                writer.Write(")");
            }
            else if (selectExpr is APSqlDateGroupExpr)
            {
                APSqlDateGroupExpr expr     = selectExpr as APSqlDateGroupExpr;
                string             datepart = "";
                switch (expr.DateGroupMode)
                {
                case APSqlDateGroupMode.Day: datepart = "dd"; break;

                case APSqlDateGroupMode.Week: datepart = "wk"; break;

                case APSqlDateGroupMode.Month: datepart = "mm"; break;

                case APSqlDateGroupMode.Quarter: datepart = "qq"; break;

                case APSqlDateGroupMode.Year: datepart = "yy"; break;
                }
                writer.Write(String.Format("DATEADD( {0}, DATEDIFF( {0}, 0,", datepart));
                WriteSelectExpression(writer, expr.RawExpr);
                writer.Write("), 0 )");
            }
            else
            {
                writer.Write(selectExpr.SelectExpr);
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Create a new 'SET' phrase.
        /// </summary>
        /// <param name="assignmentExpr">SQL assignment Expression.</param>
        /// <param name="value">Value.</param>
        /// <param name="paramName">Parameter name.</param>
        public APSqlSetPhrase(APSqlColumnExpr assignmentExpr, object value, string paramName)
        {
            if (Object.Equals(assignmentExpr, null))
            {
                throw new ArgumentNullException("assignmentExpr");
            }

            if (value is String)
            {
                value = APSqlExpr.TryFitStringToRawExpr((string)value);
            }

            _assignmentExpr = assignmentExpr;
            _paramName      = String.IsNullOrEmpty(paramName) ? assignmentExpr.ParamName : paramName;
            _value          = value;
        }
Exemplo n.º 9
0
		private void WriteSelectExpression(ParserWriter writer, APSqlExpr selectExpr)
		{
			if (selectExpr is APSqlAggregationExpr)
			{
				APSqlAggregationExpr expr = selectExpr as APSqlAggregationExpr;
				writer.Write(expr.AggregationType.ToString());
				writer.Write("(");
				if (expr.SelectMode == APSqlSelectMode.DISTINCT)
					writer.Write("DISTINCT");

				if (expr.RowSelectExpr is APSqlAsteriskExpr)
				{
					writer.Write("*");
				}
				else
				{
					WriteSelectExpression(writer, expr.RowSelectExpr);
				}

				writer.Write(")");
			}
			else if (selectExpr is APSqlDateGroupExpr)
			{
				APSqlDateGroupExpr expr = selectExpr as APSqlDateGroupExpr;
				string datepart = "";
				switch (expr.DateGroupMode)
				{
					case APSqlDateGroupMode.Day : datepart = "dd"; break;
					case APSqlDateGroupMode.Week: datepart = "wk"; break;
					case APSqlDateGroupMode.Month: datepart = "mm"; break;
					case APSqlDateGroupMode.Quarter: datepart = "qq"; break;
					case APSqlDateGroupMode.Year: datepart = "yy"; break;
				}
				writer.Write(String.Format("DATEADD( {0}, DATEDIFF( {0}, 0,", datepart));
				WriteSelectExpression(writer, expr.RawExpr);
				writer.Write("), 0 )");
			}
			else
			{
				writer.Write(selectExpr.SelectExpr);
			}
		}
Exemplo n.º 10
0
		/// <summary>
		/// Create a new APSqlDateGroupExpr.
		/// </summary>
		/// <param name="rowSelectExpr">Row SQL 'SELECT' Expression.</param>
		/// <param name="dateGroupMode">Date group mode.</param>
		public APSqlDateGroupExpr(APSqlExpr rowSelectExpr, APSqlDateGroupMode dateGroupMode)
		{
			_rawExpr = rowSelectExpr;
			_dateGroupMode = dateGroupMode;
		}
Exemplo n.º 11
0
 /// <summary>
 /// PrimeryKeyColumnDef extensions.
 /// </summary>
 /// <param name="command">The command.</param>
 /// <param name="primaryExpr">The Primary Expression.</param>
 /// <returns>The command.</returns>
 public static APSqlSelectCommand primary(this APSqlSelectCommand command, APSqlExpr primaryExpr)
 {
     command.PrimeryKeyExpr = primaryExpr;
     return(command);
 }
Exemplo n.º 12
0
		/// <summary>
		/// Create a new APSqlAggregationExpr.
		/// </summary>
		/// <param name="rowSelectExpr">Row SQL 'SELECT' Expression.</param>
		/// <param name="aggregationType">Aggregation type.</param>
		/// <param name="selectMode">Select mode.</param>
		public APSqlAggregationExpr(APSqlExpr rowSelectExpr, APSqlAggregationType aggregationType, APSqlSelectMode selectMode)
		{
			_rowSelectExpr = rowSelectExpr;
			_aggregationType = aggregationType;
			_selectMode = selectMode;
		}
Exemplo n.º 13
0
 /// <summary>
 /// Create a new APSqlAggregationExpr.
 /// </summary>
 /// <param name="rowSelectExpr">Row SQL 'SELECT' Expression.</param>
 /// <param name="aggregationType">Aggregation type.</param>
 public APSqlAggregationExpr(APSqlExpr rowSelectExpr, APSqlAggregationType aggregationType)
     : this(rowSelectExpr, aggregationType, APSqlSelectMode.ALL)
 {
 }
Exemplo n.º 14
0
 /// <summary>
 /// Create a new APSqlAggregationExpr.
 /// </summary>
 /// <param name="rowSelectExpr">Row SQL 'SELECT' Expression.</param>
 /// <param name="aggregationType">Aggregation type.</param>
 /// <param name="selectMode">Select mode.</param>
 public APSqlAggregationExpr(APSqlExpr rowSelectExpr, APSqlAggregationType aggregationType, APSqlSelectMode selectMode)
 {
     _rowSelectExpr   = rowSelectExpr;
     _aggregationType = aggregationType;
     _selectMode      = selectMode;
 }
Exemplo n.º 15
0
		/// <summary>
		/// Create a new APSqlAggregationExpr.
		/// </summary>
		/// <param name="rowSelectExpr">Row SQL 'SELECT' Expression.</param>
		/// <param name="aggregationType">Aggregation type.</param>
		public APSqlAggregationExpr(APSqlExpr rowSelectExpr, APSqlAggregationType aggregationType)
			: this(rowSelectExpr, aggregationType, APSqlSelectMode.ALL)
		{
		}
Exemplo n.º 16
0
 /// <summary>
 /// Create a new APSqlDateGroupExpr.
 /// </summary>
 /// <param name="rowSelectExpr">Row SQL 'SELECT' Expression.</param>
 /// <param name="dateGroupMode">Date group mode.</param>
 public APSqlDateGroupExpr(APSqlExpr rowSelectExpr, APSqlDateGroupMode dateGroupMode)
 {
     _rawExpr       = rowSelectExpr;
     _dateGroupMode = dateGroupMode;
 }
Exemplo n.º 17
0
		private void WriteSelectExpression(ParserWriter writer, APSqlExpr selectExpr)
		{
			if (selectExpr is APSqlAggregationExpr)
			{
				APSqlAggregationExpr expr = selectExpr as APSqlAggregationExpr;
				writer.Write(expr.AggregationType.ToString());
				writer.Write("(");
				if (expr.SelectMode == APSqlSelectMode.DISTINCT)
					writer.Write("DISTINCT");

				if (expr.RowSelectExpr is APSqlAsteriskExpr)
				{
					writer.Write("*");
				}
				else
				{
					WriteSelectExpression(writer, expr.RowSelectExpr);
				}

				writer.Write(")");
			}
			else if (selectExpr is APSqlDateGroupExpr)
			{
				APSqlDateGroupExpr expr = selectExpr as APSqlDateGroupExpr;

				string datepart = "";
				switch (expr.DateGroupMode)
				{
					case APSqlDateGroupMode.Day: datepart = "yyyy-mm-dd"; break;
					case APSqlDateGroupMode.Week: datepart = "yyyy-IW"; break;
					case APSqlDateGroupMode.Month: datepart = "yyyy-mm"; break;
					case APSqlDateGroupMode.Quarter: datepart = "yyyy-Q"; break;
					case APSqlDateGroupMode.Year: datepart = "yyyy"; break;
				}
				writer.Write("to_char(");
				WriteSelectExpression(writer, expr.RawExpr);
				writer.Write(", '{0}')", datepart);
			}
			else
			{
				writer.Write(selectExpr.SelectExpr);
			}
		}