use of net.sf.jsqlparser.statement.create.table.ColDataType in project JSqlParser by JSQLParser.
the class DeclareStatementTest method testDeclareTable.
@Test
public void testDeclareTable() throws JSQLParserException {
String statement = "DECLARE @MyTableVar TABLE (EmpID int NOT NULL, OldVacationHours int, NewVacationHours int, ModifiedDate datetime)";
Statement parsed = assertSqlCanBeParsedAndDeparsed(statement);
DeclareStatement created = new DeclareStatement().withUserVariable(new UserVariable("MyTableVar")).withColumnDefinitions(new ArrayList<>()).addColumnDefinitions(new ColumnDefinition("EmpID", new ColDataType().withDataType("int"), asList("NOT", "NULL")), new ColumnDefinition("OldVacationHours", new ColDataType("int"))).addColumnDefinitions(asList(new ColumnDefinition("NewVacationHours", new ColDataType("int")), new ColumnDefinition("ModifiedDate", new ColDataType("datetime")))).withDeclareType(DeclareType.TABLE);
assertDeparse(created, statement);
assertEqualsObjectTree(parsed, created);
}
use of net.sf.jsqlparser.statement.create.table.ColDataType in project JSqlParser by JSQLParser.
the class CreateTableTest method testExcludeWhereConstraint.
@Test
public void testExcludeWhereConstraint() throws JSQLParserException {
String statement = "CREATE TABLE foo (col1 integer, EXCLUDE WHERE (col1 > 100))";
assertSqlCanBeParsedAndDeparsed(statement);
assertDeparse(new CreateTable().withTable(new Table("foo")).addIndexes(new ExcludeConstraint().withExpression(new GreaterThan().withLeftExpression(new Column("col1")).withRightExpression(new LongValue(100)))).addColumnDefinitions(new ColumnDefinition("col1", new ColDataType("integer"))), statement);
}
use of net.sf.jsqlparser.statement.create.table.ColDataType in project JSqlParser by JSQLParser.
the class CreateTableTest method testCreateTableIssue113.
@Test
public void testCreateTableIssue113() throws JSQLParserException {
String statement = "CREATE TABLE foo (reason character varying (255) DEFAULT 'Test' :: character varying NOT NULL)";
assertSqlCanBeParsedAndDeparsed(statement);
assertDeparse(new CreateTable().withTable(new Table().withName("foo")).withColumnDefinitions(Arrays.asList(new ColumnDefinition().withColumnName("reason").withColDataType(new ColDataType().withDataType("character varying").addArgumentsStringList(Arrays.asList("255"))).addColumnSpecs("DEFAULT 'Test' :: character varying", "NOT NULL"))), statement);
}
use of net.sf.jsqlparser.statement.create.table.ColDataType in project canal-utils by wz2cool.
the class BaseAlterSqlConverter method getAddColumnExpressions.
private List<AlterColumnExpression> getAddColumnExpressions(final AlterOperation alterOperation, final String tableName, final List<AlterExpression.ColumnDataType> columnDataTypes) {
List<AlterColumnExpression> result = new ArrayList<>();
if (alterOperation != AlterOperation.ADD || columnDataTypes == null || columnDataTypes.isEmpty()) {
return result;
}
for (AlterExpression.ColumnDataType columnDataType : columnDataTypes) {
AlterColumnExpression addColumnExpression = new AlterColumnExpression();
String columnName = columnDataType.getColumnName();
ColDataType mysqlColDataType = columnDataType.getColDataType();
Optional<ColDataType> covColDataTypeOptional = getColDataTypeConverter().convert(mysqlColDataType);
if (!covColDataTypeOptional.isPresent()) {
String errorMsg = String.format("[Add Column] Cannot convert data type: %s", mysqlColDataType.getDataType());
throw new NotSupportDataTypeException(errorMsg);
}
final boolean unsignedFlag = columnDataType.getColumnSpecs().stream().anyMatch("unsigned"::equalsIgnoreCase);
addColumnExpression.setTableName(cleanText(tableName));
addColumnExpression.setColumnName(cleanText(columnName));
addColumnExpression.setOperation(EnhancedAlterOperation.ADD_COLUMN);
addColumnExpression.setColDataType(covColDataTypeOptional.get());
addColumnExpression.setUnsignedFlag(unsignedFlag);
result.add(addColumnExpression);
}
return result;
}
use of net.sf.jsqlparser.statement.create.table.ColDataType in project canal-utils by wz2cool.
the class Db2AlterSqlConverter method convertToAddColumnSql.
@Override
protected Optional<String> convertToAddColumnSql(AlterColumnExpression alterColumnExpression) {
String tableName = alterColumnExpression.getTableName();
String columnName = alterColumnExpression.getColumnName();
ColDataType colDataType = alterColumnExpression.getColDataType();
String dataTypeString = getDataTypeString(colDataType);
String sql = String.format("ALTER TABLE %s ADD COLUMN %s %s", tableName, columnName, dataTypeString);
return Optional.of(sql);
}
Aggregations