Packageindex Classtrees Modulegroups Elementlist Report XML Files

Softerra

SQL::SQLCompose

public module SQLCompose

Simple SQL Query Compose Library.

Linkshttp://www.softerra.com/products/ - [Softerra PHP Developer Library Home Page]
AuthorsSofterra <phplib@softerra.com>
SincePHP 4.0.1pl2
Version1.3.5
Copyright(c) 1999-2002 Softerra, LLC

 

Public Method Summary

string quotedValue(string $value)
Returns a single-quoted value.
string composeInsertQuery(string $table, array $values)
Returns the INSERT SQL query string.
string composeUpdateQuery(string $table, array $values, mixed $conditions)
Returns the UPDATE SQL query string.
string composeSelectQuery(mixed $tables, mixed $fields, mixed $conditions)
Returns the SELECT SQL query string.
string composeDeleteQuery(string $table, mixed $conditions)
Returns the DELETE SQL query string.
string simpleConditions(mixed $conditions)
Returns the simple condition string.
string composeQueryConditions(mixed $conditions, [ integer $type, array $limit, array $parameters, array $orderby, array $groupby ])
Returns SQL query end part.

Private Method Summary

void prepareValueOrExpression(string &$value)
Prepares a value or expression.
void prepareValuesOrExpressions(array &$values)
Prepares values or expressions.
array withTablePrefix(array $fields, string $table)
Returns an array of field names.
string homogenicConditions(array $conditions, [ string $relation, string $operation ])
Returns homogenic condition.
string equalityConditions(array $conditions)
Returns equality condition.
string complexConditions(array $conditions, array $operations)
Returns complex condition.
string dummyCondition()
Returns dummy condition.

Private Constant Summary

EXP_FLAG >>EXPRESSION=<< Expression flag.
CND_EQUALITY >>1<< Equality condition.
CND_HOMOGENIC >>2<< Homogenic condition.
CND_COMPLEX >>3<< Complex condition.
CND_SIMPLE >>4<< Simple condition.
CND_DUMMY >>5<< Dummy condition.

Public Method Details

quotedValue

public string quotedValue( string $value )

  Returns a single-quoted value.

