function build_coldef($idx, $mode = 'create')
{
    global $s_coldefs;
    if (!isset($s_coldefs[$idx]['name'])) {
        return '';
    }
    $sql = "\t" . $s_coldefs[$idx]['name'] . "\t";
    if (isset($s_coldefs[$idx]['domain']) && $s_coldefs[$idx]['domain'] != '') {
        $sql .= $s_coldefs[$idx]['domain'];
    } elseif (isset($s_coldefs[$idx]['comp']) && $s_coldefs[$idx]['comp'] != '') {
        $sql .= 'COMPUTED BY (' . $s_coldefs[$idx]['comp'] . ')';
    } elseif (isset($s_coldefs[$idx]['type'])) {
        $sql .= build_datatype($s_coldefs[$idx], 'column', $mode);
    } else {
        return '';
    }
    if (isset($s_coldefs[$idx]['default']) && $s_coldefs[$idx]['default'] != '') {
        $sql .= " DEFAULT " . $s_coldefs[$idx]['default'];
    }
    if (isset($s_coldefs[$idx]['notnull']) && $s_coldefs[$idx]['notnull'] != '') {
        $sql .= ' NOT NULL';
    }
    if (isset($s_coldefs[$idx]['unique']) && $s_coldefs[$idx]['unique'] != '') {
        $sql .= ' UNIQUE';
    }
    if (isset($s_coldefs[$idx]['check']) && $s_coldefs[$idx]['check'] != '') {
        $sql .= ' CHECK (' . $s_coldefs[$idx]['check'] . ')';
    }
    if ('alter' == $mode && isset($s_coldefs[$idx]['primary'])) {
        $sql .= ' PRIMARY KEY';
    }
    if (isset($s_coldefs[$idx]['fk_table']) && $s_coldefs[$idx]['fk_table'] != '') {
        if (isset($s_coldefs[$idx]['fk_name']) && $s_coldefs[$idx]['fk_name'] != '') {
            $sql .= ' CONSTRAINT ' . $s_coldefs[$idx]['fk_name'];
        }
        $sql .= ' REFERENCES ' . $s_coldefs[$idx]['fk_table'];
        if (isset($s_coldefs[$idx]['fk_column']) && $s_coldefs[$idx]['fk_column'] != '') {
            $sql .= ' (' . $s_coldefs[$idx]['fk_column'] . ')';
        }
        if (isset($s_coldefs[$idx]['on_update']) && $s_coldefs[$idx]['on_update'] != '') {
            $sql .= ' ON UPDATE ' . $s_coldefs[$idx]['on_update'];
        }
        if (isset($s_coldefs[$idx]['on_delete']) && $s_coldefs[$idx]['on_delete'] != '') {
            $sql .= ' ON DELETE ' . $s_coldefs[$idx]['on_delete'];
        }
    }
    if (isset($s_coldefs[$idx]['collate']) && $s_coldefs[$idx]['collate'] != '') {
        $sql .= ' COLLATE ' . $s_coldefs[$idx]['collate'];
    }
    return $sql;
}
function modify_domain($olddef, $domdef)
{
    global $dbhandle, $ib_error;
    $lsql = array();
    if ($domdef['name'] != $olddef['name']) {
        $lsql[] = 'ALTER DOMAIN ' . $olddef['name'] . ' TO ' . $domdef['name'];
    }
    if (datatype_is_modified($olddef, $domdef)) {
        $lsql[] = 'ALTER DOMAIN ' . $domdef['name'] . ' TYPE ' . build_datatype($domdef);
    }
    if (isset($olddef['default']) && $olddef['default'] != '' && $domdef['default'] == '') {
        $lsql[] = 'ALTER DOMAIN ' . $domdef['name'] . ' DROP DEFAULT';
    }
    if (isset($olddef['default']) && $domdef['default'] != '' && $olddef['default'] != $domdef['default']) {
        $lsql[] = 'ALTER DOMAIN ' . $domdef['name'] . ' SET DEFAULT ' . $domdef['default'];
    }
    if (isset($olddef['check']) && !empty($olddef['check']) && (empty($domdef['check']) || $olddef['check'] != $domdef['check'])) {
        $lsql[] = 'ALTER DOMAIN ' . $domdef['name'] . ' DROP CONSTRAINT';
    }
    if (isset($olddef['check']) && $olddef['check'] != $domdef['check']) {
        $lsql[] = 'ALTER DOMAIN ' . $domdef['name'] . ' ADD CHECK ' . $domdef['check'];
    }
    foreach ($lsql as $sql) {
        if (DEBUG) {
            add_debug($sql, __FILE__, __LINE__);
        }
        if (!@fbird_query($dbhandle, $sql)) {
            $ib_error = fbird_errmsg() . "<br>\n>";
            return FALSE;
        }
    }
    return TRUE;
}
function procedure_return_list($out)
{
    if (count($out) == 0) {
        return '';
    }
    $list = 'RETURNS (';
    foreach ($out as $parameter) {
        $list .= $parameter['name'] . ' ' . build_datatype($parameter) . ', ';
    }
    $list = substr($list, 0, -2) . ")\n";
    return $list;
}
        $s_coldefs['mod']['pk_del'] = $s_coldefs['mod']['fk_del'] = $s_coldefs['mod']['uq_del'] = FALSE;
        $col_mod_flag = TRUE;
        $js_stack .= js_request_table_columns();
    }
}
//
// altering the column definitions
//
if (isset($_POST['tb_modcol_doit'])) {
    $mod_flag = FALSE;
    $sql = 'ALTER TABLE ' . $s_modify_name . ' ';
    save_coldef('mod');
    if (!isset($s_coldefs['mod']['domain']) || $s_coldefs['mod']['domain'] != 'Yes') {
        if (datatype_is_modified($s_coldefs['old'], $s_coldefs['mod'])) {
            // build sql for altering datatype definition
            $sql .= 'ALTER ' . $s_modify_col . ' TYPE ' . build_datatype($s_coldefs['mod']) . ', ';
            $mod_flag = TRUE;
        }
        // the delete primary key checkbox is checked
        if ($s_coldefs['mod']['pk_del'] == TRUE) {
            $sql .= 'DROP CONSTRAINT ' . $s_coldefs['old']['primary'] . ', ';
            $mod_flag = TRUE;
        }
        // the delete foreign key checkbox is checked
        if ($s_coldefs['mod']['fk_del'] == TRUE) {
            $sql .= 'DROP CONSTRAINT ' . $s_coldefs['old']['fk_name'] . ', ';
            $mod_flag = TRUE;
        }
        // the delete unique constraint checkbox is checked
        if ($s_coldefs['mod']['uq_del'] == TRUE) {
            $sql .= 'DROP CONSTRAINT ' . $s_coldefs['old']['unique'] . ', ';