Exemplo n.º 1
0
 @Test
 public void testUpdateSetExpression() throws Exception {
   UpdateAnalyzedStatement statement = analyze("update users set other_id=other_id+1");
   UpdateAnalyzedStatement.NestedAnalyzedStatement statement1 =
       statement.nestedStatements().get(0);
   assertThat(statement1.assignments().size(), is(1));
   Symbol value = statement1.assignments().entrySet().iterator().next().getValue();
   assertThat(value, isFunction("add"));
 }
Exemplo n.º 2
0
 @Test
 public void testUpdateSetColumnToColumnValue() throws Exception {
   UpdateAnalyzedStatement statement = analyze("update users set name=name");
   UpdateAnalyzedStatement.NestedAnalyzedStatement statement1 =
       statement.nestedStatements().get(0);
   assertThat(statement1.assignments().size(), is(1));
   Symbol value = statement1.assignments().entrySet().iterator().next().getValue();
   assertThat(value, isReference("name"));
 }
Exemplo n.º 3
0
 @Test
 public void testTestUpdateOnTableWithAliasAndFQColumnNameInWhereClause() throws Exception {
   UpdateAnalyzedStatement statement =
       analyze("update users  t set name = 'foo' where t.name != 'foo'");
   Function eqFunction =
       (Function)
           ((Function) statement.nestedStatements().get(0).whereClause().query())
               .arguments()
               .get(0);
   assertThat(eqFunction.arguments().get(0), isReference("name"));
 }
Exemplo n.º 4
0
 @Test
 public void testUsingFQColumnNameShouldBePossibleInWhereClause() throws Exception {
   UpdateAnalyzedStatement statement =
       analyze("update users set name = 'foo' where users.name != 'foo'");
   Function eqFunction =
       (Function)
           ((Function) statement.nestedStatements().get(0).whereClause().query())
               .arguments()
               .get(0);
   assertThat(eqFunction.arguments().get(0), isReference("name"));
 }
Exemplo n.º 5
0
  @Test
  public void testUpdateAssignments() throws Exception {
    UpdateAnalyzedStatement statement = analyze("update users set name='Trillian'");
    UpdateAnalyzedStatement.NestedAnalyzedStatement statement1 =
        statement.nestedStatements().get(0);
    assertThat(statement1.assignments().size(), is(1));
    assertThat(
        ((DocTableRelation) statement.sourceRelation()).tableInfo().ident(),
        is(new TableIdent(Schemas.DEFAULT_SCHEMA_NAME, "users")));

    Reference ref = statement1.assignments().keySet().iterator().next();
    assertThat(ref.info().ident().tableIdent().name(), is("users"));
    assertThat(ref.info().ident().columnIdent().name(), is("name"));
    assertTrue(statement1.assignments().containsKey(ref));

    Symbol value = statement1.assignments().entrySet().iterator().next().getValue();
    assertThat(value, isLiteral("Trillian"));
  }