ADOdb

Database Abstraction Layer for PHP

User Tools

Site Tools


v5:dictionary:column_attributes

Dictionary Column Attributes

Description

When creating a column in a table using the dictionary methods, the information provided must confirm to the following specification. Each column created has a number of mandatory and optional parameters.

Basic Syntax

The basic syntax of the attributes is as follows:

  • All the information for the column must occur on a single line.
  • The line ending may be a newline or carriage return/newline combination.
  • Each attribute must be separated by at least one tab or space.
  • The attributes must be specified in the order below
    1. Column Name
    2. Meta Attributes
    3. Optional Arguments
/*
 * Correct syntax
 */
$flds = "
COL1 C(60) NOTNULL DEFAULT 'abc',
COL2 I8 NOTNULL DEFAULT 0
";
 
/*
 * Incorrect syntax
 */
$flds = "
COL1 
C(60) 
NOTNULL 
DEFAULT 'abc',
COL2 
I8 
NOTNULL
DEFAULT 0
";

Attributes

Column Name

  • The column name must conform to any database specific standards related to naming and length.

Meta Attributes

  • The column attributes in terms of type and length must be specified in terms of ADODb metaType descriptions, not the database definition for the type.

Optional Arguments

The following optional arguments may also be assigned to the column, table or key. If the attribute is inappropriate for the operation or column type or not supported by the DBMS, it is ignored.


Usage: Column

AUTO or AUTOINCREMENT

Creates the column as auto-increment. Support for this varies from one database to another. Some databases designate a field with an auto-increment flag as the primary key, and most databases only allow a single column in a table to be designated as auto-increment.


Usage: Index

CONSTRAINT

Adds a constraint to column. The syntax for the constraint must be defined as required by the database.


Usage: Column

DEF or DEFAULT

DEF indicates a default value for a column when a row is created. Some databases also require a field with a default value to be designated as NOT NULL, so that is automatically added to the column string. For dynamically created dates or timestsamps, see the options below.


Usage: Column

DEFDATE

Indicates if the column (metaType D or T) should be defaulted to current date when a column is created. This differs from the DEFTIMESTAMP option below in that it only contains the date portion of a timestamp.


Usage: Column

DEFTIMESTAMP

Indicates if the column (metaType D or T) should be defaulted to current timestamp when a column is created.


Usage: Column

ENUM

In databases that support the ENUM datatype, append a parenthesized, quoted list of enum values

ENUM('lions','tigers','halibut')

Note that you should not place a space between ENUM and the left parenthises (


Usage: Column

INDEX

Creates a single column index using the same name as the column, with 'idx_' prepended to the name, e.g. a column of name column1 will create an index of name idx_column1.


Usage: Any

NOQUOTE

Prevents ADOdb from applying the normal quoting rules to tables, columns and indexes. For example, a column name that contains a special character such as some-column will be automatically quoted to 'some-column'. This tag prevents the behavior.


Usage: Column

NOTNULL

Flags the column so that a NULL value cannot be inserted. For columns that are Auto-Increment or a Primary Key, this option is often implied.


Usage: Column

PRIMARY or KEY

Indicates if the column is part of the Primary Key of the table.


Usage: Column

UNIQUE

UNIQUE is an option against a key and indicates that duplicate values across all columns in the key are not allowed.


Usage: Column

UNSIGNED

Creates an unsigned integer.

v5/dictionary/column_attributes.txt · Last modified: 2016/04/03 01:34 by mnewnham