0

I'm developing a component for Joomla 3.6.4. The component includes some custom SQL tables.

Now I'd like to add more tables in another version of the same component, but it seems like there's no way to update a component using a ZIP-file. Correct?

If I try to install the component anew, it runs the old SQL install script, and causes primary key errors. Any tips would be helpful. Thank you.

Edit: My installation SQL code contains INSERT statements that caused problems with primary key collisions. These lines should only be executed once.

1 Answer 1

3

I am not sure what you mean when you say: "it seems like there's no way to update a component using a ZIP-file".

Usually you create your extension's package. In your myextension.xml file you have:

<install type="component" version="1.5" method="upgrade">

Always use method="upgrade"

Then later in your myextension.xml you define your install.php file:

<installfile>install.myextension.php</installfile>

Then in your install.myextension.php you write your code that you wanna run during the installation/update of your extension - do all checking about existing installation and the version of it, and conditionally run code to apply any changes - including alterations to the database tables - changes which usually you include in a install.sql file.

Your sql file will have your DB statements - for example:

CREATE TABLE IF NOT EXISTS `#__myextension_table` (...);

Update: INSERT's

For the case of using your INSERTs in your existing tables that already have the same values, your can modify your INSERT sql statements to:

INSERT IGNORE INTO mytable
    (pK, field1, field2)
VALUES
    (1, val1, val2),
    (2, val3, val4),
    (3, val5, val6);

The INSERT IGNO will skip any items with Duplicate primary key.

3
  • Thank you for your response. I also had INSERT statements in my SQL installation code, which caused the problems. Commented Jan 18, 2017 at 9:34
  • @OlleHärstedt - so your issue is how to insert records again in the previous tables, or it is solved now for you? In any case I updated my answer.
    – FFrewin
    Commented Jan 18, 2017 at 9:51
  • Thank you, did not know about INSERT INGORE, good tip! Just one more question: Did you also use SQL update files with version numbers, like 1.0.1.sql? I thought that if your version number is higher than previous, the install.sql will not be run, correct? Commented Jan 18, 2017 at 10:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.