Returns a quoted $value with backslashes before characters that need to be quoted in database queries, etc. These characters are a single quote ('), a double quote ("), a backslash (\) and NUL (the NULL byte).

Parameter
string $value
Returns string


composeInsertQuery

public string composeInsertQuery( string $table, array $values )

  Returns the INSERT SQL query string.

Returns the composed INSERT SQL query string.

Parameter
string $table
Table name
array $values
Array of values to insert. Array keys should be an integer or FIELD_NAMES.
Returns string

SQL query


composeUpdateQuery

public string composeUpdateQuery( string $table, array $values, mixed $conditions )

  Returns the UPDATE SQL query string.

Returns the composed UPDATE SQL query string.

Parameter
string $table
Table name.
array $values
Array of values to update. Array keys should be FIELD_NAMES.
mixed $conditions
Conditions, an array or string, if needed.
Returns string

SQL query.


composeSelectQuery

public string composeSelectQuery( mixed $tables, mixed $fields, mixed $conditions )

  Returns the SELECT SQL query string.

Returns the composed SELECT SQL query string.

Parameter
mixed $tables
Tables names, array or string.
mixed $fields
Fields names, array or string.
mixed $conditions
Conditions, an array or string, if needed.
Returns string

SQL query.


composeDeleteQuery

public string composeDeleteQuery( string $table, mixed $conditions )

  Returns the DELETE SQL query string.

Returns the composed DELETE SQL query string.

Parameter
string $table
Table name.
mixed $conditions
Conditions, an array or string, if needed.
Returns string

SQL query.


simpleConditions

public string simpleConditions( mixed $conditions )

  Returns the simple condition string.

Return the composed simple condition string. The string returned should begin with "WHERE" if $conditions is an array.

Parameter
mixed $conditions
Conditions, an array or string.
Returns string

SQL query WHERE part.


composeQueryConditions

public string composeQueryConditions( mixed $conditions, [ integer $type, array $limit, array $parameters, array $orderby, array $groupby ] )

  Returns SQL query end part.

Returns the composed WHERE, LIMIT, ORDER BY and GROUP BY parts of an SQL query.

Parameter
mixed $conditions
integer $type = >>1<<
Type of condition:
  • CND_EQUALITY - equalityConditions;
  • CND_HOMOGENIC - homogenicConditions;
  • CND_COMPLEX - complexConditions;
  • CND_SIMPLE - simpleConditions;
  • CND_DUMMY - dummyCondition.
array $limit = >>array()<<
Where $limit[0] - oofset, $limit[1] - rows.
array $parameters = >>array()<<
Additional parameters. If $type == CND_HOMOGENIC, you need to specify $parameters["relation"] and $parameters["operation"].
array $orderby = >>array()<<
$orderby[0] - string or array - field(s), $orderby[1] - direction (ASC, DESC).
array $groupby = >>array()<<
Returns string


Private Method Details

prepareValueOrExpression

private void prepareValueOrExpression( string &$value )

  Prepares a value or expression.

Prepares a value or expression to be used in SQL statements. Add slashes if $sqlAddSlashes is set.

Parameter
string &$value
Returns void

Required global variables
boolean $sqlAddSlashes
See Also prepareValuesOrExpressions()

prepareValuesOrExpressions

private void prepareValuesOrExpressions( array &$values )

  Prepares values or expressions.

Prepares values or expressions to be used in SQL statements.

Parameter
array &$values
Returns void

See Also prepareValuesOrExpressions()

withTablePrefix

private array withTablePrefix( array $fields, string $table )

  Returns an array of field names.

Returns an array of field names in the TABLE_NAME.FIELD_NAME format.

Parameter
array $fields
Field names
string $table
Table name
Returns array


homogenicConditions

private string homogenicConditions( array $conditions, [ string $relation, string $operation ] )

  Returns homogenic condition.

Returns an SQL query with the WHERE part being in the following format:

 "$conditions[key] $relation $conditions[value] [$operation $conditions[key] $relation $conditions[value]]"
 
without the "WHERE" string.

Parameter
array $conditions
Array where the array key is a table field and the array value is a field value.
string $relation = >>"="<<
One of the allowed SQL relations.
string $operation = >>"and"<<
One of the allowed SQL operations.
Returns string

WHERE part of SQL query without the "WHERE" string.

See Also equalityConditions()

equalityConditions

private string equalityConditions( array $conditions )

  Returns equality condition.

If $sqlLikeStringEquality is not set, calls homogenicConditions(). If the array value is a string, returns the WHERE part of an SQL query in the following format:

 "$conditions[key] like $conditions[value]"
 
else return
 "$conditions[key] = $conditions[value]"
 

Parameter
array $conditions
Array where the array key is a table field and the array value is a field value.
Returns string

WHERE part of an SQL query without the "WHERE" string.

Required global variables
boolean $sqlLikeStringEquality
See Also homogenicConditions()

complexConditions

private string complexConditions( array $conditions, array $operations )

  Returns complex condition.

Returns the composed complex condition string. If the array value is a string, returns the WHERE part of an SQL query in the following format:

 "$conditions[key] like $conditions[value]"
 
else return
 "$conditions[key] = $conditions[value]"
 

Parameter
array $conditions
This array contains the $field string and the $condition array $field is the $condition's key and $condition is the $condition's value $condition contains the $relation and $value string Supported $relation list: "like", "=", "!=", "", "", "=", "in", "not in", "between", "not between", "IS NULL", "IS NOT NULL"
array $operations
This array contains the "and" and "or" operations to be placed before the condition. I.e., the first element can be empty ("").
Returns string

WHERE part of an SQL query without the "WHERE" string.


dummyCondition

private string dummyCondition( )

  Returns dummy condition.

Returns the composed dummy condition string - "(1)". Needs to be used when user does not require any conditions.

Returns string

WHERE part of an SQL query without the "WHERE" string.


Private Constant Details

EXP_FLAG

define( EXP_FLAG, >>EXPRESSION=<< )
Case: default: case sensitive

Expression flag.


CND_EQUALITY

define( CND_EQUALITY, >>1<< )
Case: default: case sensitive

Equality condition.


CND_HOMOGENIC

define( CND_HOMOGENIC, >>2<< )
Case: default: case sensitive

Homogenic condition.


CND_COMPLEX

define( CND_COMPLEX, >>3<< )
Case: default: case sensitive

Complex condition.


CND_SIMPLE

define( CND_SIMPLE, >>4<< )
Case: default: case sensitive

Simple condition.


CND_DUMMY

define( CND_DUMMY, >>5<< )
Case: default: case sensitive

Dummy condition.



Packageindex Classtrees Modulegroups Elementlist Report XML Files