<?php
// $Id: locale.install,v 1.7 2006/11/14 06:20:40 drumm Exp $

/**
 * Implementation of hook_install().
 */
function locale_install() {
  // locales_source.source and locales_target.target are not used as binary
  // fields; non-MySQL database servers need to ensure the field type is text
  // and that LIKE produces a case-sensitive comparison.
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      db_query("CREATE TABLE {locales_meta} (
        locale varchar(12) NOT NULL default '',
        name varchar(64) NOT NULL default '',
        enabled int NOT NULL default '0',
        isdefault int NOT NULL default '0',
        plurals int NOT NULL default '0',
        formula varchar(128) NOT NULL default '',
        PRIMARY KEY (locale)
      ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");

      db_query("CREATE TABLE {locales_source} (
        lid int NOT NULL auto_increment,
        location varchar(255) NOT NULL default '',
        source blob NOT NULL,
        PRIMARY KEY (lid),
        KEY source (source(30))
      ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");

      db_query("CREATE TABLE {locales_target} (
        lid int NOT NULL default '0',
        translation blob NOT NULL,
        locale varchar(12) NOT NULL default '',
        plid int NOT NULL default '0',
        plural int NOT NULL default '0',
        KEY lid (lid),
        KEY lang (locale),
        KEY plid (plid),
        KEY plural (plural)
      ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
      break;

    case 'pgsql':
      db_query("CREATE TABLE {locales_meta} (
        locale varchar(12) NOT NULL default '',
        name varchar(64) NOT NULL default '',
        enabled int NOT NULL default '0',
        isdefault int NOT NULL default '0',
        plurals int NOT NULL default '0',
        formula varchar(128) NOT NULL default '',
        PRIMARY KEY (locale)
      )");

      db_query("CREATE TABLE {locales_source} (
        lid serial,
        location varchar(255) NOT NULL default '',
        source text NOT NULL,
        PRIMARY KEY (lid)
      )");

      db_query("CREATE TABLE {locales_target} (
        lid int NOT NULL default '0',
        translation text NOT NULL,
        locale varchar(12) NOT NULL default '',
        plid int NOT NULL default '0',
        plural int NOT NULL default '0'
      )");
      db_query("CREATE INDEX {locales_target}_lid_idx ON {locales_target} (lid)");
      db_query("CREATE INDEX {locales_target}_locale_idx ON {locales_target} (locale)");
      db_query("CREATE INDEX {locales_target}_plid_idx ON {locales_target} (plid)");
      db_query("CREATE INDEX {locales_target}_plural_idx ON {locales_target} (plural)");
      db_query("CREATE INDEX {locales_source}_source_idx ON {locales_source} (source)");
      break;
  }
  db_query("INSERT INTO {locales_meta} (locale, name, enabled, isdefault) VALUES ('en', 'English', '1', '1')");
}

/**
 * Implementation of hook_uninstall().
 */
function locale_uninstall() {
  db_query('DROP TABLE {locales_meta}');
  db_query('DROP TABLE {locales_source}');
  db_query('DROP TABLE {locales_target}');
}
