Class tgcSqlBuilder_Select

Description

Subclass of tgcSqlBuilder that helps to create SELECT sql-statements.

Subclass of tgcSqlBuilder that helps to create SELECT sql-statements.

Located in /tgcSqlBuilder/Select.php (line 38)

tgcSqlBuilder
   |
   --tgcSqlBuilder_Select
Method Summary
 tgcSqlBuilder_Select tgcSqlBuilder_Select (object &$dbc)
 mixed addGroupBy (string $table, [string $column = null], [string $direction = SQLBUILDER_ORDER_ASC])
 void addHaving (string $table, string $column, mixed $value, [string $compOp = null], [string $logic = null])
 void addOrderBy (string $table, [string $column = null], [string $direction = null])
 void addRawHaving (string $statement, [string $logic = SQLBUILDER_LOGICAL_AND])
 void addRawSelect (string $statement, [string $alias = null])
 void addRawWhere (string $statement, [string $logic = SQLBUILDER_LOGICAL_AND])
 void addSelect (string $table, string $column, [string $alias = null])
 void addWhere (string $table, string $column, mixed $value, [string $compOp = null], [string $logic = null])
 void disableDistinct ()
 void enableDistinct ()
 string generateQuery ()
 mixed removeGroupBy ([string $table = null], [string $column = null])
 mixed removeHaving ([string $table = null], [string $column = null], [string $logic = null])
 mixed removeOrderBy ([string $table = null], [string $column = null])
 mixed removeRawHaving ([string $logic = null])
 void removeRawSelect ([string $alias = null])
 mixed removeRawWhere ([string $logic = null])
 mixed removeSelect ([string $table = null], [string $column = null])
 mixed removeWhere ([string $table = null], [string $column = null], [string $logic = null])
 void reset ()
 void setLimit (int $offset, [int $rows = null])
 void unsetLimit ()
Methods
Constructor tgcSqlBuilder_Select (line 292)

Constructor

Constructor

  • access: public
tgcSqlBuilder_Select tgcSqlBuilder_Select (object &$dbc)
  • object $dbc: PEAR::DB connection object
addGroupBy (line 664)

Add a GROUP BY statement.

Add a GROUP BY statement. How to call the method:


1 $sql = new tgcSqlBuilder_Select($dbc);
2
3 // add a GROUP BY for a tablename and a column, ASC
4 // as ASC is the default direction it doesn't have to be specified
5 $sql->addGroupBy('users', 'groupName');
6
7 // group by alias 'grpName', direction DESC
8 $sql->addGroupBy('grpName', null, SQLBUILDER_ORDER_DESC);
9
10 // group by column no. 2, direction ASC
11 $sql->addGroupBy(2);
The statements will be found in that order in the query, in which they have been added.

  • return: true on success, else PEAR_Error
  • access: public
mixed addGroupBy (string $table, [string $column = null], [string $direction = SQLBUILDER_ORDER_ASC])
  • string $table: tablename
  • string $column: columnname
  • string $direction: SQLBUILDER_ORDER_ASC or SQLBUILDER_ORDER_DESC
addHaving (line 956)

Add a WHERE statement.

Add a WHERE statement. Possible comparison operators are: SQLBUILDER_COMP_EQUAL, SQLBUILDER_COMP_NOT_EQUAL, SQLBUILDER_COMP_LESSER_THAN, SQLBUILDER_COMP_LESSER_EQUAL, SQLBUILDER_COMP_GREATER_EQUAL, SQLBUILDER_COMP_GREATER_THAN, SQLBUILDER_COMP_STARTSWITH, SQLBUILDER_COMP_CONTAINS, SQLBUILDER_COMP_ENDSWITH, SQLBUILDER_COMP_BETWEEN If none is specified then SQLBUILDER_COMP_EQUAL will be used. Possible logical expressions are: SQLBUILDER_LOGICAL_AND, SQLBUILDER_LOGICAL_OR If none is specified, then SQLBUILDER_LOGICAL_AND will be used. When you are using SQLBUILDER_COMP_BETWEEN, then specify $values as a numerical array with two values in correct order.

  • access: public
void addHaving (string $table, string $column, mixed $value, [string $compOp = null], [string $logic = null])
  • string $table: tablename
  • string $column: columnname
  • mixed $value: value(s)
  • string $compOp: comparison operator
  • string $logic: logical linkup
addOrderBy (line 805)

Add an ORDER BY setting.

Add an ORDER BY setting. The parameter $direction can be either SQLBUILDER_ORDER_ASC or SQLBUILDER_ORDER_DESC. If none is specified, then SQLBUILDER_ORDER_ASC will be used. You can also leave $column null, if you want to order by an alias.


1 $sql = new tgcSqlBuilder_Delete($dbc);
2
3 // ... ORDER BY alias1 ASC ...
4 $sql->addOrderBy('alias1');
5
6 // ... ORDER BY alias2 DESC ...
7 $sql->addOrderBy('alias2', null, SQLBUILDER_ORDER_DESC);
If a setting for this table/column exists, it will be overwritten.

  • access: public
