It is currently Thu Aug 28, 2008 7:51 pm
Moderators: willebil, Jinx, louis.landry







<?php
/**
* @version $Id: helper.php 747 2006-08-10 22:32:34Z eddieajau $
* @package JX-Open
* @subpackage Database
* @copyright (C) 2007 New Life in IT Pty Ltd. All rights reserved.
* @license LGPL <http://www.gnu.org/licenses/lgpl.html>
*/
/**
* Query Element Class
*
* @author Andrew Eddie <andrew.eddie@newlifeinit.com>
* @package JX-Open
* @subpackage Database
*/
class JXQueryElement
{
/** @var string The name of the element */
var $_name = null;
/** @var array An array of elements */
var $_elements = null;
/** @var string Glue piece */
var $_glue = null;
/**
* Constructor
* @param string The name of the element
* @param mixed String or array
* @param string The glue for elements
*/
function JXQueryElement( $name, $elements, $glue=',' )
{
$this->_elements = array();
$this->_name = $name;
$this->append( $elements );
$this->_glue = $glue;
}
/**
* Appends element parts to the internal list
* @param mixed String or array
*/
function append( $elements )
{
if (is_array( $elements )) {
$this->_elements = array_unique( array_merge( $this->_elements, $elements ) );
} else {
$this->_elements = array_unique( array_merge( $this->_elements, array( $elements ) ) );
}
}
/**
* Render the query element
* @return string
*/
function toString()
{
return "\n{$this->_name} " . implode( $this->_glue, $this->_elements );
}
}
/**
* Query Building Class
*
* @author Andrew Eddie <andrew.eddie@newlifeinit.com>
* @package JX-Open
* @subpackage Database
*/
class JXQuery
{
/** @var string The query type */
var $_type = '';
/** @var object The select element */
var $_select = null;
/** @var object The from element */
var $_from = null;
/** @var object The join element */
var $_join = null;
/** @var object The where element */
var $_where = null;
/** @var object The where element */
var $_group = null;
/** @var object The where element */
var $_having = null;
/** @var object The where element */
var $_order = null;
/**
* Constructor
*/
function JXQuery()
{
}
/**
* @param mixed A string or an array of field names
*/
function select( $columns )
{
$this->_type = 'select';
if (is_null( $this->_select )) {
$this->_select = new JXQueryElement( 'SELECT', $columns );
} else {
$this->_select->append( $columns );
}
}
/**
* @param mixed A string or array of table names
*/
function from( $tables )
{
if (is_null( $this->_from )) {
$this->_from = new JXQueryElement( 'FROM', $tables );
} else {
$this->_from->append( $tables );
}
}
/**
* @param string
* @param string
*/
function join( $type, $conditions )
{
if (is_null( $this->_join )) {
$this->_join = array();
}
$this->_join[] = new JXQueryElement( strtoupper( $type ) . ' JOIN', $conditions );
}
/**
* @param mixed A string or array of where conditions
* @param string
*/
function where( $conditions, $glue='AND' )
{
if (is_null( $this->_where )) {
$glue = strtoupper( $glue );
$this->_where = new JXQueryElement( 'WHERE', $conditions, "\n\t$glue " );
} else {
$this->_where->append( $conditions );
}
}
/**
* @param mixed A string or array of ordering columns
*/
function group( $columns )
{
if (is_null( $this->_group )) {
$this->_group = new JXQueryElement( 'GROUP BY', $columns );
} else {
$this->_group->append( $columns );
}
}
/**
* @param mixed A string or array of ordering columns
*/
function having( $columns )
{
if (is_null( $this->_having )) {
$this->_having = new JXQueryElement( 'HAVING', $columns );
} else {
$this->_having->append( $columns );
}
}
/**
* @param mixed A string or array of ordering columns
*/
function order( $columns )
{
if (is_null( $this->_order )) {
$this->_order = new JXQueryElement( 'ORDER BY', $columns );
} else {
$this->_order->append( $columns );
}
}
/**
* @return string The completed query
*/
function toString()
{
$query = '';
switch ($this->_type)
{
case 'select':
$query .= $this->_select->toString();
$query .= $this->_from->toString();
if ($this->_join) {
// special case for joins
foreach ($this->_join as $join) {
$query .= $join->toString();
}
}
if ($this->_where) {
$query .= $this->_where->toString();
}
if ($this->_group) {
$query .= $this->_group->toString();
}
if ($this->_having) {
$query .= $this->_having->toString();
}
if ($this->_order) {
$query .= $this->_order->toString();
}
break;
}
return $query;
}
}


class JQueryMySQL extends JQuery ...

go to town ... I gave you that simply as an example 















AmyStephen wrote:Plamen -
I looked over your jquery.php and mysql.php attachments and am very impressed with your progress. Is the basic plan that there would be a separate file for each database driver? So, there could be an oracle.php and a mssqlserver.php, etc., with a configuration decision made at installation time?



It defines the JDatabaseMySQL class.

plamendp wrote:including pgsql.php (PostgreSQL DB driver).



@Darb - Enno's project is not related to this. Essentially, Enno's project could change the database model - the table structures - to implement the node concepts for the content architecture. What Plamen is working on is database abstraction layer where the database itself could be stored in a choice of many RDBMS instead of only MySQL.
just wanted to be sure that you really can´t reuse some of the building classes Enno and others is developing so most of the core logic and its models is to be used in one place only :-)

mknz wrote:Seriously looking for a quote on that. It's not worth posting a project right now. I just need to see if someone can actually get a standardized data abstraction layer completed with a mssql driver.
Also check out this thred :http://forum.joomla.org/index.php/topic,193981.0.html
Not sure of the main differences here...but I think everyone's looking for the same results.
