/// <summary>
        /// 添加SQL Having查询语句并返回当前SQL语句创建类
        /// </summary>
        /// <param name="condition">Having条件语句</param>
        /// <returns>当前SQL语句创建类</returns>
        internal SqlCommandBuilder AppendHaving(ISqlCondition condition)
        {
            if (condition != null)
            {
                this._stringBuilder.Append("HAVING ").Append(condition.ToString()).Append(' ');
            }

            return(this);
        }
Пример #2
0
        /// <summary>
        /// 创建新的Sql Not条件语句
        /// </summary>
        /// <param name="cmd">Sql语句</param>
        /// <param name="condition">条件语句</param>
        /// <exception cref="ArgumentNullException">Sql条件语句不能为空</exception>
        /// <returns>Sql Not条件语句</returns>
        internal static SqlNotCondition Create(AbstractSqlCommandWithWhere cmd, ISqlCondition condition)
        {
            if (condition == null)
            {
                throw new ArgumentNullException("condition");
            }

            return(new SqlNotCondition(cmd, condition));
        }
        /// <summary>
        /// 添加SQL Where查询语句并返回当前SQL语句创建类
        /// </summary>
        /// <param name="condition">Where条件语句</param>
        /// <returns>当前SQL语句创建类</returns>
        internal SqlCommandBuilder AppendWhere(ISqlCondition condition)
        {
            if (condition != null)
            {
                this._stringBuilder.Append("WHERE ").Append(condition.ToString()).Append(' ');
            }

            return(this);
        }
Пример #4
0
        /// <summary>
        /// 获取选择语句内容
        /// </summary>
        /// <param name="baseCommand">源选择语句</param>
        /// <param name="orderReverse">是否反转排序</param>
        /// <returns>选择语句内容</returns>
        internal static String InternalGetPagerCommand(SelectCommand baseCommand, Boolean orderReverse)
        {
            SqlCommandBuilder sb = new SqlCommandBuilder(baseCommand.Database);

            sb.AppendSelectPrefix();
            sb.AppendSelectDistinct(baseCommand.UseDistinct).AppendAllColumnNames(baseCommand.UseDistinct, baseCommand.InternalGetQueryFieldList());

            if (baseCommand.PageSize > 0 && baseCommand.RecordStart > 0)//分页模式
            {
                /*
                 *  SELECT * FROM
                 *  (
                 *      SELECT *, ROWNUM RN
                 *      FROM (SELECT * FROM TABLE_NAME)
                 *      WHERE ROWNUM <= 30
                 *  )
                 *  WHERE RN > 20
                 */

                SelectCommand innestCommand = baseCommand.Database.InternalCreateSelectCommand(baseCommand, baseCommand.TableName);
                innestCommand.InternalSetQueryFieldList(baseCommand);
                innestCommand.InternalSetJoinList(baseCommand);
                innestCommand.InternalSetWhereCondition(baseCommand);
                innestCommand.InternalSetGroupByFieldList(baseCommand);
                innestCommand.InternalSetHavingCondition(baseCommand);
                innestCommand.InternalSetOrderList(baseCommand);

                SelectCommand innerCommand = baseCommand.Database.InternalCreateSelectCommand(baseCommand, innestCommand, "");
                innerCommand.InternalSetWhereCondition(innerCommand.ConditionBuilder.LessThanOrEqualColumn("ROWNUM", (baseCommand.RecordStart + baseCommand.PageSize).ToString()));
                innerCommand.InternalQuerys(baseCommand.QueryFields);
                innerCommand.InternalQuerys(SqlQueryField.InternalCreateFromFunction(baseCommand, "ROWNUM", "RN"));

                sb.AppendSelectFrom(innerCommand.GetCommandText(), true);
                sb.AppendWhere(baseCommand.ConditionBuilder.GreaterThanColumn("RN", baseCommand.RecordStart.ToString()));
            }
            else//正常模式
            {
                sb.AppendSelectFromAndJoins(baseCommand.TableName, baseCommand.IsFromSql, baseCommand.InternalGetJoinList());

                ISqlCondition where = baseCommand.WhereCondition;

                if (baseCommand.PageSize > 0)
                {
                    where = baseCommand.ConditionBuilder.And(where, baseCommand.ConditionBuilder.LessThanOrEqualColumn("ROWNUM", baseCommand.PageSize.ToString()));
                }

                sb.AppendWhere(where);
                sb.AppendSelectGroupBys(baseCommand.InternalGetGroupByFieldList());
                sb.AppendHaving(baseCommand.InternalGetHavingCondition());
                sb.AppendSelectOrderBys(baseCommand.InternalGetOrderList(), orderReverse);
            }

            return(sb.ToString());
        }
