Search in sources :

Example 6 with AlterExpression

use of net.sf.jsqlparser.statement.alter.AlterExpression in project JSqlParser by JSQLParser.

the class AlterTest method testAlterTableAddColumn.

public void testAlterTableAddColumn() throws JSQLParserException {
    Statement stmt = CCJSqlParserUtil.parse("ALTER TABLE mytable ADD COLUMN mycolumn varchar (255)");
    assertTrue(stmt instanceof Alter);
    Alter alter = (Alter) stmt;
    assertEquals("mytable", alter.getTable().getFullyQualifiedName());
    AlterExpression alterExp = alter.getAlterExpressions().get(0);
    assertNotNull(alterExp);
    List<ColumnDataType> colDataTypes = alterExp.getColDataTypeList();
    assertEquals("mycolumn", colDataTypes.get(0).getColumnName());
    assertEquals("varchar (255)", colDataTypes.get(0).getColDataType().toString());
}
Also used : Alter(net.sf.jsqlparser.statement.alter.Alter) Statement(net.sf.jsqlparser.statement.Statement) ColumnDataType(net.sf.jsqlparser.statement.alter.AlterExpression.ColumnDataType) AlterExpression(net.sf.jsqlparser.statement.alter.AlterExpression)

Example 7 with AlterExpression

use of net.sf.jsqlparser.statement.alter.AlterExpression in project JSqlParser by JSQLParser.

the class AlterTest method testAlterTableAddColumn5.

public void testAlterTableAddColumn5() throws JSQLParserException {
    Statement stmt = CCJSqlParserUtil.parse("ALTER TABLE mytable ADD col1 timestamp (3)");
    // COLUMN keyword appears in deparsed statement
    assertStatementCanBeDeparsedAs(stmt, "ALTER TABLE mytable ADD COLUMN col1 timestamp (3)");
    Alter alter = (Alter) stmt;
    List<AlterExpression> alterExps = alter.getAlterExpressions();
    AlterExpression col1Exp = alterExps.get(0);
    List<ColumnDataType> col1DataTypes = col1Exp.getColDataTypeList();
    assertEquals("col1", col1DataTypes.get(0).getColumnName());
    assertEquals("timestamp (3)", col1DataTypes.get(0).getColDataType().toString());
}
Also used : Alter(net.sf.jsqlparser.statement.alter.Alter) Statement(net.sf.jsqlparser.statement.Statement) ColumnDataType(net.sf.jsqlparser.statement.alter.AlterExpression.ColumnDataType) AlterExpression(net.sf.jsqlparser.statement.alter.AlterExpression)

Example 8 with AlterExpression

use of net.sf.jsqlparser.statement.alter.AlterExpression in project JSqlParser by JSQLParser.

the class AlterTest method testAlterTableDropColumn2.

public void testAlterTableDropColumn2() throws JSQLParserException {
    assertSqlCanBeParsedAndDeparsed("ALTER TABLE mytable DROP COLUMN col1, DROP COLUMN col2");
    Statement stmt = CCJSqlParserUtil.parse("ALTER TABLE mytable DROP COLUMN col1, DROP COLUMN col2");
    Alter alter = (Alter) stmt;
    List<AlterExpression> alterExps = alter.getAlterExpressions();
    AlterExpression col1Exp = alterExps.get(0);
    AlterExpression col2Exp = alterExps.get(1);
    assertEquals("col1", col1Exp.getColumnName());
    assertEquals("col2", col2Exp.getColumnName());
}
Also used : Alter(net.sf.jsqlparser.statement.alter.Alter) Statement(net.sf.jsqlparser.statement.Statement) AlterExpression(net.sf.jsqlparser.statement.alter.AlterExpression)

Example 9 with AlterExpression

use of net.sf.jsqlparser.statement.alter.AlterExpression in project JSqlParser by JSQLParser.

the class AlterTest method testAlterTableAddColumn6.

public void testAlterTableAddColumn6() throws JSQLParserException {
    final String sql = "ALTER TABLE mytable ADD COLUMN col1 timestamp (3) not null";
    Statement stmt = CCJSqlParserUtil.parse(sql);
    assertStatementCanBeDeparsedAs(stmt, sql);
    Alter alter = (Alter) stmt;
    List<AlterExpression> alterExps = alter.getAlterExpressions();
    AlterExpression col1Exp = alterExps.get(0);
    assertEquals("not", col1Exp.getColDataTypeList().get(0).getColumnSpecs().get(0));
    assertEquals("null", col1Exp.getColDataTypeList().get(0).getColumnSpecs().get(1));
}
Also used : Alter(net.sf.jsqlparser.statement.alter.Alter) Statement(net.sf.jsqlparser.statement.Statement) AlterExpression(net.sf.jsqlparser.statement.alter.AlterExpression)

Example 10 with AlterExpression

use of net.sf.jsqlparser.statement.alter.AlterExpression in project JSqlParser by JSQLParser.

the class AlterTest method testAlterTableFK.

public void testAlterTableFK() throws JSQLParserException {
    String sql = "ALTER TABLE `Novels` ADD FOREIGN KEY (AuthorID) REFERENCES Author (ID)";
    Statement stmt = CCJSqlParserUtil.parse(sql);
    assertStatementCanBeDeparsedAs(stmt, sql);
    AlterExpression alterExpression = ((Alter) stmt).getAlterExpressions().get(0);
    assertEquals(alterExpression.getFkColumns().size(), 1);
    assertEquals(alterExpression.getFkColumns().get(0), "AuthorID");
    assertEquals(alterExpression.getFkSourceTable(), "Author");
    assertEquals(alterExpression.getFkSourceColumns().size(), 1);
    assertEquals(alterExpression.getFkSourceColumns().get(0), "ID");
}
Also used : Statement(net.sf.jsqlparser.statement.Statement) AlterExpression(net.sf.jsqlparser.statement.alter.AlterExpression)

Aggregations

AlterExpression (net.sf.jsqlparser.statement.alter.AlterExpression)12 Statement (net.sf.jsqlparser.statement.Statement)10 Alter (net.sf.jsqlparser.statement.alter.Alter)7 ColumnDataType (net.sf.jsqlparser.statement.alter.AlterExpression.ColumnDataType)5 AbstractIndexManager (herddb.core.AbstractIndexManager)2 TableSpaceManager (herddb.core.TableSpaceManager)2 Column (herddb.model.Column)2 StatementExecutionException (herddb.model.StatementExecutionException)2 Table (herddb.model.Table)2 AlterTableStatement (herddb.model.commands.AlterTableStatement)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Map (java.util.Map)2 ExpressionList (net.sf.jsqlparser.expression.operators.relational.ExpressionList)2 ItemsList (net.sf.jsqlparser.expression.operators.relational.ItemsList)2 MultiExpressionList (net.sf.jsqlparser.expression.operators.relational.MultiExpressionList)2 AlterOperation (net.sf.jsqlparser.statement.alter.AlterOperation)2 CreateTable (net.sf.jsqlparser.statement.create.table.CreateTable)2 AbstractTableManager (herddb.core.AbstractTableManager)1 ColumnsList (herddb.model.ColumnsList)1