Exemplo n.º 1
0
        private void WriteValues(ParserWriter writer, APSqlValuesClause clause, OracleCommand dbCmd)
        {
            if (clause != null && clause.Next != null)
            {
                writer.WriteLine();
                writer.WriteDirect("VALUES");
                APSqlSetPhrase phrase  = clause.Next;
                bool           isFirst = true;

                writer.Write('(');
                while (phrase != null)
                {
                    if (!isFirst)
                    {
                        writer.Write(',');
                    }
                    else
                    {
                        isFirst = false;
                    }

                    if (!TryWriteValue(writer, phrase.Value))
                    {
                        string paramName = "v_" + writer.GetSuitableParameterName(phrase.ParamName);
                        writer.Write(":" + paramName);
                        AddParameter(dbCmd, paramName, phrase.Value, ParameterDirection.Input);
                    }

                    phrase = phrase.Next as APSqlSetPhrase;
                }
                writer.Write(')');
            }
        }
Exemplo n.º 2
0
        private void WriteSet(ParserWriter writer, APSqlValuesClause clause, SqlCommand dbCmd)
        {
            if (clause != null && clause.Next != null)
            {
                writer.WriteLine();
                writer.WriteDirect("SET");
                APSqlSetPhrase phrase  = clause.Next;
                bool           isFirst = true;

                while (phrase != null)
                {
                    if (!isFirst)
                    {
                        writer.Write(',');
                    }
                    else
                    {
                        isFirst = false;
                    }

                    writer.Write(phrase.AssignmentExpr.SelectExpr);
                    writer.Write("=");

                    if (!TryWriteValue(writer, phrase.Value))
                    {
                        string paramName = writer.GetSuitableParameterName(phrase.ParamName);
                        writer.Write("@" + paramName);
                        AddParameter(dbCmd, paramName, phrase.Value, ParameterDirection.Input);
                    }

                    phrase = phrase.Next as APSqlSetPhrase;
                }
            }
        }
Exemplo n.º 3
0
        private void WriteConditionPhrase(ParserWriter writer, APSqlWherePhrase phrase, APSqlConditionJoinType join, OracleCommand dbCmd)
        {
            bool isFirst = true;

            writer.Write("(");

            while (phrase != null)
            {
                if (!isFirst)
                {
                    writer.Write(join.ToString());
                }

                if (phrase.IsNot)
                {
                    writer.Write("NOT (");
                }

                if (phrase is APSqlConditionAndPhrase)
                {
                    WriteConditionPhrase(writer, (phrase as APSqlConditionAndPhrase).Child, APSqlConditionJoinType.AND, dbCmd);
                }
                else if (phrase is APSqlConditionOrPhrase)
                {
                    WriteConditionPhrase(writer, (phrase as APSqlConditionOrPhrase).Child, APSqlConditionJoinType.OR, dbCmd);
                }
                else
                {
                    APSqlConditionPhrase cond = phrase as APSqlConditionPhrase;

                    // for this, if columnDef is null, mean this is a 'EXISTS ( subquery )' phrase
                    // do not
                    // change to check ConditionOperator.
                    if (cond.ConditionOperator != APSqlConditionOperator.Exists && cond.ConditionOperator != APSqlConditionOperator.NotExists)
                    {
                        WriteSelectExpression(writer, cond.Expr);
                    }


                    if (cond.ConditionOperator == APSqlConditionOperator.Equals /*&& !cond.IsRelationDef*/ && (cond.Value == null || cond.Value == DBNull.Value))
                    {
                        writer.Write("IS NULL");
                    }
                    else if (cond.ConditionOperator == APSqlConditionOperator.NotEqual /*&& !cond.IsRelationDef*/ && (cond.Value == null || cond.Value == DBNull.Value))
                    {
                        writer.Write("IS NOT NULL");
                    }
                    else
                    {
                        switch (cond.ConditionOperator)
                        {
                        case APSqlConditionOperator.Equals: writer.Write("="); break;

                        case APSqlConditionOperator.NotEqual: writer.Write("<>"); break;

                        case APSqlConditionOperator.GreaterThan: writer.Write(">"); break;

                        case APSqlConditionOperator.GreaterThanOrEqual: writer.Write(">="); break;

                        case APSqlConditionOperator.LessThan: writer.Write("<"); break;

                        case APSqlConditionOperator.LessThanOrEqual: writer.Write("<="); break;

                        case APSqlConditionOperator.Between: writer.Write("BETWEEN"); break;

                        case APSqlConditionOperator.NotBetween: writer.Write("NOT BETWEEN"); break;

                        case APSqlConditionOperator.Like: writer.Write("LIKE"); break;

                        case APSqlConditionOperator.NotLike: writer.Write("NOT LIKE"); break;

                        case APSqlConditionOperator.In: writer.Write("IN"); break;

                        case APSqlConditionOperator.NotIn: writer.Write("NOT IN"); break;

                        case APSqlConditionOperator.Exists: writer.Write("EXISTS"); break;

                        case APSqlConditionOperator.NotExists: writer.Write("NOT EXISTS"); break;
                        }

                        object value = cond.Value;

                        if (!TryWriteValue(writer, value))
                        {
                            if (value is APSqlSelectCommand)
                            {
                                switch (cond.SubQueryScalarRestrict)
                                {
                                case APSqlSubQueryScalarRestrict.All: writer.Write("ALL"); break;

                                case APSqlSubQueryScalarRestrict.Some: writer.Write("SOME"); break;

                                case APSqlSubQueryScalarRestrict.Any: writer.Write("ANY"); break;
                                }

                                writer.Write("(");
                                int idented = writer.Idented++;
                                writer.WriteLine();
                                ParseSelectInternal(value as APSqlSelectCommand, dbCmd, writer);
                                writer.Idented = idented;
                                writer.Write(")");
                            }
                            else
                            {
                                if (cond.ConditionOperator == APSqlConditionOperator.In || cond.ConditionOperator == APSqlConditionOperator.NotIn)
                                {
                                    writer.Write("(");
                                    int i = 0;
                                    foreach (object val in value as Array)
                                    {
                                        if (i != 0)
                                        {
                                            writer.Write(',');
                                        }
                                        string paramName = writer.GetSuitableParameterName(cond.ParamName);
                                        paramName = String.Format("v_{0}${1}", paramName, i);
                                        writer.Write(":" + paramName);
                                        AddParameter(dbCmd, paramName, val, ParameterDirection.Input);
                                        i++;
                                    }
                                    writer.Write(")");
                                }
                                else if (cond.ConditionOperator == APSqlConditionOperator.Between || cond.ConditionOperator == APSqlConditionOperator.NotBetween)
                                {
                                    object begin = (value as Array).GetValue(0);
                                    object end   = (value as Array).GetValue(1);

                                    if (!TryWriteValue(writer, begin))
                                    {
                                        string paramName = writer.GetSuitableParameterName(cond.ParamName);
                                        writer.Write(":" + paramName);
                                        AddParameter(dbCmd, paramName, begin, ParameterDirection.Input);
                                    }

                                    writer.Write("AND");

                                    if (!TryWriteValue(writer, end))
                                    {
                                        string paramName = writer.GetSuitableParameterName(cond.ParamName);
                                        writer.Write(":" + paramName);
                                        AddParameter(dbCmd, paramName, end, ParameterDirection.Input);
                                    }
                                }
                                else
                                {
                                    string paramName = writer.GetSuitableParameterName(cond.ParamName);
                                    writer.Write(":" + paramName);
                                    AddParameter(dbCmd, paramName, value, ParameterDirection.Input);
                                }
                            }
                        }
                    }
                }

                if (phrase.IsNot)
                {
                    writer.Write(")");
                }

                isFirst = false;
                phrase  = phrase.Next as APSqlWherePhrase;
            }

            writer.Write(")");
        }
