Exemple #1
0
        public virtual object Find(IDb session, object key)
        {
            ErrorIfSPResult();
            SqlColumn pk     = null;
            object    result = null;

            foreach (SqlColumn c in columns)
            {
                if (c.IsPK)
                {
                    pk = c;
                    break;
                }
            }
            if (pk != null)
            {
                LitQuery q = new LitQuery();
                q.Constrain(pk.Alias).Equal(key);
                IList list = new ArrayList(1);
                Select(session, q, list);
                if (list.Count > 0)
                {
                    result = list[0];
                }
            }
            return(result);
        }
Exemple #2
0
        public virtual int Delete(IDb db, IQuery query)
        {
            ErrorIfSPResult();
            int        result   = 0;
            LitQuery   sqlquery = (LitQuery)query; //as LitQuery;
            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);
        }
Exemple #3
0
        protected virtual string GetDeleteSql(LitQuery query)
        {
            StringBuilder buf = new StringBuilder("delete from ");

            if (schema != null && schema.Length > 0)
            {
                buf.Append("[").Append(schema).Append("].");
            }
            buf.Append("[").Append(name).Append("]");
            if (query != null)
            {
                buf.Append(" ").Append(query.GetSql(this));
            }
            buf.Append(";");
            return(buf.ToString());
        }
Exemple #4
0
        public virtual void Select(IDb db, IQuery query, IList list)
        {
            ErrorIfSPResult();
            LitQuery    sqlquery = (LitQuery)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));
        }
Exemple #5
0
 protected virtual string GetSelectSql(LitQuery query)
 {
     if (selectSQL == null)
     {
         StringBuilder buf   = new StringBuilder("select ");
         bool          comma = false;
         foreach (SqlColumn column in columns)
         {
             if (comma)
             {
                 buf.Append(",");
             }
             else
             {
                 comma = true;
             }
             buf.Append("[").Append(column.Name).Append("]");
         }
         buf.Append(" from ");
         if (schema != null && schema.Length > 0)
         {
             buf.Append("[").Append(schema).Append("].");
         }
         buf.Append("[").Append(name).Append("]");
         selectSQL = buf.ToString();
     }
     if (query != null)
     {
         StringBuilder buf = new StringBuilder(selectSQL);
         buf.Append(" ").Append(query.GetSql(this));
         buf.Append(";");
         return(buf.ToString());
     }
     else
     {
         return(string.Format("{0};", selectSQL));
     }
 }
        public LitConstraint(IQuery query)
		{
			this.query = (LitQuery) query;
		}
 public LitConstraint(IQuery query)
 {
     this.query = (LitQuery)query;
 }
 protected virtual string GetSelectSql(LitQuery query)
 {
     if (selectSQL == null)
     {
         StringBuilder buf = new StringBuilder("select ");
         bool comma = false;
         foreach (SqlColumn column in columns)
         {
             if (comma)
                 buf.Append(",");
             else
                 comma = true;
             buf.Append("[").Append(column.Name).Append("]");
         }
         buf.Append(" from ");
         if (schema != null && schema.Length > 0)
             buf.Append("[").Append(schema).Append("].");
         buf.Append("[").Append(name).Append("]");
         selectSQL = buf.ToString();
     }
     if (query != null)
     {
         StringBuilder buf = new StringBuilder(selectSQL);
         buf.Append(" ").Append(query.GetSql(this));
         buf.Append(";");
         return buf.ToString();
     }
     else
         return string.Format("{0};", selectSQL);
 }
 protected virtual string GetDeleteSql(LitQuery query)
 {
     StringBuilder buf = new StringBuilder("delete from ");
     if (schema != null && schema.Length > 0)
         buf.Append("[").Append(schema).Append("].");
     buf.Append("[").Append(name).Append("]");
     if (query != null)
         buf.Append(" ").Append(query.GetSql(this));
     buf.Append(";");
     return buf.ToString();
 }
 public virtual object Find(IDb session, object key)
 {
     ErrorIfSPResult();
     SqlColumn pk = null;
     object result = null;
     foreach (SqlColumn c in columns)
     {
         if (c.IsPK)
         {
             pk = c;
             break;
         }
     }
     if (pk != null)
     {
         LitQuery q = new LitQuery();
         q.Constrain(pk.Alias).Equal(key);
         IList list = new ArrayList(1);
         Select(session, q, list);
         if (list.Count > 0)
             result = list[0];
     }
     return result;
 }