I think the best way is to use the install.php file that is invoked after the component install routine is completed.
I can load the db object and do a SELECT query to find out the status of a field that tells me the schema version of my component's db BUT when I try to UPDATE the row it doesn't work.
Eventually given the test of the schema I will then do a conditional ALTER table command, etc - but I need to know if there is something I'm doing wrong or if the $database object prevents me from doing anything but SELECT.
Here is my code:
Code: Select all
$database = & JFactory::getDBO();
$query = 'SELECT schemaVersion FROM #__bsms_schemaVersion';
$database->setQuery( $query );
$schema_version = $database->loadObjectList();
$schema_version = $schema_version[0];
echo 'The database schema for this version of Bible Study is: '.$schema_version->schemaVersion.'<br>';
if ($schema_version->schemaVersion == 502)
{
$query = 'UPDATE #__bsms_schemaVersion SET schemaVersion="503" WHERE id="1"';
$database->setQuery($query);
$query = 'SELECT schemaVersion FROM #__bsms_schemaVersion';
$database->setQuery( $query );
$schema_version3 = $database->loadObjectList();
$schema_version3 = $schema_version3[0];
echo 'The database schema for this version of Bible Study is now: '.$schema_version3->schemaVersion.'<br>';
}
Is there a better way to upgrade components that have to have their db's updated?
Thanks!
Tom