コード例 #1
0
        public virtual int Delete(IDb db, IQuery query)
        {
            ErrorIfSPResult();
            int        result   = 0;
            OrlQuery   sqlquery = (OrlQuery)query; //as OrlQuery;
            string     sql      = GetDeleteSql(sqlquery);
            IDbCommand cmd      = null;

            try
            {
                cmd             = db.Connection.CreateCommand();
                cmd.CommandText = sql;
                cmd.CommandType = CommandType.Text;
                cmd.Transaction = db.Transaction;
                if (sqlquery != null)
                {
                    sqlquery.SetParameters(cmd);
                }
                cmd.Prepare();

                TraceObject.Instance.TraceCommand(cmd);

                result = cmd.ExecuteNonQuery();
            }
            finally
            {
                if (cmd != null)
                {
                    cmd.Dispose();
                    cmd = null;
                }
            }
            return(result);
        }
コード例 #2
0
 public virtual void SetParameters(IDbCommand cmd)
 {
     if (HasQuery)
     {
         query.SetParameters(cmd);
     }
     else
     {
         string           pn = string.Format(":{0}", index);
         IDbDataParameter p  = cmd.CreateParameter();
         p.ParameterName = pn;
         SqlUtils.PrepParam(p, val);
         cmd.Parameters.Add(p);
     }
 }
コード例 #3
0
        public virtual void Select(IDb db, IQuery query, IList list)
        {
            ErrorIfSPResult();
            OrlQuery    sqlquery = (OrlQuery)query;
            string      sql      = GetSelectSql(sqlquery);
            IDbCommand  cmd      = null;
            IDataReader reader   = null;

            try
            {
                cmd             = db.Connection.CreateCommand();
                cmd.CommandText = sql;
                cmd.CommandType = CommandType.Text;
                cmd.Transaction = db.Transaction;
                if (sqlquery != null)
                {
                    sqlquery.SetParameters(cmd);
                }
                cmd.Prepare();

                TraceObject.Instance.TraceCommand(cmd);

                reader = cmd.ExecuteReader();
                FillByIndex(reader, list);
            }
            finally
            {
                if (reader != null)
                {
                    if (!reader.IsClosed)
                    {
                        reader.Close();
                    }
                    reader.Dispose();
                    reader = null;
                }
                if (cmd != null)
                {
                    cmd.Dispose();
                    cmd = null;
                }
            }
            FireTriggers(list, new TriggerEventArgs(db, Timing.AfterActivate));
        }