C_SQLFILTER_READ
C_SQLFILTER_READ
SQL filter constants
QueryWriter Interface for QueryWriters.
Describes the API for a QueryWriter.
Terminology:
parseJoin(string $type, string $sql) : string
Parses an sql string to create joins if needed.
For instance with $type = 'book' and $sql = ' @joined.author.name LIKE ? OR @joined.detail.title LIKE ? '
parseJoin will return the following SQL:
' LEFT JOIN author
ON author
.id = book
.author_id
LEFT JOIN detail
ON detail
.id = book
.detail_id
WHERE author.name LIKE ? OR detail.title LIKE ? '
string | $type | the source type for the join |
string | $sql | the sql string to be parsed |
writeJoin(string $type, string $targetType, string $leftRight, string $joinType, boolean $firstOfChain, string $suffix) : string
Writes an SQL Snippet for a JOIN, returns the SQL snippet string.
string | $type | source type |
string | $targetType | target type (type to join) |
string | $leftRight | type of join (possible: 'LEFT', 'RIGHT' or 'INNER') |
string | $joinType | relation between joined tables (possible: 'parent', 'own', 'shared') |
boolean | $firstOfChain | is it the join of a chain (or the only join) |
string | $suffix | suffix to add for aliasing tables (for joining same table multiple times) |
glueSQLCondition(string $sql, integer|NULL $glue = NULL) : string
Glues an SQL snippet to the beginning of a WHERE clause.
This ensures users don't have to add WHERE to their query snippets.
The snippet gets prefixed with WHERE or AND if it starts with a condition.
If the snippet does NOT start with a condition (or this function thinks so) the snippet is returned as-is.
The GLUE type determines the prefix:
This method will never replace WHERE with AND since a snippet should never begin with WHERE in the first place. OR is not supported.
Only a limited set of clauses will be recognized as non-conditions. For instance beginning a snippet with complex statements like JOIN or UNION will not work. This is too complex for use in a snippet.
string | $sql | SQL Snippet |
integer|NULL | $glue | the GLUE type - how to glue (C_GLUE_WHERE or C_GLUE_AND) |
getColumns(string $type) : array
Returns an array containing all the columns of the specified type.
The format of the return array looks like this: $field => $type where $field is the name of the column and $type is a database specific description of the datatype.
This methods accepts a type and infers the corresponding table name.
string | $type | type of bean you want to obtain a column list of |
scanType(mixed $value, boolean $alsoScanSpecialForTypes = FALSE) : integer
Returns the Column Type Code (integer) that corresponds to the given value type. This method is used to determine the minimum column type required to represent the given value. There are two modes of operation: with or without special types. Scanning without special types requires the second parameter to be set to FALSE. This is useful when the column has already been created and prevents it from being modified to an incompatible type leading to data loss. Special types will be taken into account when a column does not exist yet (parameter is then set to TRUE).
Special column types are determines by the AQueryWriter constant C_DATA_TYPE_ONLY_IF_NOT_EXISTS (usually 80). Another 'very special' type is type C_DATA_TYPE_MANUAL (usually 99) which represents a user specified type. Although no special treatment has been associated with the latter for now.
mixed | $value | value |
boolean | $alsoScanSpecialForTypes | take special types into account |
code(string $typedescription, boolean $includeSpecials = FALSE) : integer
Returns the Type Code for a Column Description.
Given an SQL column description this method will return the corresponding code for the writer. If the include specials flag is set it will also return codes for special columns. Otherwise special columns will be identified as specified columns.
string | $typedescription | description |
boolean | $includeSpecials | whether you want to get codes for special columns as well |
widenColumn(string $type, string $column, integer $datatype) : void
This method will widen the column to the specified data type.
This methods accepts a type and infers the corresponding table name.
string | $type | type / table that needs to be adjusted |
string | $column | column that needs to be altered |
integer | $datatype | target data type |
queryRecord(string $type, array $conditions = array(), string|NULL $addSql = NULL, array $bindings = array()) : array
Selects records from the database.
This methods selects the records from the database that match the specified type, conditions (optional) and additional SQL snippet (optional).
string | $type | name of the table you want to query |
array | $conditions | criteria ( $column => array( $values ) ) |
string|NULL | $addSql | additional SQL snippet |
array | $bindings | bindings for SQL snippet |
queryRecordWithCursor(string $type, string|NULL $addSql = NULL, array $bindings = array()) : \RedBeanPHP\Cursor
Selects records from the database and returns a cursor.
This methods selects the records from the database that match the specified type, conditions (optional) and additional SQL snippet (optional).
string | $type | name of the table you want to query |
string|NULL | $addSql | additional SQL snippet |
array | $bindings | bindings for SQL snippet |
queryRecordRelated(string $sourceType, string $destType, mixed $linkID, string $addSql = '', array $bindings = array()) : array
Returns records through an intermediate type. This method is used to obtain records using a link table and allows the SQL snippets to reference columns in the link table for additional filtering or ordering.
string | $sourceType | source type, the reference type you want to use to fetch related items on the other side |
string | $destType | destination type, the target type you want to get beans of |
mixed | $linkID | ID to use for the link table |
string | $addSql | Additional SQL snippet |
array | $bindings | Bindings for SQL snippet |
queryRecordLink(string $sourceType, string $destType, string $sourceID, string $destID) : array|null
Returns the row that links $sourceType $sourceID to $destType $destID in an N-M relation.
string | $sourceType | source type, the first part of the link you're looking for |
string | $destType | destination type, the second part of the link you're looking for |
string | $sourceID | ID for the source |
string | $destID | ID for the destination |
queryRecordCount(string $type, array $conditions = array(), string|NULL $addSql = NULL, array $bindings = array()) : integer
Counts the number of records in the database that match the conditions and additional SQL.
string | $type | name of the table you want to query |
array | $conditions | criteria ( $column => array( $values ) ) |
string|NULL | $addSql | additional SQL snippet |
array | $bindings | bindings for SQL snippet |
queryRecordCountRelated(string $sourceType, string $targetType, mixed $linkID, string $addSQL = '', array $bindings = array()) : integer
Returns the number of records linked through $linkType and satisfying the SQL in $addSQL/$bindings.
string | $sourceType | source type |
string | $targetType | the thing you want to count |
mixed | $linkID | the of the source type |
string | $addSQL | additional SQL snippet |
array | $bindings | bindings for SQL snippet |
queryTagged(string $type, array $tagList, boolean $all = FALSE, string $addSql = '', array $bindings = array()) : array
Returns all rows of specified type that have been tagged with one of the strings in the specified tag list array.
Note that the additional SQL snippet can only be used for pagination, the SQL snippet will be appended to the end of the query.
string | $type | the bean type you want to query |
array | $tagList | an array of strings, each string containing a tag title |
boolean | $all | if TRUE only return records that have been associated with ALL the tags in the list |
string | $addSql | addition SQL snippet, for pagination |
array | $bindings | parameter bindings for additional SQL snippet |
queryCountTagged(string $type, array $tagList, boolean $all = FALSE, string $addSql = '', array $bindings = array()) : integer
Like queryTagged but only counts.
string | $type | the bean type you want to query |
array | $tagList | an array of strings, each string containing a tag title |
boolean | $all | if TRUE only return records that have been associated with ALL the tags in the list |
string | $addSql | addition SQL snippet, for pagination |
array | $bindings | parameter bindings for additional SQL snippet |
queryRecursiveCommonTableExpression(string $type, integer $id, boolean $up = TRUE, string|NULL $addSql = NULL, array $bindings = array(), boolean $select = \RedBeanPHP\QueryWriter::C_CTE_SELECT_NORMAL) : array
Returns all parent rows or child rows of a specified row.
Given a type specifier and a primary key id, this method returns either all child rows
as defined by having
The $select parameter can be used to adjust the select snippet of the query. Possible values are: C_CTE_SELECT_NORMAL (just select all columns, default), C_CTE_SELECT_COUNT (count rows) used for countParents and countChildren functions - or you can specify a string yourself like 'count(distinct brand)'.
string | $type | the bean type you want to query rows for |
integer | $id | id of the reference row |
boolean | $up | TRUE to query parent rows, FALSE to query child rows |
string|NULL | $addSql | optional SQL snippet to embed in the query |
array | $bindings | parameter bindings for additional SQL snippet |
boolean | $select | Select Snippet to use when querying (optional) |
updateRecord(string $type, array $updatevalues, integer|NULL $id = NULL) : integer
This method should update (or insert a record), it takes a table name, a list of update values ( $field => $value ) and an primary key ID (optional). If no primary key ID is provided, an INSERT will take place.
Returns the new ID. This methods accepts a type and infers the corresponding table name.
string | $type | name of the table to update |
array | $updatevalues | list of update values |
integer|NULL | $id | optional primary key ID value |
deleteRecord(string $type, array $conditions = array(), string $addSql = '', array $bindings = array()) : integer
Deletes records from the database.
string | $type | name of the table you want to query |
array | $conditions | criteria ( $column => array( $values ) ) |
string | $addSql | additional SQL |
array | $bindings | bindings |
sqlStateIn(string $state, array $list, array $extraDriverDetails = array()) : boolean
This method will check whether the SQL state is in the list of specified states and returns TRUE if it does appear in this list or FALSE if it does not. The purpose of this method is to translate the database specific state to a one of the constants defined in this class and then check whether it is in the list of standard states provided.
string | $state | SQL state to consider |
array | $list | list of standardized SQL state constants to check against |
array | $extraDriverDetails | Some databases communicate state information in a driver-specific format rather than through the main sqlState code. For those databases, this extra information can be used to determine the standardized state |
addFK(string $type, string $targetType, string $property, string $targetProperty, boolean $isDep = FALSE) : void
This method will add a foreign key from type and field to target type and target field.
The foreign key is created without an action. On delete/update no action will be triggered. The FK is only used to allow database tools to generate pretty diagrams and to make it easy to add actions later on. This methods accepts a type and infers the corresponding table name.
string | $type | type that will have a foreign key field |
string | $targetType | points to this type |
string | $property | field that contains the foreign key value |
string | $targetProperty | field where the fk points to |
boolean | $isDep | whether target is dependent and should cascade on update/delete |
addIndex(string $type, string $name, string $property) : void
This method will add an index to a type and field with name $name.
This methods accepts a type and infers the corresponding table name.
string | $type | type to add index to |
string | $name | name of the new index |
string | $property | field to index |
esc(string $databaseStructure, $dontQuote = FALSE) : string
Checks and filters a database structure element like a table of column for safe use in a query. A database structure has to conform to the RedBeanPHP DB security policy which basically means only alphanumeric symbols are allowed. This security policy is more strict than conventional SQL policies and does therefore not require database specific escaping rules.
string | $databaseStructure | name of the column/table to check |
$dontQuote |
renameAssocTable(string|array $fromType, string $toType = NULL) : void
Renames an association. For instance if you would like to refer to album_song as: track you can specify this by calling this method like:
renameAssociation('album_song','track')
This allows:
$album->sharedSong
to add/retrieve beans from track instead of album_song. Also works for exportAll().
This method also accepts a single associative array as its first argument.
string|array | $fromType | original type name, or array |
string | $toType | new type name (only if 1st argument is string) |
getAssocTable(array $types) : string
Returns the format for link tables.
Given an array containing two type names this method returns the name of the link table to be used to store and retrieve association records. For instance, given two types: person and project, the corresponding link table might be: 'person_project'.
array | $types | two types array($type1, $type2) |