public void Write(SqlSerializationContext context) { context.Write("("); _Value.Write(context); context.Write(" IS NOT NULL"); context.Write(")"); }
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); }
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(); } }
public void Write(SqlSerializationContext context) { Arg.Write(context); context.Write(" "); context.Write(KindToString(Kind)); context.Write(" ("); SubSelect.Write(context); context.Write(")"); }
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); }
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); }
public void Write(SqlSerializationContext context) { context.Write("("); _Operand.Write(context); context.Write(" BETWEEN "); _LowBound.Write(context); context.Write(" AND "); _HiBound.Write(context); context.Write(")"); }
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)); }
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); } }
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()"); }
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(")"); }
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)); }
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)); }
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)); }
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); }
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(); } } }
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(")"); }
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(")"); }
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)); }
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)); }
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(")"); } }
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); } }
protected override void WriteOperator(SqlSerializationContext context) { context.Write(" AND "); }
public void Write(SqlSerializationContext context) { _Property.Write(context); context.Write("="); _Value.Write(context); }
public static void RegisterLookup(Type ownerType, Type detailType, AssociationAttribute aa) { Put(__Infos, ownerType, detailType, new LookupInfo(aa.OtherKey, SqlSerializationContext.ExtractTableName(detailType.GetAtr <TableAttribute>().Name))); }
public void Write(SqlSerializationContext context) { context.Write(context.AddParameter(Value)); }
protected abstract void WriteOperator(SqlSerializationContext context);
public void Write(SqlSerializationContext context) { context.Write("["); context.Write(PropertyName); context.Write("]"); }