I stumbled upon the following code within index.php while investigating a customer issue. It seems as though there is a bit of a flaw in the logic here, but I could also just as easily be overlooking a valid scenario which requires it.

Here is the block:

PHP Code:
$version_query 'SELECT count(*) as the_count FROM config WHERE category=\'info\' AND name=\'sugar_version\'';
if(
$current_user->db->dbType == 'oci8') {

}
else if (
$current_user->db->dbType == 'mssql')
{
    
$version_query .= " AND CAST(value AS varchar(8000)) = '$sugar_db_version'";
}
 else {
    
$version_query .= " AND value = '$sugar_db_version'";
}

$result $current_user->db->query($version_query);
$row $current_user->db->fetchByAssoc($result, -1true);
$row_count $row['the_count'];

if(
$row_count == 0){

    if (
$sugar_version == '4.5.0g') {
        
$update_query 'UPDATE config SET value=\'4.5.0\' WHERE category=\'info\' AND name=\'sugar_version\'';

        
$current_user->db->query($update_query);
    }
    else {
        
sugar_die("Sugar CRM $sugar_version Files May Only Be Used With A Sugar CRM $sugar_db_version Database.");
    }

The problem I see is that if you open a Sugar database that was created with a newer version of Sugar than the one you are using, the latter part of the code will update the config table to reflect the lower version number and in turn, when the appropriate version of Sugar next attempts to open its database, it will return the message that it is unable to do so because the versions do not match.

It seems to me it would be better if Sugar would do one of the following when a lower versioned install is attempting to open a database:

1. Inform the user they are using the wrong version of Sugar and kick them out (do not update config table)

or

2. Inform user of mismatch and potential problems, keep warning up top (like when there are updates available), and do not update config.