private void FindInherited(Type type, LitTable table)
 {
     if (type.IsDefined(typeof(MapAttribute), false))
     {
         object[] attrs = type.GetCustomAttributes(typeof(MapAttribute), false);
         foreach (MapAttribute attr in attrs)
         {
             IDataBridge data = null;
             BindingFlags flags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
             MemberInfo member = type.GetProperty(attr.Field, flags);
             if (member != null)
             {
                 data = new PropertyBridge((PropertyInfo)member);
             }
             else
             {
                 member = type.GetField(attr.Field, flags);
                 if (member != null)
                     data = new FieldBridge((FieldInfo)member);
                 else
                     throw new LightException("member " + attr.Field + " not found in class " + type.Name);
             }
             if (attr.Name == null || attr.Name.Length == 0)
                 attr.Name = member.Name;
             SqlColumn column = new SqlColumn(table, attr.Name, data);
             if (attr.Alias == null || attr.Alias.Length == 0)
                 column.Alias = attr.Field;
             else
                 column.Alias = attr.Alias;
             column.IsID = attr.ID;
             column.IsPK = attr.PK;
             table.Add(column);
         }
     }
 }
 public override string GetSql(LitTable table, ref int offset)
 {
     string name = table.Translate(Column);
     if (name == null || name.Length == 0)
         throw new LightException(string.Format("column {0} not found in table {1}",
                                                Column, table.Name));
     index = offset;
     IList values = (IList)Value;
     StringBuilder buf = new StringBuilder();
     buf.Append("[").Append(name).Append("] ").Append(Operator).Append(" (");
     if (values.Count > 0)
     {
         offset = offset + values.Count;
         for (int i = index; i < offset; i++)
         {
             if (i > index)
                 buf.Append(",");
             string pname = string.Format("@{0}", i);
             buf.Append(pname);
         }
     }
     else
     {
         buf.Append("null");
     }
     buf.Append(")");
     return buf.ToString();
 }
 private LitTable BuildTable(Type type)
 {
     LitTable table = null;
     if (!type.IsDefined(typeof(TableAttribute), false))
     {
         if (!type.IsDefined(typeof(SPResultAttribute), false))
             throw new LightException("no TableAttribute or SPResultAttribute found on " + type.FullName);
         else
             table = new LitTable(type, null, null);
     }
     else
     {
         TableAttribute tableAttr = (TableAttribute)type.GetCustomAttributes(typeof(TableAttribute), false)[0];
         string name = tableAttr.Name;
         string schema = tableAttr.Schema;
         if (name == null || name.Length == 0)
             name = type.Name;
         table = new LitTable(type, name, schema);
     }
     FindInherited(type, table);
     ProcessFields(type, table);
     ProcessProperties(type, table);
     ProcessMethods(type, table);
     return table;
 }
        public override string GetSql(LitTable table, ref int offset)
        {
            string name = table.Translate(this.Column);
            if (name == null || name.Length == 0)
                throw new LightException(string.Format("column {0} not found in table {1}",
                                                       this.Column, table.Name));

            return string.Format("[{0}] {1} null", name, this.Operator);
        }
예제 #5
0
        public override string GetSql(LitTable table, ref int offset)
        {
            string name = table.Translate(this.Column);

            if (name == null || name.Length == 0)
            {
                throw new LightException(string.Format("column {0} not found in table {1}",
                                                       this.Column, table.Name));
            }

            return(string.Format("[{0}] {1} null", name, this.Operator));
        }
예제 #6
0
 protected virtual void DoSelect(Type type, IQuery query, IList list)
 {
     ErrorIfClosed();
     try
     {
         InternalOpen();
         LitTable table = TableFor(type);
         table.Select(this, query, list);
     }
     finally
     {
         InternalClose();
     }
 }
예제 #7
0
 protected virtual void DoSelect(Type type, string sql, string[] parameterName, Object[] parameters, IDbTransaction transaction, CommandType commType, IList list)
 {
     ErrorIfClosed();
     try
     {
         InternalOpen();
         LitTable table = TableFor(type);
         table.Select(this, sql, parameterName, parameters, transaction, commType, list);
     }
     finally
     {
         InternalClose();
     }
 }
