Ejemplo n.º 1
0
 public void Write(SqlSerializationContext context)
 {
     context.Write("(");
     _Value.Write(context);
     context.Write(" IS NOT NULL");
     context.Write(")");
 }
Ejemplo n.º 2
0
 public static void AppendQuerySql([NotNull] SqlSerializationContext context, [CanBeNull] IDBPredicate cond)
 {
     context.Write(SelectSql);
     cond = cond != null ? new AndCondtion(AliveRecordsFilter, cond) : AliveRecordsFilter;
     context.Write(" WHERE ");
     cond.Write(context);
 }
Ejemplo n.º 3
0
        public static void AppendSoftDeleteSql([NotNull] SqlSerializationContext context, [NotNull] ICollection <int> objs)
        {
            if (objs == null || objs.Count == 0)
            {
                throw new ArgumentException("Collection cannot be empty", "objs");
            }
            var objIDs = SqlUtils.WrapArc(objs.ConcatComma());

            context.Write(UpdateSqlHeader + " sysState = 1 WHERE ID IN " + objIDs);
            context.Next();
            if (typeof(TDataObject).IsAssignableFrom(typeof(TblUsers)))
            {
                context.Write(DataObjectSqlSerializer <TblPermissions> .UpdateSqlHeader + "sysState = 1 WHERE " + DataObject.Schema.OwnerUserRef.PropertyName + " IN " + objIDs);
                context.Next();
            }
            else if (typeof(TDataObject).IsAssignableFrom(typeof(TblGroups)))
            {
                context.Write(DataObjectSqlSerializer <TblPermissions> .UpdateSqlHeader + "sysState = 1 WHERE " + DataObject.Schema.OwnerGroupRef.PropertyName + " IN " + objIDs);
                context.Next();
            }
            foreach (var i in objs)
            {
                LookupHelper.AppendMMUnlinkAllSqlSafe <TDataObject>(context, i);
                context.Next();
            }
        }
Ejemplo n.º 4
0
 public void Write(SqlSerializationContext context)
 {
     Arg.Write(context);
     context.Write(" ");
     context.Write(KindToString(Kind));
     context.Write(" (");
     SubSelect.Write(context);
     context.Write(")");
 }
Ejemplo n.º 5
0
 public static void AppendUpdateSql([NotNull] SqlSerializationContext context, [NotNull] TDataObject instance)
 {
     context.Write(UpdateSqlHeader +
                   (from ci in DataObjectInfo <TDataObject> .Columns
                    where ci.Name != "ID"
                    select SqlUtils.WrapDbId(ci.Name) + "=" + context.AddParameter(ci.Storage.GetValue(instance))
                   ).ConcatComma()
                   + " WHERE ID=" + instance.ID);
 }
Ejemplo n.º 6
0
 public static void AppendSelectRangeSql([NotNull] SqlSerializationContext context, int from, int to, IDBPredicate st)
 {
     context.Write(__SelectRangeSqlTemplate_1, context.AddParameter(from), context.AddParameter(to));
     if (st != null)
     {
         st.Write(context);
     }
     context.Write(Environment.NewLine);
     context.Write(__SelectRangeSqlTemplate_2);
 }
Ejemplo n.º 7
0
 public void Write(SqlSerializationContext context)
 {
     context.Write("(");
     _Operand.Write(context);
     context.Write(" BETWEEN ");
     _LowBound.Write(context);
     context.Write(" AND ");
     _HiBound.Write(context);
     context.Write(")");
 }
