Beispiel #1
0
 /// <summary>
 /// 更新指定参数并返回当前语句
 /// </summary>
 /// <param name="condition">更新条件(当满足条件时更新该指定字段)</param>
 /// <param name="columnName">字段名</param>
 /// <param name="function">函数</param>
 /// <exception cref="ArgumentNullException">函数不能为空</exception>
 /// <returns>当前语句</returns>
 /// <example>
 /// <code lang="C#">
 /// <![CDATA[
 /// IDatabase db = DatabaseFactory.CreateDatabase();
 /// Boolean updateTime = true;
 ///
 /// UpdateCommand cmd = db.CreateUpdateCommand("tbl_Users")
 ///     .Set((() => { return updateTime; }), "LastLoginTime", db.Functions.Now());
 ///     .Where(c => c.Equal("UserID", 1));
 ///
 /// //UPDATE tbl_Users SET LastLoginTime = GETDATE() WHERE UserID = @UserID
 /// //@UserID = 1
 /// //"GETDATE()" will be changed into "NOW()" in Access or MySQL, "SYSDATE" in Oracle, or "DATETIME('NOW')" in SQLite.
 ///
 /// Boolean success = cmd.Result() > 0;
 /// ]]>
 /// </code>
 /// </example>
 public UpdateCommand Set(Func <Boolean> condition, String columnName, ISqlFunction function)
 {
     if (condition())
     {
         return(this.Set(columnName, function));
     }
     else
     {
         return(this);
     }
 }
        /// <summary>
        /// 查询指定函数语句并返回当前语句
        /// </summary>
        /// <param name="function">函数</param>
        /// <param name="aliasesName">别名</param>
        /// <exception cref="ArgumentNullException">函数不能为空</exception>
        /// <returns>当前语句</returns>
        public SelectCommand Query(ISqlFunction function, String aliasesName)
        {
            if (function == null)
            {
                throw new ArgumentNullException("function");
            }

            this._queryFields.Add(SqlQueryField.InternalCreateFromFunction(function.ToString(this.DatabaseType), aliasesName));

            if (function.HasParameters)
            {
                this._parameters.AddRange(function.GetAllParameters());
            }

            return(this);
        }
Beispiel #3
0
        /// <summary>
        /// 插入指定参数并返回当前语句
        /// </summary>
        /// <param name="columnName">字段名</param>
        /// <param name="function">函数</param>
        /// <exception cref="ArgumentNullException">函数不能为空</exception>
        /// <returns>当前语句</returns>
        public InsertCommand Add(String columnName, ISqlFunction function)
        {
            if (function == null)
            {
                throw new ArgumentNullException("function");
            }

            this._parameters.Add(SqlParameter.CreateCustomAction(columnName, function.ToString(this.DatabaseType)));

            if (function.HasParameters)
            {
                this._parameters.AddRange(function.GetAllParameters());
            }

            return(this);
        }
Beispiel #4
0
        /// <summary>
        /// 更新指定参数并返回当前语句
        /// </summary>
        /// <param name="columnName">字段名</param>
        /// <param name="function">函数</param>
        /// <exception cref="ArgumentNullException">函数不能为空</exception>
        /// <returns>当前语句</returns>
        /// <example>
        /// <code lang="C#">
        /// <![CDATA[
        /// IDatabase db = DatabaseFactory.CreateDatabase();
        /// UpdateCommand cmd = db.CreateUpdateCommand("tbl_Users")
        ///     .Set("LastLoginTime", db.Functions.Now());
        ///     .Where(c => c.Equal("UserID", 1));
        ///
        /// //UPDATE tbl_Users SET LastLoginTime = GETDATE() WHERE UserID = @UserID
        /// //@UserID = 1
        /// //"GETDATE()" will be changed into "NOW()" in Access or MySQL, "SYSDATE" in Oracle, or "DATETIME('NOW')" in SQLite.
        ///
        /// Boolean success = cmd.Result() > 0;
        /// ]]>
        /// </code>
        /// </example>
        public UpdateCommand Set(String columnName, ISqlFunction function)
        {
            if (function == null)
            {
                throw new ArgumentNullException("function");
            }

            this._updateFields.Add(this.CreateDataParameterCustomAction(columnName, function.GetCommandText()));

            if (function.HasParameters)
            {
                this._parameters.AddRange(function.GetAllParameters());
            }

            return(this);
        }
Beispiel #5
0
        /// <summary>
        /// Registers the functions.
        /// </summary>
        /// <param name="sqlFunction">The SQL function.</param>
        /// <exception cref="ArgumentNullException"></exception>
        protected void RegisterFunctions(ISqlFunction sqlFunction)
        {
            if (sqlFunction == null)
            {
                throw new ArgumentNullException(nameof(sqlFunction));
            }

            lock (lockFunctionMap)
            {
                ISqlFunction func;
                if (FunctionMap.TryGetValue(sqlFunction.Name, out func))
                {
                    FunctionMap.Remove(sqlFunction.Name);
                }

                FunctionMap.Add(sqlFunction.Name, sqlFunction);
            }
        }