예제 #8
0
 private void ProcessMethods(Type type, LitTable table)
 {
     MethodInfo[] methods = type.GetMethods(
         BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
     foreach (MethodInfo method in methods)
     {
         if (method.IsDefined(typeof(TriggerAttribute), false))
         {
             TriggerAttribute attr = (TriggerAttribute)
                                     method.GetCustomAttributes(typeof(TriggerAttribute), false)[0];
             SqlTrigger trigger = new SqlTrigger(method, attr.Timing);
             table.AddTrigger(trigger);
         }
     }
 }
예제 #9
0
 protected virtual void DoSelect(Type type, string procName, string[] parameterName, object[] parameters, string[] outputParameterName, int?[] outputParameterSize, DbType[] outputParameterType,
                                 ParameterDirection[] outputParameterDirection, out object[] outParameterResult, IList list)
 {
     ErrorIfClosed();
     try
     {
         InternalOpen();
         LitTable table = TableFor(type);
         table.Select(this, procName, parameterName, parameters, outputParameterName, outputParameterSize, outputParameterType, outputParameterDirection, out outParameterResult, list);
     }
     finally
     {
         InternalClose();
     }
 }
예제 #10
0
        public virtual IList Exec(Type type, string procName, string[] parameterName, object[] parameters)
        {
            ErrorIfClosed();
            IList list = new ArrayList();

            try
            {
                InternalOpen();
                LitTable table = TableFor(type);
                table.Exec(this, procName, parameterName, parameters, list);
            }
            finally
            {
                InternalClose();
            }
            return(list);
        }
예제 #11
0
        public virtual object Find(Type type, object key)
        {
            ErrorIfClosed();
            object objFind = null;

            try
            {
                InternalOpen();
                LitTable table = TableFor(type);
                objFind = table.Find(this, key);
            }
            finally
            {
                InternalClose();
            }
            return(objFind);
        }
예제 #12
0
 private void FindInherited(Type type, LitTable table)
 {
     if (type.IsDefined(typeof(MapAttribute), false))
     {
         object[] attrs = type.GetCustomAttributes(typeof(MapAttribute), false);
         foreach (MapAttribute attr in attrs)
         {
             IDataBridge  data   = null;
             BindingFlags flags  = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
             MemberInfo   member = type.GetProperty(attr.Field, flags);
             if (member != null)
             {
                 data = new PropertyBridge((PropertyInfo)member);
             }
             else
             {
                 member = type.GetField(attr.Field, flags);
                 if (member != null)
                 {
                     data = new FieldBridge((FieldInfo)member);
                 }
                 else
                 {
                     throw new LightException("member " + attr.Field + " not found in class " + type.Name);
                 }
             }
             if (attr.Name == null || attr.Name.Length == 0)
             {
                 attr.Name = member.Name;
             }
             SqlColumn column = new SqlColumn(table, attr.Name, data);
             if (attr.Alias == null || attr.Alias.Length == 0)
             {
                 column.Alias = attr.Field;
             }
             else
             {
                 column.Alias = attr.Alias;
             }
             column.IsID = attr.ID;
             column.IsPK = attr.PK;
             table.Add(column);
         }
     }
 }
예제 #13
0
		public virtual string GetSql(LitTable table, ref int offset)
		{
            if (HasQuery)
            {
                string sql = query.GetSql(table, ref offset);
                return string.Format("({0})", sql);
            }
            else
            {
                index = offset;
                offset = offset + 1;
                string name = table.Translate(column);
                if (name == null || name.Length == 0)
                    //name = column;
                    throw new LightException(string.Format("column {0} not found in table {1}", column, table.Name));
                return string.Format("[{0}]{1}@{2}", name, oper, index);
            }
		}
예제 #14
0
        public virtual string GetSql(LitTable table, ref int offset)
        {
            if (!IsComplete)
            {
                throw new InvalidOperationException("invalid query");
            }

            StringBuilder buf = new StringBuilder();
            int           sz  = constraints.Count;

            if (sz > 0)
            {
                buf.Append("where");
            }
            for (int i = 0; i < sz; i++)
            {
                if (i > 0)
                {
                    string op = operators[i - 1];
                    buf.Append(" ").Append(op);
                }
                LitConstraint constraint = constraints[i];
                string        sql        = constraint.GetSql(table, ref offset);
                buf.Append(" ").Append(sql);
            }
            sz = orders.Count;
            if (sz > 0)
            {
                buf.Append(" order by ");
                for (int i = 0; i < sz; i++)
                {
                    if (i > 0)
                    {
                        buf.Append(",");
                    }
                    LitOrder order = orders[i];
                    string   sql   = order.GetSql(table);
                    buf.Append(sql);
                }
            }
            return(buf.ToString());
        }
예제 #15
0
 public virtual string GetSql(LitTable table, ref int offset)
 {
     if (HasQuery)
     {
         string sql = query.GetSql(table, ref offset);
         return(string.Format("({0})", sql));
     }
     else
     {
         index  = offset;
         offset = offset + 1;
         string name = table.Translate(column);
         if (name == null || name.Length == 0)
         {
             //name = column;
             throw new LightException(string.Format("column {0} not found in table {1}", column, table.Name));
         }
         return(string.Format("[{0}]{1}@{2}", name, oper, index));
     }
 }
예제 #16
0
 private void ProcessFields(Type type, LitTable table)
 {
     FieldInfo[] fields = type.GetFields(
         BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
     foreach (FieldInfo field in fields)
     {
         if (!field.IsDefined(typeof(ColumnAttribute), false))
         {
             continue;
         }
         ColumnAttribute colAttr = (ColumnAttribute)
                                   field.GetCustomAttributes(typeof(ColumnAttribute), false)[0];
         FieldBridge data = new FieldBridge(field);
         if (colAttr.Name == null || colAttr.Name.Length == 0)
         {
             colAttr.Name = field.Name;
         }
         SqlColumn column = new SqlColumn(table, colAttr.Name, data);
         if (colAttr.Alias == null || colAttr.Alias.Length == 0)
         {
             column.Alias = field.Name;
         }
         else
         {
             column.Alias = colAttr.Alias;
         }
         if (field.IsDefined(typeof(IDAttribute), false))
         {
             column.IsID = true;
         }
         if (field.IsDefined(typeof(PKAttribute), false))
         {
             column.IsPK = true;
         }
         table.Add(column);
     }
 }
예제 #17
0
        public virtual int Delete(Type type, ICollection items)
        {
            ErrorIfClosed();
            if (items.Count == 0)
            {
                return(0);
            }
            int result = 0;

            try
            {
                InternalOpen();
                LitTable table = TableFor(type);
                if (autocommit)
                {
                    BeginInternal();
                }
                result = table.Delete(this, items);
                if (autocommit)
                {
                    CommitInternal();
                }
            }
            catch (Exception)
            {
                if (autocommit)
                {
                    RollbackInternal();
                }
                throw;
            }
            finally
            {
                InternalClose();
            }
            return(result);
        }
예제 #18
0
 private void ProcessProperties(Type type, LitTable table)
 {
     PropertyInfo[] fields = type.GetProperties(
         BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
     foreach (PropertyInfo field in fields)
     {
         if (!field.IsDefined(typeof(ColumnAttribute), false))
             continue;
         ColumnAttribute colAttr = (ColumnAttribute)
             field.GetCustomAttributes(typeof(ColumnAttribute), false)[0];
         PropertyBridge data = new PropertyBridge(field);
         if (colAttr.Name == null || colAttr.Name.Length == 0)
             colAttr.Name = field.Name;
         SqlColumn column = new SqlColumn(table, colAttr.Name, data);
         if (colAttr.Alias == null || colAttr.Alias.Length == 0)
             column.Alias = field.Name;
         else
             column.Alias = colAttr.Alias;
         if (field.IsDefined(typeof(IDAttribute), false))
             column.IsID = true;
         if (field.IsDefined(typeof(PKAttribute), false))
             column.IsPK = true;
         table.Add(column);
     }
 }
예제 #19
0
        public virtual string GetSql(LitTable table, ref int offset)
        {
            if (!IsComplete)
                throw new InvalidOperationException("invalid query");

            StringBuilder buf = new StringBuilder();
            int sz = constraints.Count;
            if (sz > 0)
                buf.Append("where");
            for (int i = 0; i < sz; i++)
            {
                if (i > 0)
                {
                    string op = operators[i - 1];
                    buf.Append(" ").Append(op);
                }
                LitConstraint constraint = constraints[i];
                string sql = constraint.GetSql(table, ref offset);
                buf.Append(" ").Append(sql);
            }
            sz = orders.Count;
            if (sz > 0)
            {
                buf.Append(" order by ");
                for (int i = 0; i < sz; i++)
                {
                    if (i > 0)
                        buf.Append(",");
                    LitOrder order = orders[i];
                    string sql = order.GetSql(table);
                    buf.Append(sql);
                }
            }
            return buf.ToString();
        }
예제 #20
0
 private void ProcessMethods(Type type, LitTable table)
 {
     MethodInfo[] methods = type.GetMethods(
         BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
     foreach (MethodInfo method in methods)
     {
         if (method.IsDefined(typeof(TriggerAttribute), false))
         {
             TriggerAttribute attr = (TriggerAttribute)
                 method.GetCustomAttributes(typeof(TriggerAttribute), false)[0];
             SqlTrigger trigger = new SqlTrigger(method, attr.Timing);
             table.AddTrigger(trigger);
         }
     }
 }
예제 #21
0
 public virtual string GetSql(LitTable table)
 {
     int offset = 1;
     return GetSql(table, ref offset);
 }
예제 #22
0
        public virtual string GetSql(LitTable table)
        {
            int offset = 1;

            return(GetSql(table, ref offset));
        }