Archived

Difference between revisions of "Managing Component Updates (Update SQL files)"

From Joomla! Documentation

Line 44: Line 44:
 
This example has complete install files for component versions 1.0 (initial), 1.1.1 and 1.3.  Update SQL files are included for additional incremental component versions (1.1, 1.2 and 1.2.1) between these three versions.  These extra versions illustrate the process for updates that span more than one incremental version.
 
This example has complete install files for component versions 1.0 (initial), 1.1.1 and 1.3.  Update SQL files are included for additional incremental component versions (1.1, 1.2 and 1.2.1) between these three versions.  These extra versions illustrate the process for updates that span more than one incremental version.
  
* When updating from version 1.0 to version 1.1.1, both files 1.1.sql and 1.1.1.sql are executed.  The SQL commands update the value of the first, and only, row in the database table.  The command in 1.1.1.sql over-writes the value that was written by the 1.1 update.
+
* When updating from version 1.0 to version 1.1.1, both files 1.1.sql and 1.1.1.sql are executed.  The SQL commands update the value of the first, and only, row in the database table.  The command in 1.1.1.sql over-writes the value that was written by 1.1.sql.
 
* When updating from version 1.1.1 to version 1.3, files 1.2.sql, 1.2.1.sql and 1.3.sql are executed.  The commands in 1.2.sql and 1.3.sql each create a new row in the database table.
 
* When updating from version 1.1.1 to version 1.3, files 1.2.sql, 1.2.1.sql and 1.3.sql are executed.  The commands in 1.2.sql and 1.3.sql each create a new row in the database table.
 
* When updating from version 1.0 directly to 1.3, files 1.1.sql, 1.1.1.sql, 1.2.sql, 1.2.1.sql and 1.3.sql are all executed.  You can see the cumulative effect of the table changes in the component front-end.
 
* When updating from version 1.0 directly to 1.3, files 1.1.sql, 1.1.1.sql, 1.2.sql, 1.2.1.sql and 1.3.sql are all executed.  You can see the cumulative effect of the table changes in the component front-end.

Revision as of 11:51, 29 May 2011

This page has been archived. This page contains information for an unsupported Joomla! version or is no longer relevant. It exists only as a historical reference, it will not be improved and its content may be incomplete and/or contain broken links.

Quill icon.png
Content is Incomplete

This article or section is incomplete, which means it may be lacking information. You are welcome to assist in its completion by editing it as well. If this article or section has not been edited in several days, please consider helping complete the content.
This article was last edited by Sm990 (talk| contribs) 12 years ago. (Purge)

This tutorial is for Joomla Joomla 1.6

Articles in this series[edit]

Update SQL files[edit]

The update SQL file(s) are located in a directory that is listed in the manifest file:

<update> 
	<schemas> 
		<schemapath type="mysql">sql/updates</schemapath> 
	</schemas> 
</update>

There is a file for each component version. Each file name must match the version string in the manifest file for that version. Joomla uses this string to determine which SQL files(s) to execute, and in what order they will be executed. Joomla uses the PHP version_compare function for this. Familiarize yourself with this command. Your version sequence needs to adhere to the conventions of this command. For example, the SQL files for version 3.1 include:

1.0.sql
  (empty)

1.1.sql
  UPDATE `#__democompupdate_mytable` SET myvalue='Version 1.1 text' WHERE id=1;

1.1.1.sql
  UPDATE `#__democompupdate_mytable` SET myvalue='Version 1.1.1 text' WHERE id=1;

1.2.sql
  INSERT INTO `#__democompupdate_mytable` (id,myvalue) VALUES (2,'Version 1.2 text');

1.2.1.sql
  UPDATE `#__democompupdate_mytable` SET myvalue='Version 1.2.1 text' WHERE id=2;

1.3.sql
  INSERT INTO `#__democompupdate_mytable` (id,myvalue) VALUES (3,'Version 1.3 text');

This example has complete install files for component versions 1.0 (initial), 1.1.1 and 1.3. Update SQL files are included for additional incremental component versions (1.1, 1.2 and 1.2.1) between these three versions. These extra versions illustrate the process for updates that span more than one incremental version.

  • When updating from version 1.0 to version 1.1.1, both files 1.1.sql and 1.1.1.sql are executed. The SQL commands update the value of the first, and only, row in the database table. The command in 1.1.1.sql over-writes the value that was written by 1.1.sql.
  • When updating from version 1.1.1 to version 1.3, files 1.2.sql, 1.2.1.sql and 1.3.sql are executed. The commands in 1.2.sql and 1.3.sql each create a new row in the database table.
  • When updating from version 1.0 directly to 1.3, files 1.1.sql, 1.1.1.sql, 1.2.sql, 1.2.1.sql and 1.3.sql are all executed. You can see the cumulative effect of the table changes in the component front-end.

Joomla executes the database updates in the sequence that would occur, as if the user had updated each version separately. This would be necessary if an incremental database update depended on the correct update from the previous version. An example would be: an addition of a table value during one version depended on the insertion of a new table field during the update of the previous version.

Joomla uses the PHP function version_compare to define the execution order of the SQL files. The sequencing of your component version string must adhere to that defined by the version_compare function.

Contributors[edit]