dolibarr-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Dolibarr-dev] Ajouter une colonne dans une table existante pour un


From: Laurent Destailleur (aka Eldy)
Subject: Re: [Dolibarr-dev] Ajouter une colonne dans une table existante pour un module
Date: Tue, 24 May 2016 15:19:35 +0200

Si tu as besoin de rajouter une colonne contente toi de faire un 

ALTER TABLE xxx ADD COLUMN yyy...

Avec éventuellement le param du $db->query à 1 si cela se fait avec du code dolibarr et ignore l'erreur en cas d'erreur de type duplicate column ou column alreayd exists.

Le 24 mai 2016 à 10:22, Gilles Lengy <address@hidden> a écrit :

Bonjour,

Nous avons trouvés quelques petits bugs dans nos plugins et nous les corrigeons.

Pour l'un d'entre eux, j'aurais besoin de rajouter une colonne dans une table.

Voici le code qui marche lorsque je le fais depuis phpmyadmin :

DELIMITER $$

DROP PROCEDURE IF EXISTS upgrade_database_1_0_to_1_1 $$
CREATE PROCEDURE upgrade_database_1_0_to_1_1()
BEGIN

-- add a column safely > http://stackoverflow.com/questions/972922/add-column-to-mysql-table-if-it-does-not-exist
IF NOT EXISTS( (SELECT * FROM information_schema.COLUMNS WHERE TABLE_SCHEMA=DATABASE()
        AND COLUMN_NAME='active' AND TABLE_NAME='llx_support_parution_version_parution') ) THEN
    ALTER TABLE llx_support_parution_version_parution ADD active TINYINT(4) NOT NULL DEFAULT 1;
END IF;

END $$

CALL upgrade_database_1_0_to_1_1() $$

DELIMITER ;

Par contre, ce code n'a pas l'air de marcher lorsque je désactive puis réactive le module...

Voici le code du fichier sql :

CREATE TABLE IF NOT EXISTS llx_support_parution_version_parution
(
  fk_parution INT(11) NOT NULL,
  fk_support_parution_version_support INT(11) NOT NULL
)ENGINE = InnoDB

DELIMITER $$

DROP PROCEDURE IF EXISTS upgrade_database_1_0_to_1_1 $$
CREATE PROCEDURE upgrade_database_1_0_to_1_1()
BEGIN

-- add a column safely > http://stackoverflow.com/questions/972922/add-column-to-mysql-table-if-it-does-not-exist
IF NOT EXISTS( (SELECT * FROM information_schema.COLUMNS WHERE TABLE_SCHEMA=DATABASE()
        AND COLUMN_NAME='active' AND TABLE_NAME='llx_support_parution_version_parution') ) THEN
    ALTER TABLE llx_support_parution_version_parution ADD active TINYINT(4) NOT NULL DEFAULT 1;
END IF;

END $$

CALL upgrade_database_1_0_to_1_1() $$

DELIMITER ;


Est ce que quelqu'un aurait une piste ?

Merci d'avance.

Bien à vous.

-- 
Gilles Lengy

Artaban Communication
33 (0)1 40 09 18 18
www.artaban.fr
spip.artaban.fr
Adhérent de l'April (www.april.org)

Garanti sans virus. www.avast.com

_______________________________________________
Dolibarr-dev mailing list
address@hidden
https://lists.nongnu.org/mailman/listinfo/dolibarr-dev




--
------------------------------------------------------------------------------------
Google+: https://plus.google.com/+LaurentDestailleur-Open-Source-Expert/
Facebook: https://www.facebook.com/Destailleur.Laurent
------------------------------------------------------------------------------------
* Dolibarr (Project leader): http://www.dolibarr.org (make a donation for Dolibarr project via Paypal: address@hidden)
* AWStats (Author) : http://awstats.sourceforge.net (make a donation for AWStats project via Paypal: address@hidden)
* AWBot (Author) : http://awbot.sourceforge.net
* CVSChangeLogBuilder (Author) : http://cvschangelogb.sourceforge.net



reply via email to

[Prev in Thread] Current Thread [Next in Thread]