Ejemplo n.º 8
0
        public static void RegisterMMLookup(ManyToManyRelationshipAttribute mmr, Type relType)
        {
            CheckMMSupport(mmr.First);
            CheckMMSupport(mmr.Second);

            string firstKey  = null,
                   secondKey = null;

            foreach (var p in relType.GetProperties())
            {
                AssociationAttribute aa;
                if (p.TryGetAtr(out aa))
                {
                    if (p.PropertyType == mmr.First && p.PropertyType == mmr.Second)
                    {
                        if (firstKey == null)
                        {
                            firstKey = aa.ThisKey;
                        }
                        else if (secondKey == null)
                        {
                            secondKey = aa.ThisKey;
                        }
                        else
                        {
                            throw new InvalidOperationException();
                        }
                    }
                    else if (p.PropertyType == mmr.First)
                    {
                        if (firstKey != null)
                        {
                            throw new InvalidOperationException();
                        }
                        firstKey = aa.ThisKey;
                    }
                    else if (p.PropertyType == mmr.Second)
                    {
                        if (secondKey != null)
                        {
                            throw new InvalidOperationException();
                        }
                        secondKey = aa.ThisKey;
                    }
                }
            }
            if (firstKey.IsNull() || secondKey.IsNull())
            {
                throw new DMError(Translations.LookupHelper_RegisterMMLookup_Invalid_many_to_many_relationship_definition_for__0___1_, mmr.First.Name, mmr.Second.Name);
            }
            string tableName = SqlSerializationContext.ExtractTableName(relType.GetAtr <TableAttribute>().Name);

            Put(__MMInfos, mmr.First, mmr.Second, new ManyToManyLookupInfo(firstKey, tableName, secondKey, relType));
            Put(__MMInfos, mmr.Second, mmr.First, new ManyToManyLookupInfo(secondKey, tableName, firstKey, relType));
        }
Ejemplo n.º 9
0
 public void Write(SqlSerializationContext context)
 {
     context.Write("SELECT ");
     context.Write(FieldNames.Select(f => SqlUtils.WrapDbId(f)).ConcatComma());
     context.Write(" FROM ");
     context.Write(SqlUtils.WrapDbId(DataObjectInfo <TDataObject> .TableName));
     if (Condition != null)
     {
         context.Write(" WHERE ");
         Condition.Write(context);
     }
 }
Ejemplo n.º 10
0
 public static void AppendInsertSql([NotNull] SqlSerializationContext context, [NotNull] TDataObject obj)
 {
     context.Write(InsertSqlHeader);
     context.Write(
         SqlUtils.WrapArc(
             (from ci in DataObjectInfo <TDataObject> .Columns
              where ci.Name != "ID"
              select context.AddParameter(ci.Storage.GetValue(obj))
             ).ConcatComma()
             )
         );
     context.Next();
     context.Write("select SCOPE_IDENTITY()");
 }
Ejemplo n.º 11
0
        public void Write(SqlSerializationContext context)
        {
            context.Write("(");
            A.Write(context);
            string opSym;

            switch (Kind)
            {
            case COMPARE_KIND.EQUAL:
                opSym = " = ";
                break;

            case COMPARE_KIND.IN:
                opSym = " IN ";
                break;

            case COMPARE_KIND.LESS:
                opSym = " < ";
                break;

            case COMPARE_KIND.MORE:
                opSym = " > ";
                break;

            case COMPARE_KIND.NOT_EQUAL:
                opSym = " <> ";
                break;

            case COMPARE_KIND.NOT_LESS:
                opSym = " >= ";
                break;

            case COMPARE_KIND.NOT_MORE:
                opSym = " <= ";
                break;

            case COMPARE_KIND.LIKE:
                opSym = " LIKE ";
                break;

            default:
                throw new InvalidOperationException();
            }

            context.Write(opSym);
            B.Write(context);
            context.Write(")");
        }
Ejemplo n.º 12
0
        public static void AppendMMLookupSql([NotNull] SqlSerializationContext context, IIntKeyedDataObject firstPart, Type otherType)
        {
            var r = Get(__MMInfos, firstPart.GetType(), otherType);

            if (r.IsEmpty)
            {
                throw new DMError("Couldnt fond many-to-many relation between {1} and {1}", firstPart.GetType().Name, otherType.Name);
            }
            if (firstPart.ID <= 0)
            {
                throw new DMError("{0} has invalid ID = {1}", firstPart.GetType(), firstPart.ID);
            }

            context.Write("SELECT [{0}] FROM [{1}] WHERE ([{2}] = {3}) and sysState = 0",
                          r.IDColumnName, r.TableName, r.RefColumnName, context.AddParameter(firstPart.ID));
        }