void addOrderBy (string $table, [string $column = null], [string $direction = null])
  • string $table: tablename
  • string $column: columnname
  • string $direction: oder direction
addRawHaving (line 987)

Add a raw HAVING statement.

Add a raw HAVING statement. You can add a raw HAVING statement and define a logical operator. As default this is the logical AND.

  • access: public
void addRawHaving (string $statement, [string $logic = SQLBUILDER_LOGICAL_AND])
  • string $statement: raw HAVING statement
  • string $logic: SQLBUILDER_LOGICAL_AND or SQLBUILDER_LOGICAL_OR
addRawSelect (line 513)

Add a SELECT statement.

Add a SELECT statement. Optionally you can specify an alias for the column.


1 $sql = new tgcSqlBuilder_Select($dbc)
2 // this will add the following statement:
3 // SELECT MAX(users.userId) AS maxId, AVG(users.money) FROM ...
4 $sql->addRawSelect('MAX(users.userId)', 'maxId');
5 $sql->addRawSelect('AVG(users.money)');
If you call $sql->generateQuery() before you add a (raw) SELECT statement, a SELECT * FROM ... will be performed.

void addRawSelect (string $statement, [string $alias = null])
  • string $statement: raw SELECT statement
  • string $alias: alias
addRawWhere (line 621)

Add a raw WHERE statement.

Add a raw WHERE statement. You can add a raw WHERE statement and define a logical operator. As default this is the logical AND.

  • access: public
void addRawWhere (string $statement, [string $logic = SQLBUILDER_LOGICAL_AND])
  • string $statement: raw WHERE statement
  • string $logic: SQLBUILDER_LOGICAL_AND or SQLBUILDER_LOGICAL_OR
addSelect (line 418)

Add a SELECT statement.

Add a SELECT statement. Optionally you can specify an alias for the column.


1 $sql = new tgcSqlBuilder_Select($dbc)
2 // this will add the following statement: SELECT users.username AS name ...
3 $sql->addSelect('users', 'username', 'name');
If you call $sql->generateQuery() before you add a select statement, a SELECT * FROM ... will be performed.

void addSelect (string $table, string $column, [string $alias = null])
  • string $table: tablename
  • string $column: columnname
  • string $alias: aliasname for the column
addWhere (line 590)

Add a WHERE statement.

Add a WHERE statement. Possible comparison operators are: SQLBUILDER_COMP_EQUAL, SQLBUILDER_COMP_NOT_EQUAL, SQLBUILDER_COMP_LESSER_THAN, SQLBUILDER_COMP_LESSER_EQUAL, SQLBUILDER_COMP_GREATER_EQUAL, SQLBUILDER_COMP_GREATER_THAN, SQLBUILDER_COMP_STARTSWITH, SQLBUILDER_COMP_CONTAINS, SQLBUILDER_COMP_ENDSWITH, SQLBUILDER_COMP_BETWEEN If none is specified then SQLBUILDER_COMP_EQUAL will be used. Possible logical expressions are: SQLBUILDER_LOGICAL_AND, SQLBUILDER_LOGICAL_OR If none is specified, then SQLBUILDER_LOGICAL_AND will be used. When you are using SQLBUILDER_COMP_BETWEEN, then specify $values as a numerical array with two values in correct order.

  • access: public
void addWhere (string $table, string $column, mixed $value, [string $compOp = null], [string $logic = null])
  • string $table: tablename
  • string $column: columnname
  • mixed $value: value(s)
  • string $compOp: comparison operator
  • string $logic: logical linkup
disableDistinct (line 396)

Enable the distinct setting.

Enable the distinct setting.

  • access: public
void disableDistinct ()
enableDistinct (line 386)

Enable the distinct setting.

Enable the distinct setting.

  • access: public
void enableDistinct ()
generateQuery (line 310)

Generate the sql-statement.

Generate the sql-statement. This method generates a query based on the object-information and returns it as a string.


1 $sql = new tgcSqlBuilder_Select($dbc);
2 $query = $sql->generateQuery();

  • return: sql-statement
  • access: public
string generateQuery ()

Redefinition of:
tgcSqlBuilder::generateQuery()
Generate the sql-statement.
removeGroupBy (line 714)

Remove a GROUP BY statement.

Remove a GROUP BY statement.

  • return: true on success, else PEAR_Error
  • access: public
mixed removeGroupBy ([string $table = null], [string $column = null])
  • string $table: tablename
  • string $column: columnname
removeHaving (line 973)

Remove a WHERE statement.

Remove a WHERE statement. If you don't specify any parameter, then all WHERE information will be removed. If you specify a tablename and a columnname, then this specific ORDER BY setting will be removed.

  • return: true on success or PEAR_Error (possible error(s): SQLBUILDER_ERROR_INVALID_PARAM_COMBO)
  • access: public
