You are here

function uc_usps_update_2 in Ubercart 6.2

Same name and namespace in other branches
  1. 5 shipping/uc_usps/uc_usps.install \uc_usps_update_2()

File

shipping/uc_usps/uc_usps.install, line 110
Install hooks for uc_usps.module.

Code

function uc_usps_update_2() {
  $ret = array();
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      $ret[] = update_sql("ALTER TABLE {uc_usps_products} ADD COLUMN vid mediumint(9) unsigned NOT NULL default 0 FIRST");
      $ret[] = update_sql("ALTER TABLE {uc_usps_products} DROP INDEX nid");
      $result = db_query("SELECT nid, vid FROM {node}");
      while ($product = db_fetch_object($result)) {
        db_query("UPDATE {uc_usps_products} SET vid = %d WHERE nid = %d", $product->vid, $product->nid);
      }
      $ret[] = update_sql("ALTER TABLE {uc_usps_products} ADD PRIMARY KEY (vid)");
      break;
    case 'pgsql':
      db_add_column($ret, 'uc_usps_products', 'vid', 'integer unsigned', array(
        'not null' => TRUE,
        'default' => 0,
      ));
      $ret[] = update_sql("ALTER TABLE {uc_usps_products} DROP CONSTRAINT {uc_usps_products}_nid_key");
      $result = db_query("SELECT nid, vid FROM {node}");
      while ($product = db_fetch_object($result)) {
        db_query("UPDATE {uc_usps_products} SET vid = %d WHERE nid = %d", $product->vid, $product->nid);
      }
      $ret[] = update_sql("ALTER TABLE {uc_usps_products} ADD PRIMARY KEY (vid)");
      break;
  }
  return $ret;
}