Hi bachew,

what you need is a DBScript object and the getDLLScript() method on 
DBDatabaseDriver.

Here's an example how to do it:

// required objects
DBDatabaseDriver driver = db.getDriver();
DBSQLScript script = new DBSQLScript();

// create a new table
DBTable Employees = new Employees(db);
driver.getDDLScript(DBCmdType.CREATE, Employees, script);
script.run(driver, conn, false);

// create a new column (if table already exists)
DBTableColumn myColumn = Employees.addColumn("MyColumn", DataType.TEXT, 50, 
true);
driver.getDDLScript(DBCmdType.CREATE, myColumn, script);
script.run(driver, conn, false);

// drop the column
driver.getDDLScript(DBCmdType.DROP, myColumn, script);
script.run(driver, conn, false);
Employees.getColumns().remove(myColumn); // remove it from the table object!

// drop a table
driver.getDDLScript(DBCmdType.DROP, Employees, script);
script.run(driver, conn, false);
db.getTables().remove(Employees); // remove the table object from the db

I recommend debugging through the advanced sample (SampleAdvApp). 
The method ddlSample() does exactly what you are asking for and performs a data 
model change at runtime.

Regards,
Rainer


bachew wrote:
/ 
/ re: How about drop/alter table and column?
/
/ Hi,
/ I did some quick search in the API, couldn't find API to drop/alter table and 
column. This is important because / some applications might perform data model 
upgrade.
/ Please advise.

Reply via email to