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());
}
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());
}
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());
}
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));
}
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");
}
Aggregations