What's new in 6.4.0 — Database Layer Updates

bsoremsugar —  January 24, 2012 — 10 Comments

SugarCRM 6.4.0 includes a new database layer that’s been drastically overhauled under the hood.  This refactor is a big step in cleaning up the Sugar code base and will allow for future DB support to come at a lower development cost.  The need to litter code with conditional statements that branch on different DB types is gone.  For example, consider the following code snippet based on the old codebase that converts a date input from a form as $field_value into DB format:

$dbType = $GLOBALS['db']->dbType;
if($dbType == 'mysql') {
    $dbValue = $timedate->to_db_date($field_value, false);
} else if($dbType == 'mssql') {
    $dbValue = "Convert(DateTime, '".$timedate->;to_db_date($field_value, false)."')";
} else {
    $dbValue = $timedate->to_db_date($field_value, false);
}

That snippet can now be written as:

$db = DBManagerFactory::getInstance();
$dbValue = $db->convert($field_value, "date_format", array("%Y-%m"));
Everything done in the former code block still has to happen, but it’s been encapsulated and abstracted out to the refactored database layer.  This makes it easier to add support for new databases like PostgreSQL, as well as drastically improves code readability and makes the application easier to debug.

10 responses to What's new in 6.4.0 — Database Layer Updates

  1. 
    Enrico Simonetti January 24, 2012 at 7:17 am

    Good stuff!
    Given that you are changing all the database layer, did you guys implement anything that can improve performance with MySQL?
    Eg: All writes happen on the MySQL master, and all the reads happen randomly from one of the MySQL slaves?
    Last time I checked, the only module that could read from a MySQL slave was the Reports module on Enterprise (and above I suspect).

    Cheers

  2. 

    Is there improvements for upgrade safe changes to the DB Layer.  We have run into areas where the generated SQL is incorrect for MSSQL

    • 
      Frank Steegmans January 26, 2012 at 9:13 pm

      Generally 6.4 should run a whole lot better on databases other than MySQL. Many MySQL specific constructs have been fixed. 6.4 is also the first release which is running on all 4 major supported databases (MySQL, MSSQL, Oracle and DB2) in CI (since August 2011). Every commit to the 6.4 (and later) branch results in a build, deployment and running of about 2200+ unit tests against all 4 databases.

  3. 

    Awesome ! Was looking forward to this. Thanks for sharing.

  4. 

    Great post! Very useful info. Thanks for sharing.

Trackbacks and Pingbacks:

  1. SugarCRM Developer Blog » Blog Archive » Like PostgreSQL and want to use it with SugarCRM? Check out a new community project! - August 3, 2012

    [...] you remember with the SugarCRM 6.4 release, one of the big goals we had with the database refactor it was to make it easier for building out new database backends by only needing to change the code [...]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s