Inheritance: SqlStatement, IPreparable
        object IPreparable.Prepare(IExpressionPreparer preparer)
        {
            var statement = new DeclareVariableStatement(VariableName, VariableType);
            if (DefaultExpression != null)
                statement.DefaultExpression = DefaultExpression.Prepare(preparer);

            statement.IsConstant = IsConstant;
            return statement;
        }
Beispiel #2
0
 protected virtual SqlStatement VisitDeclareVariable(DeclareVariableStatement statement)
 {
     return(new DeclareVariableStatement(statement.VariableName, statement.VariableType)
     {
         IsNotNull = statement.IsNotNull,
         IsConstant = statement.IsConstant,
         DefaultExpression = statement.DefaultExpression
     });
 }
        public static void NotNullString()
        {
            var statement = new DeclareVariableStatement("a", PrimitiveTypes.VarChar(30)) {
                IsNotNull = true
            };

            var sql = statement.ToString();
            var expected = "a VARCHAR(30) NOT NULL";

            Assert.AreEqual(expected, sql);
        }
        public static void ConstantInteger()
        {
            var statement = new DeclareVariableStatement("a", PrimitiveTypes.Integer()) {
                IsConstant = true
            };

            var sql = statement.ToString();
            var expected = "CONSTANT a INTEGER";

            Assert.AreEqual(expected, sql);
        }
        protected override void BuildStatement(SqlCodeObjectBuilder builder)
        {
            var varType = DataTypeBuilder.Build(builder.TypeResolver, Type);
            var statement = new DeclareVariableStatement(VariableName, varType);
            if (DefaultExpression != null)
                statement.DefaultExpression = ExpressionBuilder.Build(DefaultExpression);

            statement.IsConstant = IsConstant;
            statement.IsNotNull = IsConstant || IsNotNull;
            builder.AddObject(statement);
        }
Beispiel #6
0
        protected override SqlStatement PrepareExpressions(IExpressionPreparer preparer)
        {
            var statement = new DeclareVariableStatement(VariableName, VariableType);

            if (DefaultExpression != null)
            {
                statement.DefaultExpression = DefaultExpression.Prepare(preparer);
            }

            statement.IsConstant = IsConstant;
            return(statement);
        }
        public static void BigIntWithDefault()
        {
            var statement = new DeclareVariableStatement("c", PrimitiveTypes.BigInt()) {
                DefaultExpression =
                    SqlExpression.Multiply(SqlExpression.Constant(56), SqlExpression.Reference(new ObjectName("test.a")))
            };

            var sql = statement.ToString();
            var expected = "c BIGINT := 56 * test.a";

            Assert.AreEqual(expected, sql);
        }
Beispiel #8
0
        object IPreparable.Prepare(IExpressionPreparer preparer)
        {
            var statement = new DeclareVariableStatement(VariableName, VariableType);

            if (DefaultExpression != null)
            {
                statement.DefaultExpression = DefaultExpression.Prepare(preparer);
            }

            statement.IsConstant = IsConstant;
            return(statement);
        }
        public static void NotNullString()
        {
            var statement = new DeclareVariableStatement("a", PrimitiveTypes.VarChar(30))
            {
                IsNotNull = true
            };

            var sql      = statement.ToString();
            var expected = "a VARCHAR(30) NOT NULL";

            Assert.AreEqual(expected, sql);
        }
        public static void ConstantInteger()
        {
            var statement = new DeclareVariableStatement("a", PrimitiveTypes.Integer())
            {
                IsConstant = true
            };

            var sql      = statement.ToString();
            var expected = "CONSTANT a INTEGER";

            Assert.AreEqual(expected, sql);
        }
        public static void BigIntWithDefault()
        {
            var statement = new DeclareVariableStatement("c", PrimitiveTypes.BigInt())
            {
                DefaultExpression =
                    SqlExpression.Multiply(SqlExpression.Constant(56), SqlExpression.Reference(new ObjectName("test.a")))
            };

            var sql      = statement.ToString();
            var expected = "c BIGINT := 56 * test.a";

            Assert.AreEqual(expected, sql);
        }
Beispiel #12
0
 protected virtual SqlStatement VisitDeclareVariable(DeclareVariableStatement statement)
 {
     return new DeclareVariableStatement(statement.VariableName, statement.VariableType) {
         IsNotNull = statement.IsNotNull,
         IsConstant = statement.IsConstant,
         DefaultExpression = statement.DefaultExpression
     };
 }
        public void DeclareVariable()
        {
            var statement = new DeclareVariableStatement("a", PrimitiveTypes.String());

            SerializeAndAssert(statement, (serialized, deserialized) => {
                Assert.IsNotNull(deserialized);
                Assert.IsNotNull(deserialized.VariableName);
                Assert.IsNotNull(deserialized.VariableType);

                Assert.AreEqual("a", deserialized.VariableName);
                Assert.IsInstanceOf<StringType>(deserialized.VariableType);
            });
        }
        protected override SqlStatement PrepareExpressions(IExpressionPreparer preparer)
        {
            var statement = new DeclareVariableStatement(VariableName, VariableType);
            if (DefaultExpression != null)
                statement.DefaultExpression = DefaultExpression.Prepare(preparer);

            statement.IsConstant = IsConstant;
            return statement;
        }