i'm learning to write a module for a ubercart shipping. I try to refer the flatrate module because of its simply. First look of the code, the uc_flatrate.install, what is the function of this file? what is the function of hook_schema? The following is the code:

/**
* Implements hook_schema().
*/
function uc_flatrate_schema() {
  $schema = array();

  $schema['uc_flatrate_products'] = array(
    'description' => 'Stores product information for quantity-based shipping quotes methods.',
    'fields' => array(
      'vid' => array(
        'description' => 'The {uc_products}.vid.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'nid' => array(
        'description' => 'The {uc_products}.nid.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'mid' => array(
        'description' => 'The {uc_flatrate_methods}.mid.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'rate' => array(
        'description' => 'The rate multiplier, in the store default currency, per each of this product in the shipment.',
        'type' => 'numeric',
        'precision' => 16,
        'scale' => 5,
        'not null' => FALSE,
      ),
    ),
    'primary key' => array('vid', 'mid'),
    'foreign keys' => array(
      'nid' => array('uc_products' => 'nid'),
      'vid' => array('uc_products' => 'vid'),
      'mid' => array('uc_flatrate_methods' => 'mid'),
    ),
  );

  $schema['uc_flatrate_methods'] = array(
    'description' => 'Stores quantity-based shipping quotes method information.',
    'fields' => array(
      'mid' => array(
        'description' => 'Primary key: The shipping quote method ID.',
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'title' => array(
        'description' => 'The method title, displayed on administration pages.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'label' => array(
        'description' => 'The user-facing label of the shipping method.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'base_rate' => array(
        'description' => 'The amount of shipping cost before product quantity is applied.',
        'type' => 'numeric',
        'precision' => 16,
        'scale' => 5,
        'not null' => TRUE,
        'default' => 0.0,
      ),
      'product_rate' => array(
        'description' => 'The default rate multiplier, in the store default currency, per product in the shipment.',
        'type' => 'numeric',
        'precision' => 16,
        'scale' => 5,
        'not null' => TRUE,
        'default' => 0.0,
      ),
    ),
    'primary key' => array('mid'),
  );

  return $schema;
}

/**
* Implements hook_update_last_removed().
*/
function uc_flatrate_update_last_removed() {
  return 6003;
}

Comments

Defines the database tables

Get a book, and use google to supplement your studying of modules -- that's what I recommend. As for what schema's are:

The most important hook in the [your_module_name].install file is 'hook_schema()', which defines the database tables your module provides.

- Drupal 7 Module Development (pg. 153)

The '.install' file is responsible for writing information into the drupal database. Modules that have the '.install' file is database intensive -- alters data in it's corresponding tables in the database, whereas those that don't usually alters the appearance or alters the interaction of other modules in drupal with it's respective data.

- jmm42