From 928c55cbc5f3f162c10077f46d75d0bc0b1cbe53 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Thu, 21 Aug 2008 12:46:58 +0000 Subject: further whitespace fixes --- user_guide/database/forge.html | 62 +++++++++++++++++++++--------------------- 1 file changed, 31 insertions(+), 31 deletions(-) (limited to 'user_guide/database/forge.html') diff --git a/user_guide/database/forge.html b/user_guide/database/forge.html index 12ac62f57..bc67436bb 100644 --- a/user_guide/database/forge.html +++ b/user_guide/database/forge.html @@ -116,27 +116,27 @@ already be running, since the forge class relies on it.

Fields are created via an associative array. Within the array you must include a 'type' key that relates to the datatype of the field. For example, INT, VARCHAR, TEXT, etc. Many datatypes (for example VARCHAR) also require a 'constraint' key.

$fields = array(
                        'users' => array(
-                                                  'type' => 'VARCHAR',
-                                                  'constraint' => '100',
-                                           ),
-                 );
-
+                                                  'type' => 'VARCHAR',
+                                                  'constraint' => '100',
+                                           ),
+                 );
+
// will translate to "users VARCHAR(100)" when the field is added.

Additionally, the following key/values can be used:

+
  • unsigned/true : to generate "UNSIGNED" in the field definition.
  • +
  • default/value : to generate a default value in the field definition.
  • +
  • null/true : to generate "NULL" in the field definition. Without this, the field will default to "NOT NULL".
  • +
  • auto_increment/true : generates an auto_increment flag on the field. Note that the field type must be a type that supports this, such as integer.
  • +

    $fields = array(
    -                         'blog_id' => array(
    -                                                  'type' => 'INT',
    -                                                  'constraint' => 5,
    -                                                  'unsigned' => TRUE,
    -                                                  'auto_increment' => TRUE
    -                                           ),
    -                         'blog_title' => array(
    +                         'blog_id' => array(
    +                                                  'type' => 'INT',
    +                                                  'constraint' => 5,
    +                                                  'unsigned' => TRUE,
    +                                                  'auto_increment' => TRUE
    +                                           ),
    +                         'blog_title' => array(
                                                     'type' => 'VARCHAR',
                                                     'constraint' => '100',
                                              ),
    @@ -161,22 +161,22 @@ already be running, since the forge class relies on it.

    Creating an id field

    There is a special exception for creating id fields. A field with type id will automatically be assinged as an INT(9) auto_incrementing Primary Key.

    $this->dbforge->add_field('id');
    - // gives id INT(9) NOT NULL AUTO_INCREMENT

    + // gives id INT(9) NOT NULL AUTO_INCREMENT

    Adding Keys

    Generally speaking, you'll want your table to have Keys. This is accomplished with $this->dbforge->add_key('field'). An optional second parameter set to TRUE will make it a primary key. Note that add_key() must be followed by a call to create_table().

    Multiple column non-primary keys must be sent as an array. Sample output below is for MySQL.

    $this->dbforge->add_key('blog_id', TRUE);
    - // gives PRIMARY KEY `blog_id` (`blog_id`)
    -
    - $this->dbforge->add_key('blog_id', TRUE);
    - $this->dbforge->add_key('site_id', TRUE);
    - // gives PRIMARY KEY `blog_id_site_id` (`blog_id`, `site_id`)
    + // gives PRIMARY KEY `blog_id` (`blog_id`)
    +
    + $this->dbforge->add_key('blog_id', TRUE);
    + $this->dbforge->add_key('site_id', TRUE);
    + // gives PRIMARY KEY `blog_id_site_id` (`blog_id`, `site_id`)

    - $this->dbforge->add_key('blog_name');
    - // gives KEY `blog_name` (`blog_name`)
    -
    - $this->dbforge->add_key(array('blog_name', 'blog_label'));
    - // gives KEY `blog_name_blog_label` (`blog_name`, `blog_label`)

    + $this->dbforge->add_key('blog_name');
    + // gives KEY `blog_name` (`blog_name`)
    +
    + $this->dbforge->add_key(array('blog_name', 'blog_label'));
    + // gives KEY `blog_name_blog_label` (`blog_name`, `blog_label`)

    Creating a table

    After fields and keys have been declared, you can create a new table with

    $this->dbforge->create_table('table_name');
    @@ -196,7 +196,7 @@ already be running, since the forge class relies on it.

    $this->dbforge->add_column()

    The add_column() function is used to modify an existing table. It accepts the same field array as above, and can be used for an unlimited number of additional fields.

    $fields = array(
    -                         'preferences' => array('type' => 'TEXT')
    +                         'preferences' => array('type' => 'TEXT')
    );
    $this->dbforge->add_column('table_name', $fields);

    @@ -213,8 +213,8 @@ $this->dbforge->add_column('table_name', $fields);
                                                    ),
    );
    $this->dbforge->modify_column('table_name', $fields);
    -
    - // gives ALTER TABLE table_name CHANGE old_name new_name TEXT

    +
    + // gives ALTER TABLE table_name CHANGE old_name new_name TEXT

     

    -- cgit v1.2.3-24-g4f1b