Beispiel #6
0
 /// <inheritdoc />
 public ISqlObject CreateField(ISqlFunction function, string name)
 {
     return(new MySqlField(function, name));
 }
 /// <summary>
 /// Initialize a new instance of SqlServerSource class from a function.
 /// </summary>
 /// <param name="function">A SQL function.</param>
 /// <param name="name">Source name.</param>
 /// <exception cref="System.ArgumentException"><paramref name="function"/> is null.</exception>
 /// <exception cref="System.ArgumentException"><paramref name="name"/> is null or empty.</exception>
 public SqlServerSource(ISqlFunction function, string name)
     : base(new SqlObject(function, name, new SqlServerObjectFullnameProvider(), new SqlServerObjectNamedSqlStringProvider(false)))
 {
 }
        /// <summary>
        /// 更新指定参数并返回当前语句
        /// </summary>
        /// <param name="columnName">字段名</param>
        /// <param name="function">函数</param>
        /// <exception cref="ArgumentNullException">函数不能为空</exception>
        /// <returns>当前语句</returns>
        /// <example>
        /// <code lang="C#">
        /// <![CDATA[
        /// IDatabase db = DatabaseFactory.CreateDatabase();
        /// UpdateCommand cmd = db.CreateUpdateCommand("tbl_Users")
        ///     .Set("LastLoginTime", db.Functions.Now());
        ///     .Where(c => c.Equal("UserID", 1));
        /// 
        /// //UPDATE tbl_Users SET LastLoginTime = GETDATE() WHERE UserID = @UserID
        /// //@UserID = 1
        /// //"GETDATE()" will be changed into "NOW()" in Access or MySQL, "SYSDATE" in Oracle, or "DATETIME('NOW')" in SQLite.
        /// 
        /// Boolean success = cmd.Result() > 0;
        /// ]]>
        /// </code>
        /// </example>
        public UpdateCommand Set(String columnName, ISqlFunction function)
        {
            if (function == null)
            {
                throw new ArgumentNullException("function");
            }

            this._parameters.Add(this.CreateSqlParameterCustomAction(columnName, function.GetCommandText()));

            if (function.HasParameters)
            {
                this._parameters.AddRange(function.GetAllParameters());
            }

            return this;
        }
Beispiel #9
0
 protected override void Walk(bool skipColumns, Func <IQueryExpression, IQueryExpression> func)
 {
     Function = (ISqlFunction)Function.Walk(skipColumns, func);
 }
Beispiel #10
0
 public FuncLike(ISqlFunction func)
     : base(func.Precedence)
 {
     Function = func;
 }
 /// <summary>
 /// 查询指定函数语句并返回当前语句
 /// </summary>
 /// <param name="function">函数</param>
 /// <returns>当前语句</returns>
 public SelectCommand Query(ISqlFunction function)
 {
     return(this.Query(function, String.Empty));
 }
Beispiel #12
0
 /// <summary>
 /// Initialize a new instance of MySqlField class from a function.
 /// </summary>
 /// <param name="function">A SQL function.</param>
 /// <param name="name">Field name.</param>
 /// <exception cref="System.ArgumentException"><paramref name="function"/> is null.</exception>
 /// <exception cref="System.ArgumentException"><paramref name="name"/> is null or empty.</exception>
 public MySqlField(ISqlFunction function, string name)
     : base(new SqlObject(function, name, new MySqlObjectFullnameProvider(), new MySqlObjectNamedSqlStringProvider()))
 {
 }
        /// <summary>
        /// 查询指定函数语句并返回当前语句
        /// </summary>
        /// <param name="function">函数</param>
        /// <param name="aliasesName">别名</param>
        /// <exception cref="ArgumentNullException">函数不能为空</exception>
        /// <returns>当前语句</returns>
        public SelectCommand Query(ISqlFunction function, String aliasesName)
        {
            if (function == null)
            {
                throw new ArgumentNullException("function");
            }

            this._queryFields.Add(SqlQueryField.InternalCreateFromFunction(function.ToString(this.DatabaseType), aliasesName));

            if (function.HasParameters)
            {
                this._parameters.AddRange(function.GetAllParameters());
            }

            return this;
        }
 /// <summary>
 /// 查询指定函数语句并返回当前语句
 /// </summary>
 /// <param name="function">函数</param>
 /// <returns>当前语句</returns>
 public SelectCommand Query(ISqlFunction function)
 {
     return this.Query(function, String.Empty);
 }
Beispiel #15
0
 /// <summary>
 /// Initialize a new instance of SqlServerField class from a function.
 /// </summary>
 /// <param name="function">A SQL function.</param>
 /// <param name="name">Field name.</param>
 /// <exception cref="System.ArgumentException"><paramref name="function"/> is null.</exception>
 /// <exception cref="System.ArgumentException"><paramref name="name"/> is null or empty.</exception>
 public SqlServerField(ISqlFunction function, string name)
     : this((ISqlExpression)function, name)
 {
 }
Beispiel #16
0
 protected override void BuildFunction(ISqlFunction func)
 {
     func = ConvertFunctionParameters(func);
     base.BuildFunction(func);
 }