Beispiel #1
0
        /// <summary>
        /// insert () select
        /// </summary>
        /// <param name="SelectCmd"></param>
        /// <param name="Columns">select的字段</param>
        /// <returns></returns>
        public virtual bool Insert(ODACmd SelectCmd, params IODAColumns[] Columns)
        {
            try
            {
                var sql = new ODAScript()
                {
                    ScriptType = SQLType.Insert,
                };
                sql.SqlScript.Append("INSERT INTO ").Append(this.CmdName).Append("(");
                string Column = "";
                for (int i = 0; i < Columns.Length; i++)
                    Column += Columns[i].ColumnName + ",";
                sql.SqlScript.Append(Column.Remove(Column.Length - 1, 1)).Append(") ");
                var sSql = SelectCmd.GetSelectSql(Columns);
                sql.Merge(sSql);

                var db = this.GetDBAccess(sql);
                if (db == null)
                    throw new ODAException(10016, "ODACmd Insert 没有执行程序");
                var prms = sql.ParamList.ToArray();
                return db.ExecuteSQL(sql.SqlScript.ToString(), prms) > 0;
            }
            finally
            {
                this.Clear();
            }
        }
Beispiel #2
0
        /// <summary>
        ///  获取在 where 语句中使用的函表达式及其参数
        /// </summary>
        /// <param name="ConIndex">此参数无效</param>
        /// <param name="SubSql">函数表达式</param>
        /// <returns>函数表达式的参数</returns>
        protected override ODAScript GetWhereSubstring()
        {
            ODAScript sql = new ODAScript();

            if (_FuncType == Func.Exists)
            {
                var sSql = _FuncCmd.GetSelectSql(_FunColumnList.ToArray());
                sql.Merge(sSql);
                sql.SqlScript.Clear();
                sql.SqlScript.Append(_FuncName).Append(" ( ").Append(sSql.SqlScript.ToString()).Append(")");
                return(sql);
            }
            else if (_FuncType == Func.Normal) ///形如:having UserFunc(@params1,@params2) > 0
            {
                var wSql = base.GetWhereSubstring();
                var fSql = this.GetNormalFunctionSql();
                wSql.SqlScript.Replace(_FuncName, fSql.SqlScript.ToString());
                sql.Merge(fSql);
                sql.SqlScript.Clear();
                sql.SqlScript.Append(wSql.SqlScript.ToString());
                return(sql);
            }
            else if (_FuncType == Func.Express)
            {
                var wSql = base.GetWhereSubstring(); ///形如:having count(*) > 0
                wSql.ParamList.InsertRange(0, _ExpressPrms);
                return(wSql);
            }
            else
            {
                throw new ODAException(40007, string.Format("{0} Function not for Select", _FuncName));
            }
        }