MYSQL.add_column

MYSQL.add_column — adds a new column to a table.

Syntax

MYSQL.add_column (tablename, column, type, default_val, allow_null)

Arguments

tablename

A string naming the table.

column

A string naming the column to add.

type

A string naming the type of the column. Any legal MySQL type can be named here.

default_value

If non-nil, specifies the default value.

allow_null

nil to disallow NULL in this column, or non-nil to allow NULL.

Returns

On success, nil, or an error on failure.

Description

This method of the MYSQL class adds a new column to an existing table. If the default value is non-nil, then it will be used as the default value for the column. If allow_null is non-nil, then NULL will be allowed in this column.

This method is defined in the Gamma library /usr/cogent/require/MySQLSupport.g. It is made available to a Gamma program with the statement: require("MySQLSupport");.

Example

This example is taken from Section 2.2, “Tutorial 2: create_pets.g”

...

  /* Create the "pets" table, and add columns to it. */
  mysql.create_table("pets");
  mysql.add_column ("pets", "name", "VARCHAR(20)", nil, nil);
  mysql.add_column ("pets", "owner", "VARCHAR(20)", nil, nil);
  mysql.add_column ("pets", "species", "VARCHAR(20)", nil, nil);
  mysql.add_column ("pets", "sex", "CHAR(1)", nil, nil);
  mysql.add_column ("pets", "birth", "DATE", nil, t);
  mysql.add_column ("pets", "death", "DATE", nil, t);

...