Exemplo n.º 4
0
		private void WriteValues(ParserWriter writer, APSqlValuesClause clause, SqlCommand dbCmd)
		{
			if (clause != null && clause.Next != null)
			{
				writer.WriteLine();
				writer.WriteDirect("VALUES");
				APSqlSetPhrase phrase = clause.Next;
				bool isFirst = true;

				writer.Write('(');
				while (phrase != null)
				{
					if (!isFirst)
						writer.Write(',');
					else
						isFirst = false;

					if (!TryWriteValue(writer, phrase.Value))
					{
						string paramName = writer.GetSuitableParameterName(phrase.ParamName);
						writer.Write("@" + paramName);
						AddParameter(dbCmd, paramName, phrase.Value, ParameterDirection.Input);
					}

					phrase = phrase.Next as APSqlSetPhrase;
				}
				writer.Write(')');
			}
		}
Exemplo n.º 5
0
		private void WriteConditionPhrase(ParserWriter writer, APSqlWherePhrase phrase, APSqlConditionJoinType join, SqlCommand dbCmd)
		{
			bool isFirst = true;
			writer.Write("(");

			while (phrase != null)
			{
				if (!isFirst)
					writer.Write(join.ToString());

				if (phrase.IsNot)
					writer.Write("NOT (");

				if (phrase is APSqlConditionAndPhrase)
				{
					WriteConditionPhrase(writer, (phrase as APSqlConditionAndPhrase).Child, APSqlConditionJoinType.AND, dbCmd);
				}
				else if (phrase is APSqlConditionOrPhrase)
				{
					WriteConditionPhrase(writer, (phrase as APSqlConditionOrPhrase).Child, APSqlConditionJoinType.OR, dbCmd);
				}
				else
				{
					APSqlConditionPhrase cond = phrase as APSqlConditionPhrase;

					// for this, if columnDef is null, mean this is a 'EXISTS ( subquery )' phrase
					// do not 
					// change to check ConditionOperator.
					if (cond.ConditionOperator != APSqlConditionOperator.Exists && cond.ConditionOperator != APSqlConditionOperator.NotExists)
						WriteSelectExpression(writer, cond.Expr);


					if (cond.ConditionOperator == APSqlConditionOperator.Equals /*&& !cond.IsRelationDef*/ && (cond.Value == null || cond.Value == DBNull.Value))
					{
						writer.Write("IS NULL");
					}
					else if (cond.ConditionOperator == APSqlConditionOperator.NotEqual /*&& !cond.IsRelationDef*/ && (cond.Value == null || cond.Value == DBNull.Value))
					{
						writer.Write("IS NOT NULL");
					}
					else
					{
						switch (cond.ConditionOperator)
						{
							case APSqlConditionOperator.Equals: writer.Write("="); break;
							case APSqlConditionOperator.NotEqual: writer.Write("<>"); break;
							case APSqlConditionOperator.GreaterThan: writer.Write(">"); break;
							case APSqlConditionOperator.GreaterThanOrEqual: writer.Write(">="); break;
							case APSqlConditionOperator.LessThan: writer.Write("<"); break;
							case APSqlConditionOperator.LessThanOrEqual: writer.Write("<="); break;
							case APSqlConditionOperator.Between: writer.Write("BETWEEN"); break;
							case APSqlConditionOperator.NotBetween: writer.Write("NOT BETWEEN"); break;
							case APSqlConditionOperator.Like: writer.Write("LIKE"); break;
							case APSqlConditionOperator.NotLike: writer.Write("NOT LIKE"); break;
							case APSqlConditionOperator.In: writer.Write("IN"); break;
							case APSqlConditionOperator.NotIn: writer.Write("NOT IN"); break;
							case APSqlConditionOperator.Exists: writer.Write("EXISTS"); break;
							case APSqlConditionOperator.NotExists: writer.Write("NOT EXISTS"); break;
						}

						object value = cond.Value;

						if (!TryWriteValue(writer, value))
						{
							if (value is APSqlSelectCommand)
							{
								switch (cond.SubQueryScalarRestrict)
								{
									case APSqlSubQueryScalarRestrict.All: writer.Write("ALL"); break;
									case APSqlSubQueryScalarRestrict.Some: writer.Write("SOME"); break;
									case APSqlSubQueryScalarRestrict.Any: writer.Write("ANY"); break;
								}

								writer.Write("(");
								int idented = writer.Idented++;
								writer.WriteLine();
								ParseSelectInternal(value as APSqlSelectCommand, 0, dbCmd, writer);
								writer.Idented = idented;
								writer.Write(")");
							}
							else
							{
								if (cond.ConditionOperator == APSqlConditionOperator.In || cond.ConditionOperator == APSqlConditionOperator.NotIn)
								{
									writer.Write("(");
									int i = 0;
									foreach (object val in value as Array)
									{
										if (i != 0)
											writer.Write(',');
										string paramName = writer.GetSuitableParameterName(cond.ParamName);
										paramName = String.Format("@{0}${1}", paramName, i);
										writer.Write(paramName);
										AddParameter(dbCmd, paramName, val, ParameterDirection.Input);
										i++;
									}
									writer.Write(")");
								}
								else if (cond.ConditionOperator == APSqlConditionOperator.Between || cond.ConditionOperator == APSqlConditionOperator.NotBetween)
								{
									object begin = (value as Array).GetValue(0);
									object end = (value as Array).GetValue(1);


									if (!TryWriteValue(writer, begin))
									{
										string paramName = writer.GetSuitableParameterName(cond.ParamName);
										writer.Write("@" + paramName);
										AddParameter(dbCmd, paramName, begin, ParameterDirection.Input);
									}
									writer.Write("AND");

									if (!TryWriteValue(writer, end))
									{
										string paramName = writer.GetSuitableParameterName(cond.ParamName);
										writer.Write("@" + paramName);
										AddParameter(dbCmd, paramName, end, ParameterDirection.Input);
									}
								}
								else
								{
									string paramName = writer.GetSuitableParameterName(cond.ParamName);
									writer.Write("@" + paramName);
									AddParameter(dbCmd, paramName, value, ParameterDirection.Input);
								}
							}
						}
					}
				}

				if (phrase.IsNot)
					writer.Write(")");

				isFirst = false;
				phrase = phrase.Next as APSqlWherePhrase;
			}

			writer.Write(")");
		}
Exemplo n.º 6
0
		private void WriteSet(ParserWriter writer, APSqlValuesClause clause, OracleCommand dbCmd)
		{
			if (clause != null && clause.Next != null)
			{
				writer.WriteLine();
				writer.WriteDirect("SET");
				APSqlSetPhrase phrase = clause.Next;
				bool isFirst = true;

				while (phrase != null)
				{
					if (!isFirst)
						writer.Write(',');
					else
						isFirst = false;

					writer.Write(phrase.AssignmentExpr.SelectExpr);
					writer.Write("=");

					if (!TryWriteValue(writer, phrase.Value))
					{
						string paramName = "v_" + writer.GetSuitableParameterName(phrase.ParamName);
						writer.Write(":" + paramName);
						AddParameter(dbCmd, paramName, phrase.Value, ParameterDirection.Input);
					}

					phrase = phrase.Next as APSqlSetPhrase;
				}
			}
		}