Reference() public static méthode

public static Reference ( ObjectName objectName ) : SqlReferenceExpression
objectName ObjectName
Résultat SqlReferenceExpression
        public static void PrepareFromSqlQuery()
        {
            var sqlQuery = new SqlQuery("SELECT * FROM table1 WHERE a = ? AND b = ?", SqlQueryParameterNaming.Marker);

            sqlQuery.Parameters.Add(new SqlQueryParameter(PrimitiveTypes.Integer(), (SqlNumber)2));
            sqlQuery.Parameters.Add(new SqlQueryParameter(PrimitiveTypes.Integer(), (SqlNumber)1023));

            var preparer = sqlQuery.ExpressionPreparer;

            var queryExp = new SqlQueryExpression();

            queryExp.From.Table(new ObjectName("table1"));
            queryExp.Items.Add(SqlExpression.Reference(new ObjectName("*")));
            queryExp.Where = SqlExpression.And(
                SqlExpression.Equal(SqlExpression.Reference(new ObjectName("a")), SqlExpression.Parameter()),
                SqlExpression.Equal(SqlExpression.Reference(new ObjectName("b")), SqlExpression.Parameter()));

            var prepared = queryExp.Prepare(preparer);

            Assert.IsType <SqlQueryExpression>(prepared);

            var sb = new SqlStringBuilder();

            sb.AppendLine("SELECT *");
            sb.AppendLine("  FROM table1");
            sb.Append("  WHERE a = 2 AND b = 1023");

            var expectString = sb.ToString();

            Assert.Equal(expectString, prepared.ToString());
        }
Exemple #2
0
        public async Task ReduceOutsideScope()
        {
            var objName = ObjectName.Parse("a.b");

            var exp = SqlExpression.Reference(objName);

            await Assert.ThrowsAsync <SqlExpressionException>(() => exp.ReduceAsync(null));
        }
Exemple #3
0
        public void CreateReference(string name)
        {
            var objName = ObjectName.Parse(name);
            var exp     = SqlExpression.Reference(objName);

            Assert.NotNull(exp.ReferenceName);
            Assert.Equal(objName, exp.ReferenceName);
        }
Exemple #4
0
        public void GetSqlType()
        {
            var name = ObjectName.Parse("a.b");
            var exp  = SqlExpression.Reference(name);

            var type = exp.GetSqlType(context);

            Assert.Equal(PrimitiveTypes.String(), type);
        }
Exemple #5
0
        public void GetReferenceString(string name)
        {
            var objName = ObjectName.Parse(name);
            var exp     = SqlExpression.Reference(objName);

            var sql = exp.ToString();

            Assert.Equal(name, sql);
        }
Exemple #6
0
        public async Task ReduceReference(string name)
        {
            var objName = ObjectName.Parse(name);

            var exp    = SqlExpression.Reference(objName);
            var result = await exp.ReduceAsync(context);

            Assert.NotNull(result);
        }
Exemple #7
0
        public static void VisitQuery()
        {
            var exp = new SqlQueryExpression();

            exp.Items.Add(SqlExpression.Reference(new ObjectName("a")));
            exp.From.Table(new ObjectName("b"));
            exp.From.Join(JoinType.Left,
                          SqlExpression.Equal(SqlExpression.Reference(ObjectName.Parse("b.id")), SqlExpression.Reference(ObjectName.Parse("c.b_id"))));
            exp.From.Table(new ObjectName("c"));
            exp.Where = SqlExpression.GreaterThanOrEqual(SqlExpression.Reference(new ObjectName("a")), SqlExpression.Constant(SqlObject.BigInt(22)));

            Visit(exp);
        }
