opencartocmod

At opencart2.0, I want to create a ocmod extension. In install.sql, how do I determine if the database field exists?


At opencart2.0, I want to create a ocmod extension, In install.sql, I need to modify the database field. When I modify the database field, I need to decide if the field exists. Ive tried multiple variations of this, but none of them seem to work. Any ideas? Thanks in advance.

this is my install.sql,but is error

DROP PROCEDURE IF EXISTS add_col_need_credit; 
DELIMITER $$ CREATE PROCEDURE add_col_need_credit() BEGIN IF NOT EXISTS(SELECT column_name FROM information_schema.columns WHERE table_name='oc_customer_group_description' AND column_name='need_credit' ) THEN ALTER TABLE  `oc_customer_group_description`  ADD  `need_credit` numeric(10,4) NOT NULL default 0; END IF;END$$ DELIMITER ; 
CALL add_col_need_credit();

Solution

  • this is not error,you can in mysql console use it

    DROP PROCEDURE IF EXISTS add_col_need_credit; 
    DELIMITER $$ CREATE PROCEDURE add_col_need_credit() BEGIN IF NOT EXISTS(SELECT column_name FROM information_schema.columns WHERE table_name='oc_customer_group_description' AND column_name='need_credit' ) THEN ALTER TABLE  `oc_customer_group_description`  ADD  `need_credit` numeric(10,4) NOT NULL default 0; END IF;END$$ DELIMITER ; 
    CALL add_col_need_credit();