Esempio n. 1
0
        protected override DbCommand ParseInsert(APSqlInsertCommand command)
        {
            StringBuilder sb    = new StringBuilder();
            OracleCommand dbCmd = new OracleCommand();

            using (ParserWriter writer = new ParserWriter(sb, command.CommandNameSuitable))
            {
                APSqlInsertCommand insert = command as APSqlInsertCommand;

                if (insert.SubQuery != null)
                {
                    WriteInsertWithSubQuery(writer, insert);
                    writer.WriteLine();
                    ParseSelectInternal(insert.SubQuery, dbCmd, writer);
                }
                else
                {
                    WriteInsert(writer, insert, command.ValuesClause);
                    writer.Idented++;
                    WriteValues(writer, command.ValuesClause, dbCmd);

                    // oracle unsupport provider="Database", so
                    // do not return value.
                }
            }

            dbCmd.CommandText = sb.ToString();
            return(dbCmd);
        }
Esempio n. 2
0
        private void WriteInsertWithSubQuery(ParserWriter writer, APSqlInsertCommand command)
        {
            writer.WriteDirect("INSERT INTO");
            writer.Write(command.TableDef.TableName);

            if (command.SelectClause != null)
            {
                writer.Write("(");

                APSqlSelectPhrase phrase = command.SelectClause.Next as APSqlSelectPhrase;
                bool isFirst             = true;
                while (phrase != null)
                {
                    if (!isFirst)
                    {
                        writer.Write(',');
                    }
                    else
                    {
                        isFirst = false;
                    }

                    WriteSelectExpression(writer, phrase.Expr);

                    phrase = phrase.Next as APSqlSelectPhrase;
                }

                writer.Write(")");
            }
        }
Esempio n. 3
0
        protected override DbCommand ParseInsert(APSqlInsertCommand command)
        {
            StringBuilder sb    = new StringBuilder();
            SqlCommand    dbCmd = new SqlCommand();

            using (ParserWriter writer = new ParserWriter(sb, command.CommandNameSuitable))
            {
                if (command.SubQuery != null)
                {
                    WriteInsertWithSubQuery(writer, command);
                    writer.WriteLine();
                    ParseSelectInternal(command.SubQuery, 0, dbCmd, writer);
                }
                else
                {
                    WriteInsert(writer, command, command.ValuesClause);
                    writer.Idented++;
                    WriteValues(writer, command.ValuesClause, dbCmd);

                    if (command.NeedReturnAutoIncrement)
                    {
                        writer.Write("SELECT @@IDENTITY");
                    }
                }
            }

            dbCmd.CommandText = sb.ToString();
            return(dbCmd);
        }
Esempio n. 4
0
        private void WriteInsert(ParserWriter writer, APSqlInsertCommand command, APSqlValuesClause clause)
        {
            writer.WriteDirect("INSERT INTO");
            writer.Write(command.TableDef.TableName);

            if (clause != null && clause.Next != null)
            {
                APSqlSetPhrase phrase  = clause.Next;
                bool           isFirst = true;

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

                    writer.Write(phrase.AssignmentExpr.SelectExpr);

                    phrase = phrase.Next as APSqlSetPhrase;
                }
                writer.Write(")");
            }
        }
Esempio n. 5
0
 /// <summary>
 /// SQL 'VALUES' clause extensions.
 /// </summary>
 /// <param name="command">The command.</param>
 /// <param name="phrases">The 'SET' phrases</param>
 /// <returns>The command.</returns>
 public static APSqlInsertCommand values(this APSqlInsertCommand command, IEnumerable <APSqlSetPhrase> phrases)
 {
     if (phrases != null)
     {
         command.ValuesClause = new APSqlValuesClause(phrases);
     }
     return(command);
 }
Esempio n. 6
0
 /// <summary>
 /// SQL 'VALUES' clause extensions.
 /// </summary>
 /// <param name="command">The command.</param>
 /// <param name="phrases">The 'SET' phrases</param>
 /// <returns>The command.</returns>
 public static APSqlInsertCommand values(this APSqlInsertCommand command, params APSqlSetPhrase[] phrases)
 {
     if (phrases != null && phrases.Length != 0)
     {
         command.ValuesClause = new APSqlValuesClause(phrases);
     }
     return(command);
 }
Esempio n. 7
0
        /// <summary>
        /// Build 'INSERT' command.
        /// </summary>
        /// <param name="command">The 'INSERT' command.</param>
        /// <returns>The DbCommand.</returns>
        public DbCommand BuildInsertCommand(APSqlInsertCommand command)
        {
            if (command == null)
            {
                throw new ArgumentNullException("command");
            }

            return(ParseInsert(command));
        }
Esempio n. 8
0
        /// <summary>
        /// SQL 'VALUES' clause extensions. Add new 'SET' in clause.
        /// </summary>
        /// <param name="command">The command.</param>
        /// <param name="phrases">The 'SET' phrases.</param>
        /// <returns>The command.</returns>
        public static APSqlInsertCommand set(this APSqlInsertCommand command, params APSqlSetPhrase[] phrases)
        {
            if (command.ValuesClause == null || command.ValuesClause.Next == null)
            {
                command.ValuesClause = new APSqlValuesClause(phrases);
            }
            else
            {
                APSqlSetPhrase exist = command.ValuesClause.Last as APSqlSetPhrase;
                exist.SetNext(phrases);
            }

            return(command);
        }