Ejemplo n.º 13
0
        public static void AppendMMLookupSql([NotNull] SqlSerializationContext context, IIntKeyedDataObject firstPart, Type otherType)
        {
            var r = Get(__MMInfos, firstPart.GetType(), otherType);

            if (r.IsEmpty)
            {
                throw new DMError(Translations.LookupHelper_AppendMMLookupSql_Couldnt_fond_many_to_many_relation_between__1__and__1_, firstPart.GetType().Name, otherType.Name);
            }
            if (firstPart.ID <= 0)
            {
                throw new DMError(Translations.LookupHelper_AppendLookupSql_, firstPart.GetType(), firstPart.ID);
            }

            context.Write("SELECT [{0}] FROM [{1}] WHERE ([{2}] = {3}) and sysState = 0",
                          r.IDColumnName, r.TableName, r.RefColumnName, context.AddParameter(firstPart.ID));
        }
Ejemplo n.º 14
0
        static DataObjectInfo()
        {
            // Precalculation dataobject information
            Type type = typeof(TDataObject);
            var  ta   = type.GetAtr <TableAttribute>();

            TableName = SqlSerializationContext.ExtractTableName(ta.Name);

            Columns = new List <ColumnInfo>(
                from p in type.GetProperties()
                where p.HasAtr <ColumnAttribute>()
                select new ColumnInfo(type, p));
            ColumnNames = Columns.Select(c => SqlUtils.WrapDbId(c.Name)).ConcatComma();
            SelectSql   = "SELECT " + ColumnNames + " FROM " + SqlUtils.WrapDbId(TableName);
            IsSecured   = typeof(ISecuredDataObject).IsAssignableFrom(typeof(TDataObject));
        }
Ejemplo n.º 15
0
 public static void AppendSoftDeleteSql([NotNull] SqlSerializationContext context, int id)
 {
     context.Write(UpdateSqlHeader);
     context.Write(" sysState = 1 WHERE ID = ");
     context.Write(id.ToString());
     context.Next();
     if (typeof(TDataObject).IsAssignableFrom(typeof(TblUsers)))
     {
         context.Write(DataObjectSqlSerializer <TblPermissions> .UpdateSqlHeader + "sysState = 1 WHERE " + DataObject.Schema.OwnerUserRef.PropertyName + " = " + id);
         context.Next();
     }
     else if (typeof(TDataObject).IsAssignableFrom(typeof(TblGroups)))
     {
         context.Write(DataObjectSqlSerializer <TblPermissions> .UpdateSqlHeader + "sysState = 1 WHERE " + DataObject.Schema.OwnerGroupRef.PropertyName + " = " + id);
         context.Next();
     }
     LookupHelper.AppendMMUnlinkAllSqlSafe <TDataObject>(context, id);
 }
Ejemplo n.º 16
0
        public static void AppendMMUnlinkAllSqlSafe <TDataObject>([NotNull] SqlSerializationContext context, int id)
            where TDataObject : IIntKeyedDataObject
        {
            if (id <= 0)
            {
                throw new DMError("Invalid ID: " + id);
            }

            Dictionary <Type, ManyToManyLookupInfo> lookups;

            if (__MMInfos.TryGetValue(typeof(TDataObject), out lookups))
            {
                foreach (var vs in lookups.Values)
                {
                    context.Write("UPDATE [{0}] SET sysState = 1 WHERE {1} = {2}", vs.TableName, vs.RefColumnName, id);
                    context.Next();
                }
            }
        }
Ejemplo n.º 17
0
        public void Write(SqlSerializationContext context)
        {
            bool notFirst = false;

            context.Write("(");
            foreach (var p in _Param.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public))
            {
                if (notFirst)
                {
                    context.Write(" AND ");
                }
                else
                {
                    notFirst = true;
                }
                context.Write("([{0}] = {1})", p.Name, context.AddParameter(p.GetValue(_Param, null)));
            }
            context.Write(")");
        }
Ejemplo n.º 18
0
        public void Write(SqlSerializationContext context)
        {
            context.Write("(");
            bool notFirst = false;

            foreach (var cond in _Conds)
            {
                if (notFirst)
                {
                    WriteOperator(context);
                }
                else
                {
                    notFirst = true;
                }
                cond.Write(context);
            }
            context.Write(")");
        }
