Skip to content

Commit

Permalink
[#27282] Add ability to support other databases, starting with Microsoft
Browse files Browse the repository at this point in the history
SQL Server and Postgresql (platform changes)
  • Loading branch information
hooduku authored and dextercowley committed Dec 7, 2011
1 parent 92312ba commit d447c14
Show file tree
Hide file tree
Showing 30 changed files with 4,321 additions and 102 deletions.
14 changes: 8 additions & 6 deletions libraries/joomla/access/access.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,15 +219,17 @@ public static function getAssetRules($asset, $recursive = false)
$query = $db->getQuery(true);
$query->select($recursive ? 'b.rules' : 'a.rules');
$query->from('#__assets AS a');
//sqlsrv change
$query->group($recursive ? 'b.id, b.rules, b.lft' : 'a.id, a.rules, a.lft');

// If the asset identifier is numeric assume it is a primary key, else lookup by name.
if (is_numeric($asset))
{
$query->where('a.id = ' . (int) $asset);
if (is_numeric($asset)) {
// Get the root even if the asset is not found
$query->where('(a.id = ' . (int) $asset . ($recursive ? ' OR a.parent_id=0' : '') . ')');
}
else
{
$query->where('a.name = ' . $db->quote($asset));
else {
// Get the root even if the asset is not found
$query->where('(a.name = '.$db->quote($asset) . ($recursive ? ' OR a.parent_id=0' : '') . ')');
}

// If we want the rules cascading up to the global asset node we need a self-join.
Expand Down
17 changes: 14 additions & 3 deletions libraries/joomla/application/categories.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,16 @@ protected function _load($id)

// Right join with c for category
$query->select('c.*');
$query->select('CASE WHEN CHAR_LENGTH(c.alias) THEN CONCAT_WS(":", c.id, c.alias) ELSE c.id END as slug');
$query->from('#__categories as c');
$case_when = ' CASE WHEN ';
$case_when .= $query->charLength('c.alias');
$case_when .= ' THEN ';
$c_id = $query->castAsChar('c.id');
$case_when .= $query->concatenate(array($c_id, 'c.alias'), ':');
$case_when .= ' ELSE ';
$case_when .= $c_id.' END as slug';
$query->select($case_when);

$query->from('#__categories as c');
$query->where('(c.extension=' . $db->Quote($extension) . ' OR c.extension=' . $db->Quote('system') . ')');

if ($this->_options['access'])
Expand Down Expand Up @@ -265,7 +273,10 @@ protected function _load($id)
}

// Group by
$query->group('c.id');
$query->group('c.id, c.asset_id, c.access, c.alias, c.checked_out, c.checked_out_time,
c.created_time, c.created_user_id, c.description, c.extension, c.hits, c.language, c.level,
c.lft, c.metadata, c.metadesc, c.metakey, c.modified_time, c.note, c.params, c.parent_id,
c.path, c.published, c.rgt, c.title, c.modified_user_id');

// Filter by language
if ($app->isSite() && $app->getLanguageFilter())
Expand Down
9 changes: 7 additions & 2 deletions libraries/joomla/application/component/modellist.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,12 @@ public function getItems()
$this->setError($this->_db->getErrorMsg());
return false;
}

//sqlsrv change
foreach($items as $item)
{
if(isset($item->language))
$item->language = trim($item->language);
}
// Add the items to the internal cache.
$this->cache[$store] = $items;

Expand Down Expand Up @@ -228,7 +233,7 @@ public function getTotal()

// Load the total.
$query = $this->_getListQuery();
$total = (int) $this->_getListCount($query);
$total = (int) $this->_getListCount((string) $query);

// Check for a database error.
if ($this->_db->getErrorNum())
Expand Down
3 changes: 2 additions & 1 deletion libraries/joomla/application/menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ public function __construct($options = array())
{
if ($item->home)
{
$this->_default[$item->language] = $item->id;
//sql srv change
$this->_default[trim($item->language)] = $item->id;
}

// Decode the item params
Expand Down
2 changes: 1 addition & 1 deletion libraries/joomla/application/module/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ protected static function &_load()
$query->where('e.enabled = 1');

$date = JFactory::getDate();
$now = $date->toMySQL();
$now = $date->format('Y-m-d H:i:s');
$nullDate = $db->getNullDate();
$query->where('(m.publish_up = ' . $db->Quote($nullDate) . ' OR m.publish_up <= ' . $db->Quote($now) . ')');
$query->where('(m.publish_down = ' . $db->Quote($nullDate) . ' OR m.publish_down >= ' . $db->Quote($now) . ')');
Expand Down
66 changes: 65 additions & 1 deletion libraries/joomla/database/database.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ static function test();
* @subpackage Database
* @since 11.1
*/
abstract class JDatabase implements JDatabaseInterface
abstract class JDatabase
{
/**
* The name of the database driver.
Expand Down Expand Up @@ -111,6 +111,12 @@ abstract class JDatabase implements JDatabaseInterface
* @since 11.1
*/
protected $sql;
/**
* The number of queries performed by the object instance
*
* @var int
*/
protected $ticker = 0;

/**
* @var string The common database table prefix.
Expand Down Expand Up @@ -398,6 +404,15 @@ public static function splitSql($sql)
return $queries;
}

/**
* Test to see if the connector is available.
*
* @return bool True on success, false otherwise.
*
* @since 12.1
*/
abstract public static function test();

/**
* Magic method to provide method alias support for quote() and quoteName().
*
Expand Down Expand Up @@ -489,6 +504,17 @@ public function addQuoted($quoted)
* @since 11.1
*/
abstract public function connected();

/**
* Database object destructor
*
* @return boolean
* @since 12.1
*/
public function __destruct()
{
return true;
}

/**
* Method to escape a string for usage in an SQL statement.
Expand Down Expand Up @@ -1738,4 +1764,42 @@ public function stderr($showSQL = false)
return JText::_('JLIB_DATABASE_FUNCTION_NOERROR');
}
}

/**
* Drops a table from the database.
*
* @param string $table The name of the database table to drop.
* @param boolean $ifExists Optionally specify that the table must exist before it is dropped.
*
* @return JDatabaseSQLSrv Returns this object to support chaining.
* @since 11.1
*/
public abstract function dropTable($table, $ifExists = true);

/**
* Show tables in the database
* @param string $dbName
*/
public abstract function showTables($dbName);

/*
* Rename the table
* @param string $oldTable the name of the table to be renamed
* @param string $prefix for the table - used to rename constraints in non-mysql databases
* @param string $backup table prefix
* @param string $newTable newTable name
*/
public abstract function renameTable($oldTable, $prefix = null, $backup = null, $newTable) ;

/**
* Locks the table - with over ride in mysql and mysqli only
* @param object $table
* @return
*/
public abstract function lock($table);
/**
* Unlocks the table with override in mysql and mysqli only
* @return
*/
public abstract function unlock();
}
Loading

0 comments on commit d447c14

Please sign in to comment.