예제 #1
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();
            }
        }
예제 #2
0
파일: DBOps.cs 프로젝트: nbl852003/iudico
 public void Write(SqlSerializationContext context)
 {
     context.Write("(");
     _Value.Write(context);
     context.Write(" IS NOT NULL");
     context.Write(")");
 }
예제 #3
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);
 }
예제 #4
0
파일: DBOps.cs 프로젝트: nbl852003/iudico
 public void Write(SqlSerializationContext context)
 {
     Arg.Write(context);
     context.Write(" ");
     context.Write(KindToString(Kind));
     context.Write(" (");
     SubSelect.Write(context);
     context.Write(")");
 }
예제 #5
0
파일: DBOps.cs 프로젝트: nbl852003/iudico
 public void Write(SqlSerializationContext context)
 {
     context.Write("(");
     _Operand.Write(context);
     context.Write(" BETWEEN ");
     _LowBound.Write(context);
     context.Write(" AND ");
     _HiBound.Write(context);
     context.Write(")");
 }
예제 #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);
 }
예제 #7
0
파일: DBOps.cs 프로젝트: nbl852003/iudico
 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);
     }
 }
예제 #8
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()");
 }
예제 #9
0
파일: DBOps.cs 프로젝트: nbl852003/iudico
        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(")");
        }
예제 #10
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);
 }
예제 #11
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);
 }
예제 #12
0
파일: DBOps.cs 프로젝트: nbl852003/iudico
        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(")");
        }
예제 #13
0
파일: DBOps.cs 프로젝트: nbl852003/iudico
        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(")");
        }
예제 #14
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(")");
            }
        }
예제 #15
0
파일: DBOps.cs 프로젝트: nbl852003/iudico
        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);
            }
        }
예제 #16
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));
        }
예제 #17
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));
        }
예제 #18
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();
                }
            }
        }
예제 #19
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));
        }
예제 #20
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));
        }
예제 #21
0
파일: DBOps.cs 프로젝트: nbl852003/iudico
 protected override void WriteOperator(SqlSerializationContext context)
 {
     context.Write(" AND ");
 }
예제 #22
0
파일: DBOps.cs 프로젝트: nbl852003/iudico
 public void Write(SqlSerializationContext context)
 {
     _Property.Write(context);
     context.Write("=");
     _Value.Write(context);
 }
예제 #23
0
파일: DBOps.cs 프로젝트: nbl852003/iudico
 public void Write(SqlSerializationContext context)
 {
     context.Write(context.AddParameter(Value));
 }
예제 #24
0
파일: DBOps.cs 프로젝트: nbl852003/iudico
 public void Write(SqlSerializationContext context)
 {
     context.Write("[");
     context.Write(PropertyName);
     context.Write("]");
 }