Search in sources :

Example 6 with Replace

use of net.sf.jsqlparser.statement.replace.Replace in project JSqlParser by JSQLParser.

the class ReplaceTest method testReplaceSyntax2.

@Test
public void testReplaceSyntax2() throws JSQLParserException {
    String statement = "REPLACE mytable (col1, col2, col3) VALUES ('as', ?, 565)";
    Replace replace = (Replace) PARSER_MANAGER.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);
}
Also used : Replace(net.sf.jsqlparser.statement.replace.Replace) JdbcParameter(net.sf.jsqlparser.expression.JdbcParameter) StringReader(java.io.StringReader) Test(org.junit.Test)

Aggregations

Replace (net.sf.jsqlparser.statement.replace.Replace)6 Test (org.junit.Test)6 StringReader (java.io.StringReader)4 JdbcParameter (net.sf.jsqlparser.expression.JdbcParameter)2 Table (net.sf.jsqlparser.schema.Table)2 ArrayList (java.util.ArrayList)1 Expression (net.sf.jsqlparser.expression.Expression)1 ItemsList (net.sf.jsqlparser.expression.operators.relational.ItemsList)1 Column (net.sf.jsqlparser.schema.Column)1 Statement (net.sf.jsqlparser.statement.Statement)1 SubSelect (net.sf.jsqlparser.statement.select.SubSelect)1 CCJSqlParserManagerTest (net.sf.jsqlparser.test.simpleparsing.CCJSqlParserManagerTest)1