Esempio n. 9
0
		/// <summary>
		/// Build 'INSERT' command.
		/// </summary>
		/// <param name="command">The 'INSERT' command.</param>
		/// <returns>The DbCommand.</returns>
		public DbCommand BuildInsertCommand(APSqlInsertCommand command)
		{
			if (command == null)
				throw new ArgumentNullException("command");

			return ParseInsert(command);
		}
Esempio n. 10
0
 /// <summary>
 /// Execute.
 /// </summary>
 /// <param name="command">The command.</param>
 /// <param name="db">The database.</param>
 /// <returns>The scale.</returns>
 public static object executeScale(this APSqlInsertCommand command, APDatabase db)
 {
     return(db.ExecuteScalar(command));
 }
Esempio n. 11
0
 /// <summary>
 /// SQL 'VALUES' clause extensions.
 /// </summary>
 /// <param name="command">The command.</param>
 /// <param name="phrase">The 'SET' phrase</param>
 /// <returns>The command.</returns>
 public static APSqlInsertCommand values(this APSqlInsertCommand command, APSqlSetPhrase phrase)
 {
     command.ValuesClause = new APSqlValuesClause(phrase);
     return(command);
 }
Esempio n. 12
0
 /// <summary>
 /// SQL SubQuery clause extensions.
 /// </summary>
 /// <param name="command">The command.</param>
 /// <param name="subQuery">SubQuery.</param>
 /// <param name="phrases">The 'SELECT' phrases.</param>
 /// <returns>The command.</returns>
 public static APSqlInsertCommand subQuery(this APSqlInsertCommand command, APSqlSelectCommand subQuery, IEnumerable <APSqlSelectPhrase> phrases)
 {
     command.SubQuery     = subQuery;
     command.SelectClause = new APSqlSelectClause(phrases);
     return(command);
 }
Esempio n. 13
0
 /// <summary>
 /// Execute.
 /// </summary>
 /// <param name="command">The command.</param>
 /// <param name="db">The database.</param>
 public static void execute(this APSqlInsertCommand command, APDatabase db)
 {
     db.ExecuteNonQuery(command);
 }
Esempio n. 14
0
 /// <summary>
 /// SQL SubQuery clause extensions.
 /// </summary>
 /// <param name="command">The command.</param>
 /// <param name="subQuery">SubQuery.</param>
 /// <param name="clause">The 'SELECT' clause.</param>
 /// <returns>The command.</returns>
 public static APSqlInsertCommand subQuery(this APSqlInsertCommand command, APSqlSelectCommand subQuery, APSqlSelectClause clause)
 {
     command.SubQuery     = subQuery;
     command.SelectClause = clause;
     return(command);
 }
Esempio n. 15
0
 /// <summary>
 /// SQL SubQuery clause extensions.
 /// </summary>
 /// <param name="command">The command.</param>
 /// <param name="subQuery">SubQuery.</param>
 /// <param name="phrases">The 'SELECT' phrases.</param>
 /// <returns>The command.</returns>
 public static APSqlInsertCommand subQuery(this APSqlInsertCommand command, APSqlSelectCommand subQuery, params APSqlSelectPhrase[] phrases)
 {
     command.SubQuery     = subQuery;
     command.SelectClause = new APSqlSelectClause(phrases);
     return(command);
 }
Esempio n. 16
0
 /// <summary>
 /// Build 'INSERT' command.
 /// </summary>
 /// <param name="command">The 'INSERT' command.</param>
 /// <returns>The DbCommand.</returns>
 public override DbCommand BuildInsertCommand(APSqlInsertCommand command)
 {
     return(_parser.BuildInsertCommand(command));
 }
Esempio n. 17
0
		protected override DbCommand ParseInsert(APSqlInsertCommand command)
		{
			StringBuilder sb = new StringBuilder();
			OracleCommand dbCmd = new OracleCommand();

			using (ParserWriter writer = new ParserWriter(sb, command.CommandNameSuitable))
			{
				APSqlInsertCommand insert = command as APSqlInsertCommand;

				if (insert.SubQuery != null)
				{
					WriteInsertWithSubQuery(writer, insert);
					writer.WriteLine();
					ParseSelectInternal(insert.SubQuery, dbCmd, writer);
				}
				else
				{
					WriteInsert(writer, insert, command.ValuesClause);
					writer.Idented++;
					WriteValues(writer, command.ValuesClause, dbCmd);

					// oracle unsupport provider="Database", so
					// do not return value.
				}
			}

			dbCmd.CommandText = sb.ToString();
			return dbCmd;
		}
Esempio n. 18
0
 /// <summary>
 /// Build 'INSERT' command.
 /// </summary>
 /// <param name="command">The 'INSERT' command.</param>
 /// <returns>The DbCommand.</returns>
 public abstract DbCommand BuildInsertCommand(APSqlInsertCommand command);
