Post by Dutch Pride Code » Fri Jul 30, 2021 6:51 pm

Version 3.0.3.7

I am creating an extension with a model file, it needs some new database tables to store data. Now the install() method does actually create 3 new tables as it should. However, the uninstall() method does not remove the tables from the database. When re-installing, as a result, it generates an error saying the tables already exist until I've manually removed the tables from the OC database. What am I missing?

Controller says:
(the file name is correct)

Code: Select all

    public function uninstall() {
        $this->load->model('extension/module/smanager');
        $this->model_extension_module_smanager->uninstall();
    }
Model says:

Code: Select all

	public function uninstall() {
		$this->db->query("DROP TABLE IF EXISTS `" . DB_PREFIX . "sproduct`");
		$this->db->query("DROP TABLE IF EXISTS `" . DB_PREFIX . "ssetting`");
		$this->db->query("DROP TABLE IF EXISTS `" . DB_PREFIX . "slisting`");
	}

User avatar
Active Member

Posts

Joined
Sun Jan 26, 2020 9:46 pm

Post by straightlight » Fri Jul 30, 2021 7:14 pm

EMGX wrote:
Fri Jul 30, 2021 6:51 pm
Version 3.0.3.7

I am creating an extension with a model file, it needs some new database tables to store data. Now the install() method does actually create 3 new tables as it should. However, the uninstall() method does not remove the tables from the database. When re-installing, as a result, it generates an error saying the tables already exist until I've manually removed the tables from the OC database. What am I missing?

Controller says:
(the file name is correct)

Code: Select all

    public function uninstall() {
        $this->load->model('extension/module/smanager');
        $this->model_extension_module_smanager->uninstall();
    }
Model says:

Code: Select all

	public function uninstall() {
		$this->db->query("DROP TABLE IF EXISTS `" . DB_PREFIX . "sproduct`");
		$this->db->query("DROP TABLE IF EXISTS `" . DB_PREFIX . "ssetting`");
		$this->db->query("DROP TABLE IF EXISTS `" . DB_PREFIX . "slisting`");
	}
The complete code.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by Dutch Pride Code » Fri Jul 30, 2021 7:16 pm

straightlight wrote:
Fri Jul 30, 2021 7:14 pm
The complete code.
Well, installing works. Why doesn't uninstalling work?
It drops the tables that were created on install. That's all it has to do. Right?

User avatar
Active Member

Posts

Joined
Sun Jan 26, 2020 9:46 pm

Post by straightlight » Fri Jul 30, 2021 7:19 pm

EMGX wrote:
Fri Jul 30, 2021 7:16 pm
straightlight wrote:
Fri Jul 30, 2021 7:14 pm
The complete code.
Well, installing works. Why doesn't uninstalling work?
It drops the tables, that's all it has to do. Right?
Ensure your database permissions from your databases icon on your host panel are properly set. If those permissions are set right, you shouldn't have any issues uninstalling these tables. If so and your permissions are set correctly, then you'd either have to post the complete code or contact your host regarding permission issues.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by paulfeakins » Fri Jul 30, 2021 7:52 pm

It's a bad idea to drop tables on uninstall as it's not clear that data will be lost.

Better just to add IF NOT EXISTS to your CREATE query.

UK OpenCart Hosting | OpenCart Audits | OpenCart Support - please email info@antropy.co.uk


User avatar
Guru Member
Online

Posts

Joined
Mon Aug 22, 2011 11:01 pm
Location - London Gatwick, United Kingdom

Post by Dutch Pride Code » Sat Jul 31, 2021 12:31 am

paulfeakins wrote:
Fri Jul 30, 2021 7:52 pm
It's a bad idea to drop tables on uninstall as it's not clear that data will be lost.

Better just to add IF NOT EXISTS to your CREATE query.
So I'd be better off leaving the data in the users database and re-use that data when installing the extension again?

User avatar
Active Member

Posts

Joined
Sun Jan 26, 2020 9:46 pm

Post by paulfeakins » Mon Aug 02, 2021 6:37 pm

EMGX wrote:
Sat Jul 31, 2021 12:31 am
So I'd be better off leaving the data in the users database and re-use that data when installing the extension again?
Yes, that's how many extensions work.

UK OpenCart Hosting | OpenCart Audits | OpenCart Support - please email info@antropy.co.uk


User avatar
Guru Member
Online

Posts

Joined
Mon Aug 22, 2011 11:01 pm
Location - London Gatwick, United Kingdom
Who is online

Users browsing this forum: No registered users and 101 guests