Ejemplo n.º 19
0
        public static void AppendMMLinkSql([NotNull] SqlSerializationContext context, IIntKeyedDataObject o1, IIntKeyedDataObject o2)
        {
            if (o1.ID <= 0)
            {
                throw new DMError("{0} has invalid ID = {1}", o1.GetType(), o1.ID);
            }
            if (o2.ID <= 0)
            {
                throw new DMError("{0} has invalid ID = {1}", o2.GetType(), o2.ID);
            }

            var r = Get(__MMInfos, o1.GetType(), o2.GetType());

            if (r.IsEmpty)
            {
                throw new DMError("Couldnt fond many-to-many relation between {1} and {1}", o1.GetType().Name, o2.GetType().Name);
            }

            context.Write("INSERT INTO [{0}] ([{1}], [{2}]) VALUES ({3}, {4})",
                          r.TableName, r.RefColumnName, r.IDColumnName, context.AddParameter(o1.ID), context.AddParameter(o2.ID));
        }
Ejemplo n.º 20
0
        public static void AppendMMUnLinkSql([NotNull] SqlSerializationContext context, IIntKeyedDataObject o1, IIntKeyedDataObject o2)
        {
            var r = Get(__MMInfos, o1.GetType(), o2.GetType());

            if (r.IsEmpty)
            {
                throw new DMError(Translations.LookupHelper_AppendMMLookupSql_Couldnt_fond_many_to_many_relation_between__1__and__1_, o1.GetType().Name, o2.GetType().Name);
            }

            if (o1.ID <= 0)
            {
                throw new DMError(Translations.LookupHelper_AppendLookupSql_, o1.GetType(), o1.ID);
            }
            if (o2.ID <= 0)
            {
                throw new DMError(Translations.LookupHelper_AppendLookupSql_, o2.GetType(), o2.ID);
            }

            context.Write("DELETE [{0}] WHERE [{1}] = {3} AND [{2}] = {4}",
                          r.TableName, r.RefColumnName, r.IDColumnName, context.AddParameter(o1.ID), context.AddParameter(o2.ID));
        }
Ejemplo n.º 21
0
        public static void AppendLookupSql([NotNull] SqlSerializationContext context, [NotNull] IIntKeyedDataObject owner, [NotNull] Type detailType, [CanBeNull] IDBPredicate condition)
        {
            var r = Get(__Infos, owner.GetType(), detailType);

            if (r.IsEmpty)
            {
                throw new DMError("Couldnt found relation between {0} and {1}", owner.GetType(), detailType);
            }
            if (owner.ID <= 0)
            {
                throw new DMError("{0} has invalid ID = {1}", owner.GetType().Name, owner.ID);
            }

            context.Write("SELECT ID FROM [{0}] where ([{1}] = {2}) and sysState = 0", r.TableName, r.RefColumnName, context.AddParameter(owner.ID));
            if (condition != null)
            {
                context.Write(" AND (");
                condition.Write(context);
                context.Write(")");
            }
        }
Ejemplo n.º 22
0
        public void Write(SqlSerializationContext context)
        {
            context.Write("UPDATE " + DataObjectInfo <TDataObject> .TableName + " SET ");
            bool notFirst = false;

            foreach (var a in _Assignements)
            {
                if (notFirst)
                {
                    context.Write(",");
                }
                else
                {
                    notFirst = true;
                }
                a.Write(context);
            }
            if (_Condition != null)
            {
                context.Write(" WHERE ");
                _Condition.Write(context);
            }
        }
Ejemplo n.º 23
0
 protected override void WriteOperator(SqlSerializationContext context)
 {
     context.Write(" AND ");
 }
Ejemplo n.º 24
0
 public void Write(SqlSerializationContext context)
 {
     _Property.Write(context);
     context.Write("=");
     _Value.Write(context);
 }
Ejemplo n.º 25
0
 public static void RegisterLookup(Type ownerType, Type detailType, AssociationAttribute aa)
 {
     Put(__Infos, ownerType, detailType,
         new LookupInfo(aa.OtherKey, SqlSerializationContext.ExtractTableName(detailType.GetAtr <TableAttribute>().Name)));
 }
Ejemplo n.º 26
0
 public void Write(SqlSerializationContext context)
 {
     context.Write(context.AddParameter(Value));
 }
Ejemplo n.º 27
0
 protected abstract void WriteOperator(SqlSerializationContext context);
Ejemplo n.º 28
0
 public void Write(SqlSerializationContext context)
 {
     context.Write("[");
     context.Write(PropertyName);
     context.Write("]");
 }