Esempio n. 19
0
		private void WriteInsert(ParserWriter writer, APSqlInsertCommand command, APSqlValuesClause clause)
		{
			writer.WriteDirect("INSERT INTO");
			writer.Write(command.TableDef.TableName);

			if (clause != null && clause.Next != null)
			{
				APSqlSetPhrase phrase = clause.Next;
				bool isFirst = true;

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

					writer.Write(phrase.AssignmentExpr.SelectExpr);

					phrase = phrase.Next as APSqlSetPhrase;
				}
				writer.Write(")");
			}
		}
Esempio n. 20
0
		/// <summary>
		/// Parse 'INSERT' command.
		/// </summary>
		/// <param name="command">The 'INSERT' command.</param>
		/// <returns>The DbCommand.</returns>
		protected abstract DbCommand ParseInsert(APSqlInsertCommand command);
Esempio n. 21
0
		private void WriteInsertWithSubQuery(ParserWriter writer, APSqlInsertCommand command)
		{
			writer.WriteDirect("INSERT INTO");
			writer.Write(command.TableDef.TableName);

			if (command.SelectClause != null)
			{
				writer.Write("(");

				APSqlSelectPhrase phrase = command.SelectClause.Next as APSqlSelectPhrase;
				bool isFirst = true;
				while (phrase != null)
				{
					if (!isFirst)
						writer.Write(',');
					else
						isFirst = false;

					WriteSelectExpression(writer, phrase.Expr);

					phrase = phrase.Next as APSqlSelectPhrase;
				}

				writer.Write(")");
			}
		}
Esempio n. 22
0
		protected override DbCommand ParseInsert(APSqlInsertCommand command)
		{
			StringBuilder sb = new StringBuilder();
			SqlCommand dbCmd = new SqlCommand();

			using (ParserWriter writer = new ParserWriter(sb, command.CommandNameSuitable))
			{
				if (command.SubQuery != null)
				{
					WriteInsertWithSubQuery(writer, command);
					writer.WriteLine();
					ParseSelectInternal(command.SubQuery, 0, dbCmd, writer);
				}
				else
				{
					WriteInsert(writer, command, command.ValuesClause);
					writer.Idented++;
					WriteValues(writer, command.ValuesClause, dbCmd);

					if (command.NeedReturnAutoIncrement)
					{
						writer.Write("SELECT @@IDENTITY");
					}
				}
			}

			dbCmd.CommandText = sb.ToString();
			return dbCmd;
		}
Esempio n. 23
0
 /// <summary>
 /// SQL 'VALUES' clause extensions. Add new 'SET' in clause.
 /// </summary>
 /// <param name="command">The command.</param>
 /// <param name="assignmentExpr">SQL assignment Expression.</param>
 /// <param name="value">Value.</param>
 /// <param name="paramName">Parameter name.</param>
 /// <returns>The command.</returns>
 public static APSqlInsertCommand set(this APSqlInsertCommand command, APSqlColumnExpr assignmentExpr, object value, string paramName)
 {
     return(set(command, new APSqlSetPhrase(assignmentExpr, value, paramName)));
 }
Esempio n. 24
0
 /// <summary>
 /// SQL 'VALUES' clause extensions. Add new 'SET' in clause.
 /// </summary>
 /// <param name="command">The command.</param>
 /// <param name="assignmentExpr">SQL assignment Expression.</param>
 /// <param name="valueExpr">SQL value of assignment Expression.</param>
 /// <returns>The command.</returns>
 public static APSqlInsertCommand set(this APSqlInsertCommand command, APSqlColumnExpr assignmentExpr, IAPSqlValueExpr valueExpr)
 {
     return(set(command, new APSqlSetPhrase(assignmentExpr, valueExpr)));
 }
Esempio n. 25
0
 /// <summary>
 /// Parse 'INSERT' command.
 /// </summary>
 /// <param name="command">The 'INSERT' command.</param>
 /// <returns>The DbCommand.</returns>
 protected abstract DbCommand ParseInsert(APSqlInsertCommand command);
Esempio n. 26
0
 /// <summary>
 /// SQL 'VALUES' clause extensions.
 /// </summary>
 /// <param name="command">The command.</param>
 /// <param name="clause">The 'VALUES' clause.</param>
 /// <returns>The command.</returns>
 public static APSqlInsertCommand values(this APSqlInsertCommand command, APSqlValuesClause clause)
 {
     command.ValuesClause = clause;
     return(command);
 }
Esempio n. 27
0
		/// <summary>
		/// Build 'INSERT' command.
		/// </summary>
		/// <param name="command">The 'INSERT' command.</param>
		/// <returns>The DbCommand.</returns>
		public override DbCommand BuildInsertCommand(APSqlInsertCommand command)
		{
			return _parser.BuildInsertCommand(command);
		}
Esempio n. 28
0
		/// <summary>
		/// Build 'INSERT' command.
		/// </summary>
		/// <param name="command">The 'INSERT' command.</param>
		/// <returns>The DbCommand.</returns>
		public abstract DbCommand BuildInsertCommand(APSqlInsertCommand command);