alterColumnSql

Add usage example, expand description of new table requirement

See Also

Column Attributes Reference

Syntax
array alterColumnSql(
    string $tableName,
    string $columnData,
    optional string $tableFields='',
    optional string $tableOptions=''
    )

Description

The method alterColumnSql() creates the SQL statement necessary to modify an existing column on an existing table, given by $tableName, with the attributes specified in the string $columnData. The column must already exist in the specified table.

The information specified in the $columnData string must conform to the Column Attributes standard.

Limitations

Based on the database and column type, it may not be possible to modify the column to requested settings without prior action. The optional tableFields and tableOptions may help this by effectively:

Some of the qualifying events that may require this action are:

In order to actually modify the column, the returned array must be passed to the executeSqlArray() method.

Usage

/*
 * create a data dictionary object, using this connection
 */
$dict = NewDataDictionary($db);
 
 
$table = 'lctable';
$flds = 'col6 C(50)';
 
$sql = $dict->alterColumnSql($table,$flds);
/*
 * Sql looks like:
 *  ALTER TABLE "lctable" ALTER COLUMN "col6" SET DATA TYPE VARCHAR(50)
 */
 
/*
 * Complete the process by executing the statement
*/
$db->startTrans();
$dict->executeSqlArray($sql);
$db->completeTrans();