Пример #5
0
 /// <summary>
 /// 使用Or连接条件
 /// </summary>
 /// <param name="condition">过滤条件</param>
 public ISqlBuilder Or(string condition)
 {
     if (condition.IsEmpty())
     {
         return(this);
     }
     if (_condition == null)
     {
         _condition = SqlCondition.Create(condition);
         return(this);
     }
     _condition = new OrCondition(_condition.GetCondition(), condition);
     return(this);
 }
Пример #6
0
 /// <summary>
 /// 初始化Sql Not条件语句类
 /// </summary>
 /// <param name="baseCommand">源Sql语句</param>
 /// <param name="baseCondition">基础Sql条件语句</param>
 private SqlNotCondition(AbstractSqlCommandWithWhere baseCommand, ISqlCondition baseCondition)
     : base(baseCommand)
 {
     this._baseCondition = baseCondition;
 }
Пример #7
0
 public static string And(ISqlCondition condition) => condition != null ? $"{S.And} {condition.ToSql()}" : null;
Пример #8
0
        /// <summary>
        /// 添加SQL Where查询语句并返回当前SQL语句创建类
        /// </summary>
        /// <param name="condition">Where条件语句</param>
        /// <returns>当前SQL语句创建类</returns>
        internal SqlCommandBuilder AppendWhere(ISqlCondition condition)
        {
            if (condition != null)
            {
                this._stringBuilder.Append("WHERE ").Append(condition.GetClauseText()).Append(' ');
            }

            return this;
        }
Пример #9
0
 public void TestEnds() {
     _condition = SqlCondition.Create( "a", "@", Operator.Ends );
     Assert.AreEqual( "a Like @a", _condition.GetCondition() );
 }
Пример #10
0
 public void TestGreater() {
     _condition = SqlCondition.Create( "a", "@", Operator.Greater );
     Assert.AreEqual( "a>@a", _condition.GetCondition() );
 }
Пример #11
0
        /// <summary>
        /// 设置指定查询的语句并返回当前语句
        /// </summary>
        /// <param name="having">查询语句</param>
        /// <returns>当前语句</returns>
        public SelectCommand Having(ISqlCondition having)
        {
            this._having = having;

            return this;
        }
Пример #12
0
 /// <summary>
 /// 使用Or连接条件
 /// </summary>
 /// <param name="condition">过滤条件</param>
 public ISqlBuilder Or( ISqlCondition condition ) {
     return Or( condition.GetCondition() );
 }
Пример #13
0
 public ISqlOn AndNot(ISqlCondition clause) => And(SqlCondition.Not(clause));
Пример #14
0
 public ISqlOn And(ISqlCondition clause) => Chain(() => AndRaw = clause);
Пример #15
0
 public SqlOn(ISqlCondition clause)
 {
     ConditionRaw = clause;
 }
Пример #16
0
 public ISqlWhere OrNot(ISqlCondition clause) => Chain(() => SqlCondition.Not(clause));
Пример #17
0
 public ISqlWhere AndNot(ISqlCondition clause) => Chain(() => AndRaw = SqlCondition.Not(clause));
Пример #18
0
 public SqlWhere(ISqlCondition clause)
 {
     ConditionRaw = clause;
 }
Пример #19
0
        /// <summary>
        /// 添加SQL Having查询语句并返回当前SQL语句创建类
        /// </summary>
        /// <param name="condition">Having条件语句</param>
        /// <returns>当前SQL语句创建类</returns>
        internal SqlCommandBuilder AppendHaving(ISqlCondition condition)
        {
            if (condition != null)
            {
                this._stringBuilder.Append("HAVING ").Append(condition.GetClauseText()).Append(' ');
            }

            return this;
        }
Пример #20
0
 /// <summary>
 /// 设置查询语句
 /// </summary>
 /// <param name="where">查询语句</param>
 internal void InternalSetWhereCondition(ISqlCondition where)
 {
     this._where = where;
 }
