Package net.sf.jsqlparser.statement.replace

Examples of net.sf.jsqlparser.statement.replace.Replace


                {if (true) return update;}
    throw new Error("Missing return statement in function");
  }

  final public Replace Replace() throws ParseException {
        Replace replace = new Replace();
        Table table = null;
        Column tableColumn = null;
        Expression value = null;

        List columns = new ArrayList();
        List expList = new ArrayList();
        ItemsList itemsList = null;
        Expression exp = null;
    jj_consume_token(K_REPLACE);
    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
    case K_INTO:
      jj_consume_token(K_INTO);
      break;
    default:
      jj_la1[4] = jj_gen;
      ;
    }
    table = Table();
    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
    case K_SET:
      jj_consume_token(K_SET);
      tableColumn = Column();
      jj_consume_token(77);
      value = SimpleExpression();
                                                                                columns.add(tableColumn); expList.add(value);
      label_2:
      while (true) {
        switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
        case 78:
          ;
          break;
        default:
          jj_la1[5] = jj_gen;
          break label_2;
        }
        jj_consume_token(78);
        tableColumn = Column();
        jj_consume_token(77);
        value = SimpleExpression();
                                                                                   columns.add(tableColumn); expList.add(value);
      }
                                replace.setExpressions(expList);
      break;
    case K_SELECT:
    case K_VALUES:
    case 79:
      if (jj_2_1(2)) {
        jj_consume_token(79);
        tableColumn = Column();
                                                              columns.add(tableColumn);
        label_3:
        while (true) {
          switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
          case 78:
            ;
            break;
          default:
            jj_la1[6] = jj_gen;
            break label_3;
          }
          jj_consume_token(78);
          tableColumn = Column();
                                                                                                                      columns.add(tableColumn);
        }
        jj_consume_token(80);
      } else {
        ;
      }
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case K_VALUES:
        jj_consume_token(K_VALUES);
        jj_consume_token(79);
        exp = PrimaryExpression();
                                                                          expList.add(exp);
        label_4:
        while (true) {
          switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
          case 78:
            ;
            break;
          default:
            jj_la1[7] = jj_gen;
            break label_4;
          }
          jj_consume_token(78);
          exp = PrimaryExpression();
                                                                                expList.add(exp);
        }
        jj_consume_token(80);
                                                                                                             itemsList = new ExpressionList(expList);
        break;
      case K_SELECT:
      case 79:
                                          replace.setUseValues(false);
        itemsList = SubSelect();
        break;
      default:
        jj_la1[8] = jj_gen;
        jj_consume_token(-1);
        throw new ParseException();
      }
                                replace.setItemsList(itemsList);
      break;
    default:
      jj_la1[9] = jj_gen;
      jj_consume_token(-1);
      throw new ParseException();
    }
                if (columns.size() > 0)
                        replace.setColumns(columns);
                replace.setTable(table);
                {if (true) return replace;}
    throw new Error("Missing return statement in function");
  }
View Full Code Here


    @Test
  public void testGetTableListFromReplace() throws Exception {
    String sql = "REPLACE INTO MY_TABLE1 (a) VALUES ((SELECT a from MY_TABLE2 WHERE a = 1))";
    net.sf.jsqlparser.statement.Statement statement = pm.parse(new StringReader(sql));

    Replace replaceStatement = (Replace) statement;
    TablesNamesFinder tablesNamesFinder = new TablesNamesFinder();
    List<String> tableList = tablesNamesFinder.getTableList(replaceStatement);
    assertEquals(2, tableList.size());
    assertTrue(tableList.contains("MY_TABLE1"));
    assertTrue(tableList.contains("MY_TABLE2"));
View Full Code Here


    @Test
  public void testReplaceSyntax1() throws JSQLParserException {
    String statement = "REPLACE mytable SET col1='as', col2=?, col3=565";
    Replace replace = (Replace) parserManager.parse(new StringReader(statement));
    assertEquals("mytable", replace.getTable().getName());
    assertEquals(3, replace.getColumns().size());
    assertEquals("col1", ((Column) replace.getColumns().get(0)).getColumnName());
    assertEquals("col2", ((Column) replace.getColumns().get(1)).getColumnName());
    assertEquals("col3", ((Column) replace.getColumns().get(2)).getColumnName());
    assertEquals("as", ((StringValue) replace.getExpressions().get(0)).getValue());
    assertTrue(replace.getExpressions().get(1) instanceof JdbcParameter);
    assertEquals(565, ((LongValue) replace.getExpressions().get(2)).getValue());
    assertEquals(statement, "" + replace);

  }
View Full Code Here

  }

    @Test
  public void testReplaceSyntax2() throws JSQLParserException {
    String statement = "REPLACE mytable (col1, col2, col3) VALUES ('as', ?, 565)";
    Replace replace = (Replace) parserManager.parse(new StringReader(statement));
    assertEquals("mytable", replace.getTable().getName());
    assertEquals(3, replace.getColumns().size());
    assertEquals("col1", ((Column) replace.getColumns().get(0)).getColumnName());
    assertEquals("col2", ((Column) replace.getColumns().get(1)).getColumnName());
    assertEquals("col3", ((Column) replace.getColumns().get(2)).getColumnName());
    assertEquals("as", ((StringValue) ((ExpressionList) replace.getItemsList()).getExpressions().get(0)).getValue());
    assertTrue(((ExpressionList) replace.getItemsList()).getExpressions().get(1) instanceof JdbcParameter);
    assertEquals(565, ((LongValue) ((ExpressionList) replace.getItemsList()).getExpressions().get(2)).getValue());
    assertEquals(statement, "" + replace);
  }
View Full Code Here

  }

    @Test
  public void testReplaceSyntax3() throws JSQLParserException {
    String statement = "REPLACE mytable (col1, col2, col3) SELECT * FROM mytable3";
    Replace replace = (Replace) parserManager.parse(new StringReader(statement));
    assertEquals("mytable", replace.getTable().getName());
    assertEquals(3, replace.getColumns().size());
    assertEquals("col1", ((Column) replace.getColumns().get(0)).getColumnName());
    assertEquals("col2", ((Column) replace.getColumns().get(1)).getColumnName());
    assertEquals("col3", ((Column) replace.getColumns().get(2)).getColumnName());
    assertTrue(replace.getItemsList() instanceof SubSelect);
    // TODO:
    // assertEquals(statement, ""+replace);
  }
View Full Code Here

TOP

Related Classes of net.sf.jsqlparser.statement.replace.Replace

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.