mixed removeHaving ([string $table = null], [string $column = null], [string $logic = null])
  • string $table: tablename
  • string $column: columnname
  • string $logic: logical operation (possible values: SQLBUILDER_LOGICAL_AND, SQLBUILDER_LOGICAL_OR)
removeOrderBy (line 849)

Remove an ORDER BY setting.

Remove an ORDER BY setting. If you don't specify any parameter, then all ORDER BY information will be removed. If you specify a tablename and a columnname, then this specific ORDER BY setting will be removed.

  • return: true on success or PEAR_Error (possible error(s): SQLBUILDER_ERROR_INVALID_PARAM_COMBO)
  • access: public
mixed removeOrderBy ([string $table = null], [string $column = null])
  • string $table: tablename
  • string $column: columnname
removeRawHaving (line 999)

Remove the raw WHERE statements, that have been stored so far.

Remove the raw WHERE statements, that have been stored so far.

  • return: true on success, else PEAR_Error
  • access: public
mixed removeRawHaving ([string $logic = null])
  • string $logic: SQLBUILDER_LOGICAL_AND or SQLBUILDER_LOGICAL_OR
removeRawSelect (line 545)

Remove a raw SELECT statement.

Remove a raw SELECT statement. If call the method without parameters, all raw SELECT statements that have been stored so far will be removed. If you call the method with parameter, then the specified SELECT statement will be removed.


1 $sql = new tgcSqlBuilder_Select($dbc);
2 $sql->addRawSelect('MAX(users.userId)', 'maxId');
3 $sql->addRawSelect('AVG(users.money)');
4
5 // remove a specific raw SELECT statement by alias
6 $sql->removeRawSelect('maxId');
7
8 // remove all raw SELECT statements
9 $sql->removeRawSelect();

  • access: public
void removeRawSelect ([string $alias = null])
  • string $alias: alias
removeRawWhere (line 633)

Remove the raw WHERE statements, that have been stored so far.

Remove the raw WHERE statements, that have been stored so far.

  • return: true on success, else PEAR_Error
  • access: public
mixed removeRawWhere ([string $logic = null])
  • string $logic: SQLBUILDER_LOGICAL_AND or SQLBUILDER_LOGICAL_OR
removeSelect (line 456)

Remove a SELECT statement.

Remove a SELECT statement. If call the method without parameters, all SELECT statements that have been stored so far will be removed. If you call the method with one or two parameters, then the specified SELECT statement will be removed.


1 $sql = new tgcSqlBuilder_Select($dbc);
2 $sql->addSelect('users', 'userId');
3 $sql->addSelect('users', 'username', 'name');
4 $sql->addSelect('users', 'email', 'mail');
5
6 // remove a specific SELECT statement by alias
7 $sql->removeSelect('name');
8
9 // remove a specific SELECT statement
10 $sql->removeSelect('users', 'userId');
11
12 // remove all SELECT statements
13 $sql->removeSelect();

  • return: true on success, else PEAR_Error object
  • access: public
mixed removeSelect ([string $table = null], [string $column = null])
  • string $table: tablename
  • string $column: columnname
removeWhere (line 607)

Remove a WHERE statement.

Remove a WHERE statement. If you don't specify any parameter, then all WHERE information will be removed. If you specify a tablename and a columnname, then this specific ORDER BY setting will be removed.

  • return: true on success or PEAR_Error (possible error(s): SQLBUILDER_ERROR_INVALID_PARAM_COMBO)
  • access: public
mixed removeWhere ([string $table = null], [string $column = null], [string $logic = null])
  • string $table: tablename
  • string $column: columnname
  • string $logic: logical operation (possible values: SQLBUILDER_LOGICAL_AND, SQLBUILDER_LOGICAL_OR)
reset (line 366)

Reset the object's whole information.

Reset the object's whole information.

  • access: public
void reset ()

Redefinition of:
tgcSqlBuilder::reset()
Reset the object's whole information.
setLimit (line 908)

Set a LIMIT for the query.

Set a LIMIT for the query. Example:


1 $sql = new tgcSqlBuilder_Select($dbc);
2
3 // set a limit of 15 rows starting from offset 30
4 $sql->setLimit(30, 15);
5
6 // set a limit of 20 rows (starting from offset 0)
7 $sql->setLimit(20);

  • access: public
void setLimit (int $offset, [int $rows = null])
  • int $offset: offset
  • int $rows: number of rows
unsetLimit (line 925)

Unset the current LIMIT information.

Unset the current LIMIT information.

  • access: public
void unsetLimit ()

Inherited Methods

Inherited From tgcSqlBuilder

 tgcSqlBuilder::tgcSqlBuilder()
 tgcSqlBuilder::addTable()
 tgcSqlBuilder::escape()
 tgcSqlBuilder::generateQuery()
 tgcSqlBuilder::removeTable()
 tgcSqlBuilder::reset()

Documentation generated on Fri, 19 Nov 2004 23:54:05 +0100 by phpDocumentor 1.2.3