コード例 #1
0
ファイル: DefaultConstraint.cs プロジェクト: npenin/uss
		public DefaultConstraint(Constant default_value, bool isNull) : base ( isNull )
		{
			_DefaultValue = default_value;
		}
コード例 #2
0
ファイル: MsSqlDialect.cs プロジェクト: npenin/uss
        public override void Visit(Constant constant)
        {
            switch (constant.DbType)
            {
                case DbType.Binary:
                    // Format string for binary content in queries (e.g., 0xC9CBBBCCCEB9C8CABCCCCEB9C9CBBB )
                    _Query.Append("0x");
                    foreach (byte b in (byte[])constant.Value)
                    {
                        _Query.Append(Convert.ToString(b, 16));
                    }
                    break;
                default:
                    base.Visit(constant);
                    break;
            }

        }
コード例 #3
0
ファイル: MySqlDialect.cs プロジェクト: npenin/uss
		private void PrintConstant (Constant constant)
		{
			if (constant.Value == null) {
				_Query.Append ("null");
				return;
			}

			_Query.Append ("'");
			switch (constant.DbType) {
				case DbType.Date :
				case DbType.DateTime :
					_Query.Append (DateTime.Parse(((string) constant.Value), CultureInfo.CurrentCulture).ToString (
						"yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture));
					break;
				case DbType.Time :
					_Query.Append (TimeSpan.Parse ((string) constant.Value).ToString ());
					break;
			}
			_Query.Append ("' ");
		}
コード例 #4
0
ファイル: AccessDialect.cs プロジェクト: npenin/uss
 public override void Visit(Constant constant)
 {
     if (constant.DbType == DbType.DateTime || constant.DbType == DbType.Time || constant.DbType == DbType.Date)
     {
         DateTime date = DateTime.Parse((string)constant.Value);
         _Query.AppendFormat("#{0} {1}#", date.ToString(Culture.DateTimeFormat.ShortDatePattern), date.ToString(Culture.DateTimeFormat.LongTimePattern));
     }
     else
         base.Visit(constant);
 }
コード例 #5
0
        public void Process(DeleteEntityCommand c)
        {
            EntityMapping deleteEntityMapping = _Mapping.Entities[c.Type, true];
            Hashtable cmds = new Hashtable();

            foreach (ReferenceMapping refm in deleteEntityMapping.References)
            {
                Evaluant.Uss.Models.Reference reference = _Engine.Model.GetReference(c.Type, refm.Name);
                EntityMapping entityChildMapping = _Mapping.Entities[refm.EntityChild];

                if (!reference.ToMany)
                    continue;
                foreach (RuleMapping rulem in refm.Rules)
                {
                    if (rulem.ParentTable == deleteEntityMapping.Table)
                    {
                        // update child table
                        SQLCommand cmd = (SQLCommand)cmds[rulem.ChildTable];
                        EntityMapping childEntity = _Mapping.Entities[refm.EntityChild];
                        if (!reference.IsComposition && rulem.ChildTable == childEntity.Table)
                        {
                            if (cmd == null)
                            {
                                cmd = new UpdateCommand(rulem, rulem.ChildTable);
                                cmds.Add(rulem.ChildTable, cmd);
                            }
                        }
                        else
                        {
                            if (cmd == null)
                            {
                                cmd = new DeleteCommand(rulem, rulem.ChildTable);
                                cmds.Add(rulem.ChildTable, cmd);
                            }
                        }

                        //if (cmd is DeleteCommand)
                        //    continue;

                        for (int i = 0; i < rulem.ParentFields.Length; i++)
                        {
                            DbType dbType;
                            if (deleteEntityMapping.IdFields.Contains(refm.Rules[0].ParentFields[i]))
                            {
                                dbType = _Dialect.GetDbTypeToPrimaryKey(deleteEntityMapping.Ids[refm.Rules[0].ParentFields[i]].Generator);
                            }
                            else
                            {
                                dbType = _Dialect.GetDbTypeToPrimaryKey(childEntity.Ids[refm.Rules[0].ChildFields[i]].Generator);
                            }


                            Constant newValue;
                            if (rulem.ParentDefaultValues.Length > i && !string.IsNullOrEmpty(rulem.ParentDefaultValues[i]))
                                newValue = new Constant(rulem.ParentDefaultValues[i], dbType);
                            else
                                newValue = new Constant(DBNull.Value, dbType);

                            // SSX 28/01/08: add contains test
                            if (entityChildMapping.Ids[rulem.ChildFields[i]] == null && cmd is UpdateCommand
                                && !((UpdateCommand)cmd).ColumnValueCollection.Contains(rulem.ChildFields[i]))
                                ((UpdateCommand)cmd).ColumnValueCollection.Add(rulem.ChildFields[i], newValue);

                            Column childField = new Column(rulem, rulem.ChildFields[i]);
                            Constant childParameter = new Constant(ConvertId(deleteEntityMapping, rulem.ParentFields[i], c.ParentId), dbType);
                            BinaryLogicExpression parentClause = new BinaryLogicExpression(childField, BinaryLogicOperator.Equals, childParameter);
                            if (cmd is UpdateCommand)
                                ((UpdateCommand)cmd).WhereClause.SearchCondition.Add(parentClause);
                            else
                                ((DeleteCommand)cmd).Condition.SearchCondition.Add(parentClause);
                        }

                        if (!string.IsNullOrEmpty(rulem.Constraint))
                            DisableForeignKeys(rulem.ChildTable);
                    }
                }
            }

            // Deletes all references to and from it first
            foreach (EntityMapping em in _Mapping.Entities)
            {
                foreach (ReferenceMapping refm in em.References)
                {
                    //Evaluant.Uss.Models.Model childModel = _Engine.Model.GetEntity(

                    if (refm.EntityChild == deleteEntityMapping.Type) // To
                    {
                        for (int indexRule = 0; indexRule < refm.Rules.Count; indexRule++)
                        {
                            RuleMapping rulem = refm.Rules[indexRule];
                            if ((rulem.ChildField == deleteEntityMapping.IdFields &&
                                deleteEntityMapping.DiscriminatorField == null) ||
                                (rulem.ChildField + ";" + deleteEntityMapping.DiscriminatorField == deleteEntityMapping.IdFields &&
                                deleteEntityMapping.DiscriminatorField != null))
                            {
                                // delete childtable

                                if (cmds.ContainsKey(rulem.ChildTable))
                                    continue;

                                DeleteCommand cmd = new DeleteCommand(rulem, rulem.ChildTable);
                                cmds.Add(rulem.ChildTable, cmd);

                                for (int index = 0; index < rulem.ChildFields.Length; index++)
                                {
                                    DbType dbType = _Dialect.GetDbTypeToPrimaryKey(deleteEntityMapping.Ids[index].Generator);

                                    cmd.Condition.SearchCondition.Add(new BinaryLogicExpression(
                                        new Column(rulem, rulem.ChildFields[index]),
                                        BinaryLogicOperator.Equals,
                                        new Constant(ConvertId(deleteEntityMapping, rulem.ChildFields[index], c.ParentId), dbType)
                                    ));
                                }


                                if (!string.IsNullOrEmpty(refm.DiscriminatorField) && indexRule == refm.Rules.Count - 1)
                                {
                                    cmd.Condition.SearchCondition.Add(new BinaryLogicExpression(
                                        new Column(rulem, refm.DiscriminatorField),
                                        BinaryLogicOperator.Equals,
                                        new Parameter(rulem, refm.DiscriminatorValue)
                                        ));
                                }

                                if (!string.IsNullOrEmpty(rulem.Constraint))
                                    DisableForeignKeys(rulem.ChildTable);
                            }

                            if (rulem.ParentField != em.IdFields && em.DiscriminatorField != null
                                || rulem.ParentTable != em.Table)
                            {
                                // update parent table
                                SQLCommand cmd = (SQLCommand)cmds[rulem.ParentTable];
                                if (cmd == null)
                                {
                                    cmd = new UpdateCommand(rulem, rulem.ParentTable);
                                    cmds.Add(rulem.ParentTable, cmd);
                                }

                                if (cmd is DeleteCommand)
                                    continue;

                                for (int i = 0; i < rulem.ParentFields.Length; i++)
                                {
                                    DbType dbType = _Dialect.GetDbTypeToPrimaryKey(deleteEntityMapping.Ids[i].Generator);

                                    Constant newValue = new Constant(DBNull.Value, dbType);
                                    if (rulem.ParentDefaultValues.Length > i && !string.IsNullOrEmpty(rulem.ParentDefaultValues[i]))
                                        newValue = new Constant(rulem.ParentDefaultValues[i], dbType);

                                    // SSX 28/01/08: add contains test
                                    if (em.Ids[rulem.ParentFields[i]] == null
                                        && !((UpdateCommand)cmd).ColumnValueCollection.Contains(rulem.ParentFields[i]))
                                        ((UpdateCommand)cmd).ColumnValueCollection.Add(rulem.ParentFields[i], newValue);

                                    Column parentField = new Column(rulem, rulem.ParentFields[i]);
                                    Constant parentParameter = new Constant(ConvertId(deleteEntityMapping, rulem.ParentFields[i], c.ParentId), dbType);
                                    BinaryLogicExpression parentClause = new BinaryLogicExpression(parentField, BinaryLogicOperator.Equals, parentParameter);
                                    ((UpdateCommand)cmd).WhereClause.SearchCondition.Add(parentClause);
                                }

                                // UPDATE parentTable SET parentField = NULL WHERE (parentField = @parentValue AND discriminator = 'name's relation')
                                if (!string.IsNullOrEmpty(refm.DiscriminatorField) && indexRule == refm.Rules.Count - 1)
                                {
                                    Column discriminatorField = new Column(rulem, rulem.ParentField);
                                    Constant discriminatorValue = new Constant(refm.DiscriminatorValue, DbType.AnsiString);
                                    BinaryLogicExpression discriminatorClause = new BinaryLogicExpression(discriminatorField, BinaryLogicOperator.Equals, discriminatorValue);
                                    ((UpdateCommand)cmd).WhereClause.SearchCondition.Add(discriminatorClause);
                                }

                                if (!string.IsNullOrEmpty(rulem.Constraint))
                                    DisableForeignKeys(rulem.ParentTable);

                            }
                        }

                    }

                }
            }


            // Deletes all attributes if they are in a separate table
            if (deleteEntityMapping.Attributes != null)
            {
                foreach (AttributeMapping am in deleteEntityMapping.Attributes)
                {
                    if (am.Table != deleteEntityMapping.Table)
                    {
                        DeleteCommand cmd = new DeleteCommand(am, am.Table);
                        for (int index = 0; index < deleteEntityMapping.Ids.Count; index++)
                        {
                            PrimaryKeyMapping pkm = deleteEntityMapping.Ids[index];
                            cmd.Condition.SearchCondition.Add(new BinaryLogicExpression(
                                new Column(am, am.ParentFields[index]),
                                BinaryLogicOperator.Equals,
                                new Constant(ConvertId(deleteEntityMapping, pkm.Field, c.ParentId), _Dialect.GetDbTypeToPrimaryKey(pkm.Generator))));
                        }
                        cmds.Add(am.Table, cmd);
                    }
                }
            }

            // SSX 28/01/08: remove table if already existing
            if (cmds.Contains(deleteEntityMapping.Table))
            {
                cmds.Remove(deleteEntityMapping.Table);
            }

            if (!cmds.ContainsKey(deleteEntityMapping.Table))
            {
                DeleteCommand cmd = new DeleteCommand(deleteEntityMapping, deleteEntityMapping.Table);
                for (int index = 0; index < deleteEntityMapping.Ids.Count; index++)
                {
                    PrimaryKeyMapping pkm = deleteEntityMapping.Ids[index];
                    cmd.Condition.SearchCondition.Add(new BinaryLogicExpression(
                        new Column(deleteEntityMapping, pkm.Field),
                        BinaryLogicOperator.Equals,
                        new Constant(ConvertId(deleteEntityMapping, pkm.Field, c.ParentId), _Dialect.GetDbTypeToPrimaryKey(pkm.Generator))));
                }
                cmds.Add(deleteEntityMapping.Table, cmd);
            }

            foreach (string tableName in cmds.Keys)
            {

                foreach (string query in _Dialect.RenderQueries((ISQLExpression)cmds[tableName]))
                {
                    if (!string.IsNullOrEmpty(query))
                    {
                        IDbCommand cmd = _Driver.CreateCommand(query, _Connection, _Transaction);
                        if (_Engine.TraceSqlSwitch.Enabled)
                            TraceHelpler.Trace(cmd, _Dialect);

                        cmd.ExecuteNonQuery();
                    }
                }


            }


        }
コード例 #6
0
        public void Process(DeleteReferenceCommand c)
        {
            ReferenceMapping referenceMapping = null;
            if (!string.IsNullOrEmpty(c.ChildType))
                referenceMapping = _Mapping.Entities[c.ParentType, true].References[c.Role, c.ChildType];
            else
                referenceMapping = _Mapping.Entities[c.ParentType, true].References[c.Role];

            if (referenceMapping == null)
            {
                Evaluant.Uss.Models.Entity current = _Engine.Model.GetEntity(c.ParentType);
                while (referenceMapping == null && current != null)
                {
                    Evaluant.Uss.Models.Entity currentChild = _Engine.Model.GetEntity(c.ChildType);
                    while (referenceMapping == null && currentChild != null)
                    {
                        referenceMapping = _Mapping.Entities[current.Type, true].References[c.Role, current.Type, currentChild.Type];
                        currentChild = _Engine.Model.GetParent(currentChild);
                    }

                    if (referenceMapping == null)
                        current = _Engine.Model.GetParent(current);
                }
            }

            if (referenceMapping == null)
                throw new Exception(String.Format("The reference '{0}' of the entity '{1}' is not defined in your mapping file", c.Role, c.ParentType));

            EntityMapping parentMapping = referenceMapping.EntityParent;
            EntityMapping childMapping = _Mapping.Entities[referenceMapping.EntityChild, true];

            RuleMappingCollection rules = referenceMapping.Rules;

            bool isParentRefered = true;

            // Delete all records to index tables
            for (int index = 0; index < rules.Count; index++)
            {
                ISQLExpression query = null;

                //if first rule : ParentField is a foreign key ==> update parent table
                if ((index == 0) && (rules[index].ParentField != parentMapping.IdFields))
                {
                    // UPDATE parenttable SET FK_column = NULL WHERE PK_Column = PK_Value
                    query = new UpdateCommand(rules[index], rules[index].ParentTable);

                    for (int i = 0; i < rules[index].ParentFields.Length; i++)
                    {
                        if (parentMapping.Ids[rules[index].ParentFields[i]] == null)
                        {
                            Constant constant = new Constant(DBNull.Value, _Dialect.GetDbTypeToPrimaryKey(childMapping.Ids[i].Generator));
                            if (rules[index].ParentDefaultValues.Length > i && !string.IsNullOrEmpty(rules[index].ParentDefaultValues[i]))
                                constant = new Constant(rules[index].ParentDefaultValues[i], _Dialect.GetDbTypeToPrimaryKey(childMapping.Ids[i].Generator));

                            ((UpdateCommand)query).ColumnValueCollection.Add(rules[index].ParentFields[i], constant);
                        }
                    }

                    for (int i = 0; i < parentMapping.Ids.Count; i++)
                    {
                        string PK_Column = parentMapping.IdFields.Split(SqlMapperProvider.IDSEP)[i];
                        string PK_Value = ConvertId(parentMapping, PK_Column, c.ParentId);
                        ((UpdateCommand)query).WhereClause.SearchCondition.Add(new BinaryLogicExpression(
                             new Column(parentMapping.Ids[i], PK_Column),
                             BinaryLogicOperator.Equals,
                             new Constant(PK_Value, _Dialect.GetDbTypeToPrimaryKey(parentMapping.Ids[i].Generator))));
                    }



                    ExecuteCommand(query);
                }

                //if last rule : ChildField is a foreign key ==> update child table
                if ((index == rules.Count - 1) && (rules[index].ChildField != childMapping.IdFields))
                {
                    // UPDATE childtable SET FK_column = NULL WHERE PK_Column = PK_Value
                    query = new UpdateCommand(rules[index], rules[index].ChildTable);


                    for (int i = 0; i < rules[index].ChildFields.Length; i++)
                    {
                        if (childMapping.Ids[rules[index].ChildFields[i]] == null)
                        {
                            Constant constant = new Constant(DBNull.Value, _Dialect.GetDbTypeToPrimaryKey(parentMapping.Ids[i].Generator));
                            if (rules[index].ChildDefaultValues.Length > i && !string.IsNullOrEmpty(rules[index].ChildDefaultValues[i]))
                                constant = new Constant(rules[index].ChildDefaultValues[i], _Dialect.GetDbTypeToPrimaryKey(parentMapping.Ids[i].Generator));

                            ((UpdateCommand)query).ColumnValueCollection.Add(rules[index].ChildFields[i], constant);
                        }
                    }

                    for (int i = 0; i < childMapping.Ids.Count; i++)
                        ((UpdateCommand)query).WhereClause.SearchCondition.Add(new BinaryLogicExpression(
                           new Column(childMapping.Ids[i], childMapping.IdFields.Split(SqlMapperProvider.IDSEP)[i]),
                           BinaryLogicOperator.Equals,
                           new Constant(ConvertId(childMapping, childMapping.IdFields.Split(SqlMapperProvider.IDSEP)[i], c.ChildId), _Dialect.GetDbTypeToPrimaryKey(childMapping.Ids[i].Generator))));

                    //PrimaryKeyMapping PK_mapping = index == 0 ? parentMapping.Ids[0] : childMapping.Ids[0];
                    //string PK_column = childMapping.IdFields;
                    //string PK_value = c.ChildId;



                    ExecuteCommand(query);
                }

                // Execute a delete command to index table
                if (index != rules.Count - 1)
                {
                    // Delete records to index table with one foreign key : rule(n).ChildField == rule(n+1).ParentField
                    if (rules[index].ChildField == rules[index + 1].ParentField)
                    {
                        // the refered table is parent table ==> WHERE rule(n).ChildField == ParentId
                        if (isParentRefered)
                        {
                            query = new DeleteCommand(rules[index], rules[index].ChildTable);
                            ((DeleteCommand)query).Condition.SearchCondition.Add(new BinaryLogicExpression(
                                new Column(rules[index], rules[index].ChildField),
                                BinaryLogicOperator.Equals,
                                new Constant(c.ParentId, _Dialect.GetDbTypeToPrimaryKey(parentMapping.Ids[0].Generator))));

                        }

                        // the refered table is child table ==>  WHERE rule(n).ChildField == ChildId
                        else
                        {
                            query = new DeleteCommand(rules[index], rules[index].ChildTable);
                            ((DeleteCommand)query).Condition.SearchCondition.Add(new BinaryLogicExpression(
                                new Column(rules[index], rules[index].ChildField),
                                BinaryLogicOperator.Equals,
                                new Constant(c.ChildId, _Dialect.GetDbTypeToPrimaryKey(childMapping.Ids[0].Generator))));
                        }

                    }

                    // Delete records to index table with two foreign key : rule(n).ChildField != rule(n+1).ParentField
                    else
                    {
                        query = new DeleteCommand(rules[index], rules[index].ChildTable);
                        ((DeleteCommand)query).Condition.SearchCondition.Add(new BinaryLogicExpression(
                            new Column(rules[index], rules[index].ChildField),
                            BinaryLogicOperator.Equals,
                            new Constant(c.ParentId, _Dialect.GetDbTypeToPrimaryKey(parentMapping.Ids[0].Generator))));
                        ((DeleteCommand)query).Condition.SearchCondition.Add(new BinaryLogicExpression(
                            new Column(rules[index + 1], rules[index + 1].ParentField),
                            BinaryLogicOperator.Equals,
                            new Constant(c.ChildId, _Dialect.GetDbTypeToPrimaryKey(childMapping.Ids[0].Generator))));
                        isParentRefered = false;
                    }

                    ExecuteCommand(query);
                }
            }
        }
コード例 #7
0
ファイル: SqlMapperTransformer.cs プロジェクト: npenin/uss
 public override void Visit(Value val)
 {
     ISQLExpression value = null;
     switch (val.Type)
     {
         case ValueEnum.Boolean:
             value = new Constant(val.Text, DbType.Boolean);
             break;
         case ValueEnum.Date:
             value = new Constant(val.Text, DbType.Date);
             break;
         case ValueEnum.Float:
             value = new Constant(val.Text, DbType.Double);
             break;
         case ValueEnum.Integer:
             value = new Constant(val.Text, DbType.Int32);
             break;
         case ValueEnum.String:
             value = new Constant(val.Text, DbType.AnsiString);
             break;
         case ValueEnum.Unknown:
             value = null;
             break;
     }
     sqlExpressionContext.Push(value);
 }
コード例 #8
0
ファイル: SqlMapperTransformer.cs プロジェクト: npenin/uss
        public override void Visit(BinaryOperator binaryop)
        {
            bool firstIsType = ((int)_ExprLevel.Peek() == EXPR);
            _ExprLevel.Push(_ExprLevel.Peek());

            ISQLExpression expression = null;

            EntityMapping entityMap = null;
            if (!firstIsType)
                entityMap = (EntityMapping)entityMappingContext.Peek();

            //	Try to get the queried attribute. If it is a date type and the 
            //	corresponding mapping is generic, we have to convert the value as ticks
            //	instead of the standard representation

            Value val = binaryop.LeftOperand as Value;
            Path path = binaryop.LeftOperand as Path;

            if (val == null)
                val = binaryop.RightOperand as Value;

            if (path == null)
                path = binaryop.RightOperand as Path;

            if (!firstIsType)
            {
                if (val != null && path != null && path.Identifiers.Count == 1)
                {
                    AttributeMapping am = entityMap.Attributes[path.Identifiers[path.Identifiers.Count - 1].Value, true];

                    if (val.Type == ValueEnum.Date)
                    {
                        //	If the field type isn't date type, convert the value as ticks
                        if (am.DbType != DbType.Date && am.DbType != DbType.DateTime && am.DbType != DbType.Time)
                        {
                            DateTime dt = Convert.ToDateTime(val.Text);
                            val.Text = Common.Utils.ConvertToString(dt, dt.GetType());
                        }
                    }
                }
            }

            ISQLExpression discriminatorConstraint = null;
            Path p = binaryop.LeftOperand as Path;
            if (p == null)
                p = binaryop.RightOperand as Path;

            if (p != null && !firstIsType)
            {
                AttributeMapping am = entityMap.Attributes[p.Identifiers[p.Identifiers.Count - 1].Value];

                if (am != null &&
                    am.Discriminator != null &&
                    am.Discriminator != string.Empty &&
                    am.DiscriminatorValue != null &&
                    am.DiscriminatorValue != string.Empty)
                {
                    Column left = new Column(am, am.Discriminator);
                    Constant right = new Constant(path.Identifiers[path.Identifiers.Count - 1].Value, DbType.AnsiStringFixedLength);
                    discriminatorConstraint = new BinaryLogicExpression(
                        left,
                        BinaryLogicOperator.Equals,
                        right);
                }
            }

            switch (binaryop.Type)
            {
                case BinaryOperatorEnum.And:
                    binaryop.LeftOperand.Accept(this);
                    ISQLExpression leftValueExpression = (ISQLExpression)sqlExpressionContext.Pop();

                    binaryop.RightOperand.Accept(this);
                    ISQLExpression rightValueExpression = (ISQLExpression)sqlExpressionContext.Pop();

                    expression = new BinaryLogicExpression(leftValueExpression, BinaryLogicOperator.And, rightValueExpression);

                    if (discriminatorConstraint != null)
                        expression = new BinaryLogicExpression(
                            expression,
                            BinaryLogicOperator.And,
                            discriminatorConstraint);

                    sqlExpressionContext.Push(expression);

                    break;
                case BinaryOperatorEnum.Or:
                    binaryop.LeftOperand.Accept(this);
                    leftValueExpression = (ISQLExpression)sqlExpressionContext.Pop();

                    binaryop.RightOperand.Accept(this);
                    rightValueExpression = (ISQLExpression)sqlExpressionContext.Pop();

                    expression = new BinaryLogicExpression(leftValueExpression, BinaryLogicOperator.Or, rightValueExpression);

                    if (discriminatorConstraint != null)
                        expression = new BinaryLogicExpression(
                            expression,
                            BinaryLogicOperator.And,
                            discriminatorConstraint);

                    sqlExpressionContext.Push(expression);

                    break;
                case BinaryOperatorEnum.Equal:

                    binaryop.LeftOperand.Accept(this);
                    leftValueExpression = (ISQLExpression)sqlExpressionContext.Pop();

                    binaryop.RightOperand.Accept(this);
                    rightValueExpression = (ISQLExpression)sqlExpressionContext.Pop();

                    expression = new BinaryLogicExpression(leftValueExpression, BinaryLogicOperator.Equals, rightValueExpression);

                    if (discriminatorConstraint != null)
                        expression = new BinaryLogicExpression(
                            expression,
                            BinaryLogicOperator.And,
                            discriminatorConstraint);

                    sqlExpressionContext.Push(expression);

                    break;
                case BinaryOperatorEnum.Greater:
                    binaryop.LeftOperand.Accept(this);
                    leftValueExpression = (ISQLExpression)sqlExpressionContext.Pop();

                    binaryop.RightOperand.Accept(this);
                    rightValueExpression = (ISQLExpression)sqlExpressionContext.Pop();

                    expression = new BinaryLogicExpression(leftValueExpression, BinaryLogicOperator.Greater, rightValueExpression);

                    if (discriminatorConstraint != null)
                        expression = new BinaryLogicExpression(
                            expression,
                            BinaryLogicOperator.And,
                            discriminatorConstraint);

                    sqlExpressionContext.Push(expression);
                    break;

                case BinaryOperatorEnum.GreaterOrEqual:
                    binaryop.LeftOperand.Accept(this);
                    leftValueExpression = (ISQLExpression)sqlExpressionContext.Pop();

                    binaryop.RightOperand.Accept(this);
                    rightValueExpression = (ISQLExpression)sqlExpressionContext.Pop();

                    expression = new BinaryLogicExpression(leftValueExpression, BinaryLogicOperator.GreaterOrEquals, rightValueExpression);

                    if (discriminatorConstraint != null)
                        expression = new BinaryLogicExpression(
                            expression,
                            BinaryLogicOperator.And,
                            discriminatorConstraint);

                    sqlExpressionContext.Push(expression);
                    break;
                case BinaryOperatorEnum.Lesser:
                    binaryop.LeftOperand.Accept(this);
                    leftValueExpression = (ISQLExpression)sqlExpressionContext.Pop();

                    binaryop.RightOperand.Accept(this);
                    rightValueExpression = (ISQLExpression)sqlExpressionContext.Pop();

                    expression = new BinaryLogicExpression(leftValueExpression, BinaryLogicOperator.Lesser, rightValueExpression);

                    if (discriminatorConstraint != null)
                        expression = new BinaryLogicExpression(
                            expression,
                            BinaryLogicOperator.And,
                            discriminatorConstraint);

                    sqlExpressionContext.Push(expression);
                    break;
                case BinaryOperatorEnum.LesserOrEqual:
                    binaryop.LeftOperand.Accept(this);
                    leftValueExpression = (ISQLExpression)sqlExpressionContext.Pop();

                    binaryop.RightOperand.Accept(this);
                    rightValueExpression = (ISQLExpression)sqlExpressionContext.Pop();

                    expression = new BinaryLogicExpression(leftValueExpression, BinaryLogicOperator.LesserOrEquals, rightValueExpression);

                    if (discriminatorConstraint != null)
                        expression = new BinaryLogicExpression(
                            expression,
                            BinaryLogicOperator.And,
                            discriminatorConstraint);

                    sqlExpressionContext.Push(expression);
                    break;

                case BinaryOperatorEnum.NotEqual:
                    binaryop.LeftOperand.Accept(this);
                    leftValueExpression = (ISQLExpression)sqlExpressionContext.Pop();

                    binaryop.RightOperand.Accept(this);
                    rightValueExpression = (ISQLExpression)sqlExpressionContext.Pop();

                    expression = new BinaryLogicExpression(leftValueExpression, BinaryLogicOperator.NotEquals, rightValueExpression);

                    if (discriminatorConstraint != null)
                        expression = new BinaryLogicExpression(
                            expression,
                            BinaryLogicOperator.And,
                            discriminatorConstraint);

                    sqlExpressionContext.Push(expression);
                    break;

                case BinaryOperatorEnum.Plus:
                case BinaryOperatorEnum.Times:
                case BinaryOperatorEnum.Div:
                case BinaryOperatorEnum.Minus:
                case BinaryOperatorEnum.Modulo:
                    binaryop.LeftOperand.Accept(this);
                    leftValueExpression = (ISQLExpression)sqlExpressionContext.Pop();

                    binaryop.RightOperand.Accept(this);
                    rightValueExpression = (ISQLExpression)sqlExpressionContext.Pop();

                    expression = new BinaryLogicExpression(leftValueExpression, BinaryOperatorToBinaryLogicOperator(binaryop.Type), rightValueExpression);

                    if (discriminatorConstraint != null)
                        expression = new BinaryLogicExpression(expression, BinaryLogicOperator.And, discriminatorConstraint);

                    sqlExpressionContext.Push(expression);
                    break;

                case BinaryOperatorEnum.Contains:
                    binaryop.LeftOperand.Accept(this);
                    leftValueExpression = (ISQLExpression)sqlExpressionContext.Pop();

                    binaryop.RightOperand.Accept(this);
                    rightValueExpression = (ISQLExpression)sqlExpressionContext.Pop();

                    expression = new LikePredicate(leftValueExpression, String.Format("%{0}%", (string)((Constant)rightValueExpression).Value));

                    if (discriminatorConstraint != null)
                        expression = new BinaryLogicExpression(
                            expression,
                            BinaryLogicOperator.And,
                            discriminatorConstraint);

                    sqlExpressionContext.Push(expression);
                    break;

                case BinaryOperatorEnum.BeginsWith:
                    binaryop.LeftOperand.Accept(this);
                    leftValueExpression = (ISQLExpression)sqlExpressionContext.Pop();

                    binaryop.RightOperand.Accept(this);
                    rightValueExpression = (ISQLExpression)sqlExpressionContext.Pop();

                    expression = new LikePredicate(leftValueExpression, String.Format("{0}%", (string)((Constant)rightValueExpression).Value));

                    if (discriminatorConstraint != null)
                        expression = new BinaryLogicExpression(
                            expression,
                            BinaryLogicOperator.And,
                            discriminatorConstraint);

                    sqlExpressionContext.Push(expression);

                    break;
                case BinaryOperatorEnum.EndsWith:
                    binaryop.LeftOperand.Accept(this);
                    leftValueExpression = (ISQLExpression)sqlExpressionContext.Pop();

                    binaryop.RightOperand.Accept(this);
                    rightValueExpression = (ISQLExpression)sqlExpressionContext.Pop();

                    expression = new LikePredicate(leftValueExpression, String.Format("%{0}", (string)((Constant)rightValueExpression).Value));

                    if (discriminatorConstraint != null)
                        expression = new BinaryLogicExpression(
                            expression,
                            BinaryLogicOperator.And,
                            discriminatorConstraint);

                    sqlExpressionContext.Push(expression);

                    break;
            }

            _ExprLevel.Pop();
        }
コード例 #9
0
ファイル: Db2Dialect.cs プロジェクト: npenin/uss
        public override void Visit(Constant constant)
        {
            if (constant.Value == DBNull.Value)
            {
                _Query.Append(Db2Dialect.CAST)
                    .Append(Db2Dialect.OPENBRACE)
                .Append(Db2Dialect.NULL)
                .Append(Db2Dialect.AS)
                .Append(TypeName(constant.DbType, 0).FormatType())
                .Append(Db2Dialect.CLOSEBRACE);

                if (!string.IsNullOrEmpty(constant.Alias))
                    _Query.Append(SPACE).Append(AS).Append(FormatAttribute(constant.Alias)).Append(SPACE);
            }
            else
            {
                switch (constant.DbType)
                {
                    case DbType.Date :
                        _Query.Append(SINGLEQUOTE).Append(DateTime.Parse(constant.Value.ToString()).ToString("yyyy-MM-dd", base.Culture)).Append(SINGLEQUOTE);
                        break;
                    case DbType.Time :
                        _Query.Append(SINGLEQUOTE).Append(DateTime.Parse(constant.Value.ToString()).ToString("HH.mm.ss", base.Culture)).Append(SINGLEQUOTE);
                        break;
                   
                    default:

                        base.Visit(constant);
                        break;
                }
               
            }
        }
コード例 #10
0
ファイル: OracleDialect.cs プロジェクト: npenin/uss
        public override void Visit(Constant constant)
        {

           
            switch (constant.DbType)
            {
                case DbType.Date:
                case DbType.DateTime:
                case DbType.Time:
                    DateTime date = DateTime.Parse((string)constant.Value);
                    _Query.AppendFormat("TO_DATE('{0} {1}', 'DD/MM/YYYY HH24:MI:SS')", date.ToString("dd/MM/yyyy"), date.ToString("HH:mm:ss", Culture));
                    break;

                case DbType.Binary:
                    // Format string for binary content in queries (e.g., 0xC9CBBBCCCEB9C8CABCCCCEB9C9CBBB )
                    _Query.Append(SINGLEQUOTE);
                    foreach (byte b in (byte[])constant.Value)
                    {
                        _Query.Append(Convert.ToString(b, 16));
                    }
                    _Query.Append(SINGLEQUOTE);
                    break;

                default:
                    base.Visit(constant);
                    break;
            }
        }
コード例 #11
0
ファイル: DBDialect.cs プロジェクト: npenin/uss
		public virtual void Visit(Constant constant)
		{
			string result = String.Empty;

			if(constant.Value != DBNull.Value)
			{
				switch(constant.DbType)
				{
					case DbType.AnsiStringFixedLength:
					case DbType.StringFixedLength:
						if (constant.Value.ToString() == STAR)
							_Query.Append (MULT);
						else 
                        {
							result = constant.Value.ToString();
							result = result.Replace (SINGLEQUOTE, DOUBLESINGLEQUOTE);
                            _Query.Append(SINGLEQUOTE).Append(result).Append(SINGLEQUOTE);
						}
						break;
                    case DbType.Guid:
                    case DbType.AnsiString:
					case DbType.String:
						result = (string) constant.Value;
                        result = result.Replace(SINGLEQUOTE, DOUBLESINGLEQUOTE);
                        _Query.Append(SINGLEQUOTE).Append(result).Append(SINGLEQUOTE);
						break;

					case DbType.Date:
					case DbType.DateTime:
						_Query.Append(SINGLEQUOTE).Append(DateTime.Parse(constant.Value.ToString()).ToString("s", _Culture)).Append(SINGLEQUOTE);
						break;
					case DbType.Boolean:
                        _Query.Append(FormatValue(constant.Value.ToString(), DbType.Boolean));
                        break;
					case DbType.Byte: /// TODO: Comment the reason of this case (if it is necessary)
						_Query.Append((byte)constant.Value);
						break;
					
					case DbType.Int32:
					case DbType.Binary:
					case DbType.Currency:
					case DbType.Decimal:
					case DbType.Double:
					case DbType.Int16:
					case DbType.Int64:
					case DbType.Object:
					case DbType.SByte:
					case DbType.Single:
					case DbType.UInt16:
					case DbType.UInt32:
					case DbType.UInt64:
					case DbType.VarNumeric:
						_Query.Append(Convert.ToString(constant.Value, _Culture));
						break;
				}
			}
			else
			{
				_Query.Append(NULL);
			}

            _Query.Append(SPACE);
            if (constant.Alias != null && constant.Alias != string.Empty)
                _Query.Append(AS).Append(FormatAttribute(constant.Alias)).Append(SPACE);
				
		}