Exemplo n.º 1
0
 public List <T> Select <T>(IDBExecutor exec) where T : new()
 {
     return(Select <T>(new ORMSelect(Adp)
     {
         FocalType = typeof(T)
     }, exec));
 }
Exemplo n.º 2
0
        /// <summary>
        /// Execute the insert and return the inserted identity value
        /// </summary>
        /// <param name="adp"></param>
        /// <returns></returns>
        public object ExecuteReturnID(IDBExecutor adp)
        {
            bool prevValue = ReturnID;

            ReturnID = true;

            SQSelectResult res = null;

            try
            {
                res = adp.Insert(this);

                if (res.Reader.Read())
                {
                    return(res.Reader.GetValue(0));
                }
            }
            finally
            {
                ReturnID = prevValue;
                if (res != null)
                {
                    res.Close();
                }
            }

            return(null);
        }
Exemplo n.º 3
0
        public List <T> Select <T>(ORMCondBase condition, IDBExecutor exec) where T : new()
        {
            ORMSelect s = new ORMSelect(Adp);

            s.FocalType = typeof(T);
            s.Condition = condition;
            return(Select <T>(s, exec));
        }
Exemplo n.º 4
0
        public void Delete(IDGBase vl, IDBExecutor exec)
        {
            SchemaTable t = Schema.EnsureSchema(vl.GetType());

            if (t != null)
            {
                SQDeleteQuery dlt = new SQDeleteQuery()
                {
                    DeleteTable = new SQAliasableObject(t.Table.Name),
                    Condition   = new SQCondition(t.Table.GetPrimaryKey().Name, SQRelationOperators.Equal, vl.ID.ToString())
                };
                dlt.Execute(exec);
            }
        }
Exemplo n.º 5
0
        public void Update(IDGBase vl, IDBExecutor exec)
        {
            SchemaTable t = Schema.EnsureSchema(vl.GetType());

            if (t != null)
            {
                SQUpdateQuery upd = new SQUpdateQuery()
                {
                    UpdateTable = new SQAliasableObject(t.Table.Name),
                    Condition   = new SQCondition(t.Table.GetPrimaryKey().Name, SQRelationOperators.Equal, vl.ID.ToString())
                };
                PopulateSetQuery(upd, vl, t);
                upd.Execute(exec);
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Execute the insert and return the inserted identity value
        /// </summary>
        /// <typeparam name="T">Type of identity column</typeparam>
        /// <param name="adp"></param>
        /// <returns></returns>
        public T ExecuteReturnID <T>(IDBExecutor adp)
        {
            object value = ExecuteReturnID(adp);

            if (value != null)
            {
                if (value is T)
                {
                    return((T)value);
                }

                return((T)Convert.ChangeType(value, typeof(T)));
            }

            return(default(T));
        }
Exemplo n.º 7
0
        public Int64 Insert(IDGBase vl, IDBExecutor exec)
        {
            SchemaTable t = Schema.EnsureSchema(vl.GetType());

            if (t != null)
            {
                SQInsertQuery ins = new SQInsertQuery()
                {
                    Table    = new SQAliasableObject(t.Table.Name),
                    ReturnID = true
                };
                PopulateSetQuery(ins, vl, t);
                return(ins.ExecuteReturnID <Int64>(exec));
            }

            return(-1);
        }
Exemplo n.º 8
0
        public virtual List <T> Select <T>(ORMSelect select, IDBExecutor exec) where T : new()
        {
            List <T> res = new List <T>();

            SchemaTable t = Schema.EnsureSchema(typeof(T));

            if (t != null)
            {
                SQSelectResult sr = exec.Select(select.GetQuery().Query);
                try
                {
                    while (sr.Reader.Read())
                    {
                        T item = new T();
                        BeforePopulateFromDB(item);
                        for (int i = 0; i < t.Columns.Count; i++)
                        {
                            if (!sr.Reader.IsDBNull(i))
                            {
                                if (item is IPopulateProperties)
                                {
                                    ((IPopulateProperties)item).PopulateProperty(t.Columns[i].Property.Name, GetFieldValue(sr.Reader, i, t.Columns[i]));
                                }
                                else
                                {
                                    t.Columns[i].Property.SetValue(item, GetFieldValue(sr.Reader, i, t.Columns[i]), null);
                                }
                            }
                        }
                        res.Add(item);
                    }
                }
                finally
                {
                    sr.Connection.Close();
                }
            }
            else
            {
                throw new InvalidTypeException(typeof(T));
            }

            return(res);
        }
Exemplo n.º 9
0
 public void Execute(IDBExecutor adp)
 {
     adp.Delete(this);
 }
Exemplo n.º 10
0
 public void Execute(IDBExecutor dbe)
 {
     dbe.Insert(this);
 }
Exemplo n.º 11
0
 public void Execute(IDBExecutor adp)
 {
     adp.Update(this);
 }
Exemplo n.º 12
0
 public SQSelectResult Execute(IDBExecutor adp)
 {
     return(adp.Select(this));
 }
Exemplo n.º 13
0
 /// <summary>
 /// Execute the insert
 /// </summary>
 /// <param name="adp"></param>
 public void Execute(IDBExecutor adp)
 {
     adp.Insert(this).Close();
 }