poll.install 2.17 KB
Newer Older
1
<?php
2
// $Id$
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33

function poll_install() {
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      db_query("CREATE TABLE {poll} (
        nid int(10) unsigned NOT NULL default '0',
        runtime int(10) NOT NULL default '0',
        active int(2) unsigned NOT NULL default '0',
        PRIMARY KEY (nid)
      ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");

      db_query("CREATE TABLE {poll_votes} (
        nid int(10) unsigned NOT NULL,
        uid int(10) unsigned NOT NULL default 0,
        chorder int(10) NOT NULL default -1,
        hostname varchar(128) NOT NULL default '',
        INDEX (nid),
        INDEX (uid),
        INDEX (hostname)
      ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");

      db_query("CREATE TABLE {poll_choices} (
        chid int(10) unsigned NOT NULL auto_increment,
        nid int(10) unsigned NOT NULL default '0',
        chtext varchar(128) NOT NULL default '',
        chvotes int(6) NOT NULL default '0',
        chorder int(2) NOT NULL default '0',
        PRIMARY KEY (chid),
        KEY nid (nid)
      ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
34 35
      break;

36 37
    case 'pgsql':
      db_query("CREATE TABLE {poll} (
38
        nid int_unsigned NOT NULL default '0',
39
        runtime int NOT NULL default '0',
40
        active int_unsigned NOT NULL default '0',
41 42 43 44
        PRIMARY KEY (nid)
      )");

      db_query("CREATE TABLE {poll_votes} (
45 46
        nid int_unsigned NOT NULL,
        uid int_unsigned NOT NULL default 0,
47 48 49 50 51 52 53 54 55
        chorder int NOT NULL default -1,
        hostname varchar(128) NOT NULL default ''
      )");
      db_query("CREATE INDEX {poll_votes}_nid_idx ON {poll_votes} (nid)");
      db_query("CREATE INDEX {poll_votes}_uid_idx ON {poll_votes} (uid)");
      db_query("CREATE INDEX {poll_votes}_hostname_idx ON {poll_votes} (hostname)");

      db_query("CREATE TABLE {poll_choices} (
        chid serial CHECK (chid >= 0),
56
        nid int_unsigned NOT NULL default '0',
57 58 59 60 61 62 63
        chtext varchar(128) NOT NULL default '',
        chvotes int NOT NULL default '0',
        chorder int NOT NULL default '0',
        PRIMARY KEY (chid)
      )");
      db_query("CREATE INDEX {poll_choices}_nid_idx ON {poll_choices} (nid)");
      break;
64 65
  }
}