Пример #21
0
        /// <summary>
        /// 设置指定查询的语句并返回当前语句
        /// </summary>
        /// <param name="where">查询语句</param>
        /// <returns>当前语句</returns>
        public AbstractSqlCommandWithWhere Where(Func <SqlConditionBuilder, ISqlCondition> where)
        {
            this._where = where (this._conditionBuilder);

            return(this);
        }
Пример #22
0
 public ISqlOn Or(ISqlCondition clause) => Chain(() => OrRaw = clause);
Пример #23
0
        /// <summary>
        /// 设置指定查询的语句并返回当前语句
        /// </summary>
        /// <param name="where">查询语句</param>
        /// <returns>当前语句</returns>
        public SelectCommand Where(ISqlCondition where)
        {
            this._where = where;

            return this;
        }
Пример #24
0
 public ISqlOn OrNot(ISqlCondition clause) => Or(SqlCondition.Not(clause));
Пример #25
0
 public ISqlUpdate WhereNot(ISqlCondition clause) => Where(SqlCondition.Not(clause));
Пример #26
0
 public ISqlSelect WhereNot(ISqlCondition clause) => Where(SqlCondition.Not(clause));
Пример #27
0
 public void TestLessEqual() {
     _condition = SqlCondition.Create( "a", "@", Operator.LessEqual );
     Assert.AreEqual( "a<=@a", _condition.GetCondition() );
 }
Пример #28
0
 /// <summary>
 /// 使用And连接条件
 /// </summary>
 /// <param name="condition">过滤条件</param>
 public ISqlBuilder And(ISqlCondition condition)
 {
     return(And(condition.GetCondition()));
 }
Пример #29
0
 public ISqlSelect Where(ISqlCondition clause) => Where(new SqlWhere(clause));
Пример #30
0
 public static string Or(ISqlCondition condition) => condition != null ? $"{S.Or} {condition.ToSql()}" : null;
Пример #31
0
        /// <summary>
        /// 设置指定查询的语句并返回当前语句
        /// </summary>
        /// <param name="where">查询语句</param>
        /// <returns>当前语句</returns>
        /// <example>
        /// <code lang="C#">
        /// <![CDATA[
        /// IDatabase db = DatabaseFactory.CreateDatabase();
        /// UpdateCommand cmd = db.CreateUpdateCommand("tbl_Users")
        ///     .Set("UserName", "admin");
        /// 
        /// cmd.Where(SqlCondition.Equal(cmd, "UserID", 1));
        /// 
        /// //UPDATE tbl_Users SET UserName = @UserName WHERE UserID = @UserID
        /// //@UserName = "******"
        /// //@UserID = 1
        /// 
        /// Boolean success = cmd.Result() > 0;
        /// ]]>
        /// </code>
        /// </example>
        public UpdateCommand Where(ISqlCondition where)
        {
            this._where = where;

            return this;
        }
 /// <summary>
 /// 设置查询语句
 /// </summary>
 /// <param name="command">另一个语句</param>
 internal void InternalSetWhereCondition(AbstractSqlCommandWithWhere command)
 {
     this._where = command._where;
 }
Пример #33
0
 /// <summary>
 /// 使用Or连接条件
 /// </summary>
 /// <param name="condition">过滤条件</param>
 public ISqlBuilder Or(ISqlCondition condition)
 {
     return(Or(condition.GetCondition()));
 }
 /// <summary>
 /// 设置查询语句
 /// </summary>
 /// <param name="where">查询语句</param>
 internal void InternalSetWhereCondition(ISqlCondition where)
 {
     this._where = where;
 }
        /// <summary>
        /// 设置指定查询的语句并返回当前语句
        /// </summary>
        /// <param name="where">查询语句</param>
        /// <returns>当前语句</returns>
        public AbstractSqlCommandWithWhere Where(ISqlCondition where)
        {
            this._where = where;

            return this;
        }
        /// <summary>
        /// 设置指定查询的语句并返回当前语句
        /// </summary>
        /// <param name="where">查询语句</param>
        /// <returns>当前语句</returns>
        public AbstractSqlCommandWithWhere Where(Func<SqlConditionBuilder, ISqlCondition> where)
        {
            this._where = where(this._conditionBuilder);

            return this;
        }
