Search in sources :

Example 11 with AlterExpression

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

the class AlterTest method testAlterTableAddColumn_ColumnKeyWordImplicit.

public void testAlterTableAddColumn_ColumnKeyWordImplicit() throws JSQLParserException {
    Statement stmt = CCJSqlParserUtil.parse("ALTER TABLE mytable ADD 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 12 with AlterExpression

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

the class AlterTest method testAlterTablePK.

public void testAlterTablePK() throws JSQLParserException {
    final String sql = "ALTER TABLE `Author` ADD CONSTRAINT `AuthorPK` PRIMARY KEY (`ID`)";
    Statement stmt = CCJSqlParserUtil.parse(sql);
    assertStatementCanBeDeparsedAs(stmt, sql);
    AlterExpression alterExpression = ((Alter) stmt).getAlterExpressions().get(0);
    assertNull(alterExpression.getConstraintName());
    // TODO: should this pass? ==>        assertEquals(alterExpression.getPkColumns().get(0), "ID");
    assertEquals(alterExpression.getIndex().getColumnsNames().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