Exemple #8
0
        public async Task ReduceNotFoundReference(string name)
        {
            var objName = ObjectName.Parse(name);

            var exp    = SqlExpression.Reference(objName);
            var result = await exp.ReduceAsync(context);

            Assert.NotNull(result);
            Assert.IsType <SqlConstantExpression>(result);

            var value = ((SqlConstantExpression)result).Value;

            Assert.Equal(SqlObject.Unknown, value);
        }
        public static void MakeNewNaturalJoinQuery()
        {
            var query = new SqlQueryExpression();

            query.Items.Add(SqlExpression.Reference(ObjectName.Parse("a.*")));
            query.Items.Add(SqlExpression.Reference(ObjectName.Parse("b.*")));
            query.From.Table(ObjectName.Parse("table1"), "a");
            query.From.Table(ObjectName.Parse("table2"), "b");

            var expected = new SqlStringBuilder();

            expected.AppendLine("SELECT a.*, b.*");
            expected.Append("  FROM table1 AS a, table2 AS b");
            Assert.Equal(expected.ToString(), query.ToString());
        }
        public static void CreateNewSimpleQuery()
        {
            var query = new SqlQueryExpression();

            query.Items.Add(SqlExpression.Reference(ObjectName.Parse("a.*")));
            query.Items.Add(SqlExpression.Reference(ObjectName.Parse("b")));
            query.From.Table(ObjectName.Parse("tab1"));


            var expected = new SqlStringBuilder();

            expected.AppendLine("SELECT a.*, b");
            expected.Append("  FROM tab1");

            Assert.False(query.From.IsEmpty);
            Assert.Equal(expected.ToString(), query.ToString());
        }
        public static void MakeNewInnerJoinQuery()
        {
            var query = new SqlQueryExpression();

            query.Items.Add(SqlExpression.Reference(ObjectName.Parse("a.*")));
            query.Items.Add(SqlExpression.Reference(ObjectName.Parse("b.*")));
            query.From.Table(ObjectName.Parse("table1"), "a");
            query.From.Join(JoinType.Inner,
                            SqlExpression.Equal(SqlExpression.Reference(ObjectName.Parse("a.id")),
                                                SqlExpression.Reference(ObjectName.Parse("b.a_id"))));
            query.From.Table(ObjectName.Parse("table2"), "b");

            var expected = new SqlStringBuilder();

            expected.AppendLine("SELECT a.*, b.*");
            expected.Append("  FROM table1 AS a INNER JOIN table2 AS b ON a.id = b.a_id");

            Assert.Equal(expected.ToString(), query.ToString());
        }
        public void ExecuteSelectAll()
        {
            var expression =
                new SqlQueryExpression(new[] { new SelectColumn(SqlExpression.Reference(new ObjectName("first_name"))) });

            expression.FromClause.AddTable("test_table");

            Field result = null;

            Assert.DoesNotThrow(() => result = expression.EvaluateToConstant(AdminQuery, null));
            Assert.IsNotNull(result);
            Assert.IsInstanceOf <QueryType>(result.Type);
            Assert.IsNotNull(result.Value);
            Assert.IsInstanceOf <SqlQueryObject>(result.Value);

            ITable queryResult = null;

            Assert.DoesNotThrow(() => queryResult = ((SqlQueryObject)result.Value).QueryPlan.Evaluate(AdminQuery));
            Assert.IsNotNull(queryResult);
            Assert.AreEqual(3, queryResult.RowCount);
        }
Exemple #13
0
            public override SqlReferenceExpression Deserialize(BinaryReader reader)
            {
                var name = ObjectName.Deserialize(reader);

                return(SqlExpression.Reference(name));
            }
        private void CreateTestTable()
        {
            var tableInfo = new TableInfo(ObjectName.Parse("APP.test_table"));
            var idColumn  = tableInfo.AddColumn("id", PrimitiveTypes.Integer());

            idColumn.DefaultExpression = SqlExpression.FunctionCall("UNIQUEKEY",
                                                                    new SqlExpression[] { SqlExpression.Reference(tableInfo.TableName) });
            tableInfo.AddColumn("first_name", PrimitiveTypes.String());
            tableInfo.AddColumn("last_name", PrimitiveTypes.String());
            tableInfo.AddColumn("birth_date", PrimitiveTypes.DateTime());
            tableInfo.AddColumn("active", PrimitiveTypes.Boolean());

            Query.CreateTable(tableInfo);
            Query.AddPrimaryKey(tableInfo.TableName, "id", "PK_TEST_TABLE");
        }
Exemple #15
0
 /// <summary>
 /// Creates a special <see cref="SelectColumn"/> that is used to select
 /// all the columns in a table.
 /// </summary>
 /// <param name="glob">The <i>glob</i> name for the column, which can be
 /// a simple asterisk (*) or prefixed by a table name (eg. Table.*).</param>
 /// <returns>
 /// Returns an instance of <see cref="SelectColumn"/> that is specially used
 /// for selecting all the columns from a table.
 /// </returns>
 public static SelectColumn Glob(string glob)
 {
     return(new SelectColumn(SqlExpression.Reference(ObjectName.Parse(glob))));
 }
Exemple #16
0
        public static void VisitReference()
        {
            var exp = SqlExpression.Reference(new ObjectName("a"));

            Visit(exp, true);
        }
Exemple #17
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="reference"></param>
 /// <returns></returns>
 public virtual SqlExpression VisitReference(SqlReferenceExpression reference)
 {
     return(SqlExpression.Reference(reference.ReferenceName));
 }
Exemple #18
0
 static SqlQueryExpressionItem()
 {
     All = new SqlQueryExpressionItem(SqlExpression.Reference(new ObjectName("*")));
 }