book review not working with prefix tables

daco - July 31, 2007 - 06:18
Project:Book Review
Version:5.x-1.x-dev
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:active
Description

I installed the module on drupal 5.2 with dev1_ as prefix. The bookreview.install didn't create the tables with the prefix.
I replaced CREATE TABLE bookreview_links with CREATE TABLE {bookreview_links} and the same with every table. Now it creates the right tables.
Also added the uninstall function post here: http://drupal.org/node/145270

Rename the attached file removing .txt extension

the code:

<?php
// $Id: bookreview.install,v 1.1 2006/06/15 14:32:33 jeremy Exp $

/**
* Implementation of hook_install()
*/
function bookreview_install() {
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      db_query("CREATE TABLE {bookreview} (
                  nid int(10) unsigned NOT NULL,
                  booktitle varchar(255) NOT NULL default '',
                  cover varchar(255) NOT NULL default '',
                  publisher varchar(255) NOT NULL default '',
                  copyright varchar(255) NOT NULL default 0,
                  isbn varchar(255) NOT NULL default '',
  price varchar(255) NOT NULL default '',
  pages varchar(255) NOT NULL default 0,
  rating int(1) NOT NULL default 0,
  synopsis text,
  contents text,
  review text,
  PRIMARY KEY (nid),
  KEY (booktitle)
                );");

      db_query("CREATE TABLE {bookreview_links} (
                  lid int(10) unsigned NOT NULL auto_increment,
                  nid int(10) unsigned NOT NULL,
                  booklink varchar(255) NOT NULL default '',
                  description varchar(255) NOT NULL default '',
                  weight tinyint DEFAULT '0',
                  KEY (lid),
                  KEY (nid)
                );");

      db_query("CREATE TABLE {bookreview_authors} (
                  aid int(10) unsigned NOT NULL auto_increment,
                  nid int(10) unsigned NOT NULL,
                  author varchar(255) NOT NULL default '',
                  weight tinyint DEFAULT '0',
                  KEY (aid),
                  KEY (nid)
                );");
      break;
    case 'pgsql':
      db_query("CREATE TABLE {bookreview} (
                  nid integer NOT NULL,
                  booktitle varchar(255) NOT NULL default '',
                  cover varchar(255) NOT NULL default '',
                  publisher varchar(255) NOT NULL default '',
                  copyright varchar(255) NOT NULL default '',
                  isbn varchar(255) NOT NULL default '',
                  price varchar(255) NOT NULL default '',
                  pages varchar(255) NOT NULL default '',
                  rating integer NOT NULL default 0,
                  synopsis text,
  contents text,
  review text,
  PRIMARY KEY (nid)
);");
      db_query("CREATE index {bookreview_booktitle} on bookreview (booktitle);");

      db_query("CREATE TABLE {bookreview_links} (
  lid serial NOT NULL,
  nid integer NOT NULL,
  booklink varchar(255) NOT NULL default '',
  description varchar(255) NOT NULL default '',
  weight smallint DEFAULT '0'
);");
      db_query("CREATE index {bookreview_links}_lid on bookreview_links (lid);");
      db_query("CREATE index {bookreview_links}_nid on bookreview_links (nid);");

      db_query("CREATE TABLE {bookreview_authors} (
  aid serial NOT NULL,
  nid integer NOT NULL,
  author varchar(255) NOT NULL default '',
  weight smallint DEFAULT '0');");
      db_query("CREATE index {bookreview_authors}_aid on bookreview_authors (aid);");
      db_query("CREATE index {bookreview_authors}_nid on bookreview_authors (nid);");
      break;
  }
  drupal_set_message(t('All tables required by the bookreview module have been created.'));
}
/**
* Implementation of hook_uninstall().
*/
function bookreview_uninstall() {
db_query('DROP TABLE {bookreview}');
db_query('DROP TABLE {bookreview_links}');
db_query('DROP TABLE {bookreview_authors}');
}

AttachmentSize
book.install.txt1.08 KB

#1

smartango - August 9, 2007 - 13:20

uninstall hook should remove setted variables too

function bookreview_uninstall() {
  global $db_type;
  db_query('DROP TABLE {bookreview}');
  db_query('DROP TABLE {bookreview_links}');
  db_query('DROP TABLE {bookreview_authors}');
  variable_del('bookreview_store_blocktitle');
  variable_del('bookreview_store_snippet');
}

 
 

Drupal is a registered trademark of Dries Buytaert.