Пример #37
0
        /// <summary>
        /// 创建新的Sql Not条件语句
        /// </summary>
        /// <param name="cmd">Sql语句</param>
        /// <param name="condition">条件语句</param>
        /// <exception cref="ArgumentNullException">Sql条件语句不能为空</exception>
        /// <returns>Sql Not条件语句</returns>
        internal static SqlNotCondition Create(AbstractSqlCommandWithWhere cmd, ISqlCondition condition)
        {
            if (condition == null)
            {
                throw new ArgumentNullException("condition");
            }

            return new SqlNotCondition(cmd, condition);
        }
Пример #38
0
        /// <summary>
        /// 设置指定查询的语句并返回当前语句
        /// </summary>
        /// <param name="where">查询语句</param>
        /// <returns>当前语句</returns>
        /// <example>
        /// <code lang="C#">
        /// <![CDATA[
        /// IDatabase db = DatabaseFactory.CreateDatabase();
        /// UpdateCommand cmd = db.CreateUpdateCommand("tbl_Users")
        ///     .Set("UserName", "admin");
        ///
        /// cmd.Where(SqlCondition.Equal(cmd, "UserID", 1));
        ///
        /// //UPDATE tbl_Users SET UserName = @UserName WHERE UserID = @UserID
        /// //@UserName = "******"
        /// //@UserID = 1
        ///
        /// Boolean success = cmd.Result() > 0;
        /// ]]>
        /// </code>
        /// </example>
        public new UpdateCommand Where(ISqlCondition where)
        {
            this._where = where;

            return(this);
        }
Пример #39
0
 /// <summary>
 /// 设置查询语句
 /// </summary>
 /// <param name="command">另一个语句</param>
 internal void InternalSetWhereCondition(AbstractSqlCommandWithWhere command)
 {
     this._where = command._where;
 }
Пример #40
0
        /// <summary>
        /// 设置指定查询的语句并返回当前语句
        /// </summary>
        /// <param name="having">查询语句</param>
        /// <returns>当前语句</returns>
        public SelectCommand Having(ISqlCondition having)
        {
            this._having = having;

            return(this);
        }
Пример #41
0
        /// <summary>
        /// 设置指定查询的语句并返回当前语句
        /// </summary>
        /// <param name="where">查询语句</param>
        /// <returns>当前语句</returns>
        public AbstractSqlCommandWithWhere Where(ISqlCondition where)
        {
            this._where = where;

            return(this);
        }
Пример #42
0
        /// <summary>
        /// 设置指定查询的语句并返回当前语句
        /// </summary>
        /// <param name="where">查询语句</param>
        /// <returns>当前语句</returns>
        public SelectCommand Where(ISqlCondition where)
        {
            this._where = where;

            return(this);
        }
Пример #43
0
 /// <summary>
 /// 使用And连接条件
 /// </summary>
 /// <param name="condition">过滤条件</param>
 public ISqlBuilder And( ISqlCondition condition ) {
     return And( condition.GetCondition() );
 }
Пример #44
0
 public ISqlDelete Where(ISqlCondition clause) => Where(new SqlWhere(clause));
Пример #45
0
 /// <summary>
 /// 使用Or连接条件
 /// </summary>
 /// <param name="condition">过滤条件</param>
 public ISqlBuilder Or( string condition ) {
     if ( condition.IsEmpty() )
         return this;
     if ( _condition == null ) {
         _condition = SqlCondition.Create( condition );
         return this;
     }
     _condition = new OrCondition( _condition.GetCondition(), condition );
     return this;
 }
Пример #46
0
 public ISqlUpdate Where(ISqlCondition clause) => Where(new SqlWhere(clause));
Пример #47
0
 /// <summary>
 /// 初始化Sql Not条件语句类
 /// </summary>
 /// <param name="baseCommand">源Sql语句</param>
 /// <param name="baseCondition">基础Sql条件语句</param>
 private SqlNotCondition(AbstractSqlCommandWithWhere baseCommand, ISqlCondition baseCondition)
     : base(baseCommand)
 {
     this._baseCondition = baseCondition;
 }
Пример #48
0
 /// <summary>
 /// 初始化Sql Not条件语句类
 /// </summary>
 /// <param name="baseCommand">源Sql语句</param>
 /// <param name="baseCondition">基础Sql条件语句</param>
 internal SqlNotCondition(AbstractSqlCommand baseCommand, ISqlCondition baseCondition)
     : base(baseCommand)
 {
     this._baseCondition = baseCondition;
 }