By haiidi on
Hii
i write a module wich manage products, i have to cretae 3 tables in my file.install
when i enable my module there is no errors but those tables are not created!!
this is my code:
<?php
function iprog_install(){
switch($GLOBALS['db_type']){
case 'mysql':
case 'mysqli':
db_query("CREATE TABLE {categorie} (
id_cat int(11) NOT NULL AUTO_INCREMENT,
cat_supp text NOT NULL,
cat_inf text NOT NULL,
ordre int(11) NOT NULL,
description text NOT NULL,
PRIMARY KEY (id_cat)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;");
db_query("CREATE TABLE {programme} (
id_prog int(11) NOT NULL AUTO_INCREMENT,
num_ref int(11) not null,
titre text NOT NULL,
categorie text NOT NULL,
type text NOT NULL,
desc text ,
description text ,
emplacement text ,
residence text ,
architecture text ,
promoteur text ,
garanties text ,
plus_local text,
plus_produits text,
plus_prestations text,
rue text not null,
numero int(11) not null,
code_postal int(11) not null,
ville text not null,
region text not null,
carte_map text not null,
departement text not null,
pays text not null,
situation text not null,
proximité bool,
plan_acces text,
date_livraison date,
passage_actes date,
per_obtenu text,
type text,
locatif bool,
duree_bail text,
date_bail date,
freq_loyer text,
indexation text,
nbre_tot_lots int(11),
nbre_lots_dispo int(11),
nbre_lots_opt int(11),
permis_purge bool,
prop_classique bool,
date_paiment date,
gestionnaire text,
notaire text,
resp_prog text,
lois text,
prix_foncier_min float,
prix_max float,
frais_gerance float,
charges float,
rentabilite float,
tva bool,
taux float,
comission float,
PRIMARY KEY (id_prog)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;");
db_query("CREATE TABLE {departement} (
id_dept int(11) NOT NULL AUTO_INCREMENT,
nonD text NOT NULL,
ordre text NOT NULL,
description text NOT NULL,
situation text NOT NULL,
tourisme text NOT NULL,
PRIMARY KEY (id_dept)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;");
break;
case 'pgsql':
db_query("CREATE TABLE {categorie} (
id_cat int(11) NOT NULL AUTO_INCREMENT,
cat_supp text NOT NULL,
cat_inf text NOT NULL,
ordre int(11) NOT NULL,
description text NOT NULL
PRIMARY KEY (id_cat)
) ;");
db_query(" CREATE INDEX {categorie}_id_ix on {categorie} (id_cat);");
db_query("CREATE TABLE {programme} (
id_prog int(11) NOT NULL AUTO_INCREMENT,
num_ref int(11) not null,
titre text NOT NULL,
categorie text NOT NULL,
type text NOT NULL,
desc text ,
description text ,
emplacement text ,
residence text ,
architecture text ,
promoteur text ,
garanties text ,
plus_local text,
plus_produits text,
plus_prestations text,
rue text not null,
numero int(11) not null,
code_postal int(11) not null,
ville text not null,
region text not null,
carte_map text not null,
departement text not null,
pays text not null,
situation text not null,
proximité bool,
plan_acces text,
date_livraison date,
passage_actes date,
per_obtenu text,
type text,
locatif bool,
duree_bail text,
date_bail date,
freq_loyer text,
indexation text,
nbre_tot_lots int(11),
nbre_lots_dispo int(11),
nbre_lots_opt int(11),
permis_purge bool,
prop_classique bool,
date_paiment date,
gestionnaire text,
notaire text,
resp_prog text,
lois text,
prix_foncier_min float,
prix_max float,
frais_gerance float,
charges float,
rentabilite float,
tva bool,
taux float,
comission float,
PRIMARY KEY (id_prog)
) ;");
db_query(" CREATE INDEX {programme}_id_ix on {programme} (id_prog);");
db_query("CREATE TABLE {departement} (
id_dept int(11) NOT NULL AUTO_INCREMENT,
nonD text NOT NULL,
ordre text NOT NULL,
description text NOT NULL,
situation text NOT NULL,
tourisme text NOT NULL,
PRIMARY KEY (id_dept)
) ;");
db_query(" CREATE INDEX {departement}_id_ix on {departement} (id_dept);");
}
}
function iprog_uninstall(){
switch($GLOBALS['db_type']){
case 'mysql':
case 'mysqli':
db_query("drop table {categorie}");
db_query("drop table {programme}");
db_query("drop table {departement}");
break;
case 'pgsql':
db_query("drop table {categorie}");
db_query("drop table {programme}");
db_query("drop table {departement}");
break;
}
}
?>
please help me! i have to show this work tommorow!!
thanks
Comments
First off, you are creating
First off, you are creating your tables the entirely wrong way. You should be using the schema API to define your tables, and let Drupal create them, rather than calling the query on your own through db_query().
But as to your problem, disable your module, then click on the uninstall tab. Uninstall your module (ignore the errors that come up after this) and re-install your module.
Contact me to contract me for D7 -> D10/11 migrations.
how can i
thank you for your answer!
i followed the procedure mentioned (uninstall/install) but only the third table was created!!
could you please explain to me how can i use the schema API, i am newbie to drupal and i didin't know how to dill with!
http://drupal.org/developing/
http://drupal.org/developing/api/schema
Contact me to contract me for D7 -> D10/11 migrations.
thanks
thanks a lot! it help me a lot!
http://drupal.org/project/schema
use this module can automatic get the code
http://drupal.org/project/schema