Class Hylax_SQL_Attributes
This class provides attributes methods for any existing SQL class.
Copyright 1999-2012 Horde LLC (http://www.horde.org/)
See the enclosed file COPYING for license information (LGPL). If you
did not receive this file, see http://www.horde.org/licenses/lgpl21.
Methods summary
public
|
#
Hylax_SQL_Attributes( DB $dbh, array $params )
Constructor.
Parameters
- $dbh
- A PEAR::DB object.
- $params
- The id column, table names, etc.
|
public
array
|
#
getAttributes( integer $id )
Returns all attributes for a given id or multiple ids.
Returns all attributes for a given id or multiple ids.
Parameters
- $id
- array $id The id to fetch or an array of ids.
Returns
array A hash of attributes, or a multi-level hash
of ids => their attributes.
|
public
|
#
getByAttributes( array $criteria )
Return a set of ids based on a set of attribute criteria.
Return a set of ids based on a set of attribute criteria.
Parameters
- $criteria
- <p>The array of criteria. Example:
$criteria['OR'] = array(
array('field' => 'name',
'op' => '=',
'test' => 'foo'),
array('field' => 'name',
'op' => '=',
'test' => 'bar'));
This would return all ids for which the field
attribute_name is either 'foo' or 'bar'.</p>
|
public
|
#
insertAttributes( integer $id, array $attributes )
Given a new attribute set and an id, insert each into the DB. If
anything fails in here, rollback the transaction, return the relevant
error and bail out.
Given a new attribute set and an id, insert each into the DB. If
anything fails in here, rollback the transaction, return the relevant
error and bail out.
Parameters
- $id
- <p>The id of the record for which attributes are
being inserted.</p>
- $attributes
- An hash containing the attributes.
|
public
|
#
deleteAttributes( integer $id )
Given an id, delete all attributes for that id from the
attributes table.
Given an id, delete all attributes for that id from the
attributes table.
Parameters
- $id
- <p>The id of the record for which attributes are being
deleted.</p>
|
public
|
#
updateAttributes( integer $id, array $attributes )
Given an id, update all attributes for that id in the attributes table
with the new attributes.
Given an id, update all attributes for that id in the attributes table
with the new attributes.
Parameters
- $id
- <p>The id of the record for which attributes are
being deleted.</p>
- $attributes
- An hash containing the attributes.
|
public
string
|
#
_buildAttributeQuery( string $glue, array $criteria, boolean $join = false )
Build a piece of an attribute query.
Build a piece of an attribute query.
Parameters
- $glue
- The glue to join the criteria (OR/AND).
- $criteria
- The array of criteria.
- $join
- Should we join on a clean attributes table?
Returns
string An SQL fragment.
|
public
|
#
_getAlias( boolean $increment = false )
Get an alias to an attributes table, incrementing it if
necessary.
Get an alias to an attributes table, incrementing it if
necessary.
Parameters
- $increment
- Increment the alias count? Defaults to false.
|
Properties summary
public
DB
|
$_db
The PEAR::DB object to run queries with.
The PEAR::DB object to run queries with.
|
|
public
array
|
$_params
Parameters to use when generating queries:
id_column - The primary id column to use in joins.
primary_table - The main table name.
attribute_table - The table that the attributes are stored in.
Parameters to use when generating queries: id_column - The primary id column to use in joins. primary_table - The main table name. attribute_table - The table that the attributes are stored in.
|
|
public
integer
|
$_table_count
The number of copies of the attributes table that we need to join on in
the current query.
The number of copies of the attributes table that we need to join on in
the current query.
|
|