Overview

Namespaces

  • None
  • RedBeanPHP
    • Adapter
    • BeanHelper
    • Cursor
    • Driver
    • Logger
      • RDefault
    • QueryWriter
    • RedException
    • Repository
    • Util

Classes

  • AQueryWriter
  • CUBRID
  • MySQL
  • PostgreSQL
  • SQLiteT
  • Overview
  • Namespace
  • Class

Class AQueryWriter

RedBeanPHP Abstract Query Writer. Represents an abstract Database to RedBean To write a driver for a different database for RedBean Contains a number of functions all implementors can inherit or override.

Direct known subclasses

RedBeanPHP\QueryWriter\CUBRID, RedBeanPHP\QueryWriter\MySQL, RedBeanPHP\QueryWriter\PostgreSQL, RedBeanPHP\QueryWriter\SQLiteT
Abstract
Namespace: RedBeanPHP\QueryWriter
Copyright:

(c) copyright G.J.G.T. (Gabor) de Mooij and the RedBeanPHP Community. This source file is subject to the BSD/GPLv2 License that is bundled with this source code in the file license.txt.


License: BSD/GPLv2
Author: Gabor de Mooij and the RedBeanPHP Community
File: RedBeanPHP/QueryWriter/AQueryWriter.php
Located at QueryWriter/AQueryWriter.php
Methods summary
public static boolean
# canBeTreatedAsInt( string $value )

Checks whether a number can be treated like an int.

Checks whether a number can be treated like an int.

Parameters

$value
string representation of a certain value

Returns

boolean
public static
# getAssocTableFormat( $types )

See

QueryWriter::getAssocTableFormat
public static
# renameAssociation( $from, $to = NULL )

See

QueryWriter::renameAssociation
public static string
# camelsSnake( string $camel )

Globally available service method for RedBeanPHP. Converts a camel cased string to a snake cased string.

Globally available service method for RedBeanPHP. Converts a camel cased string to a snake cased string.

Parameters

$camel
camelCased string to converty to snake case

Returns

string
public static
# clearRenames( )

Clears renames.

Clears renames.

public static
# setNarrowFieldMode( boolean $narrowField )

Toggles 'Narrow Field Mode'. In Narrow Field mode the queryRecord method will narrow its selection field to

Toggles 'Narrow Field Mode'. In Narrow Field mode the queryRecord method will narrow its selection field to

SELECT {table}.*

instead of

SELECT *

This is a better way of querying because it allows more flexibility (for instance joins). However if you need the wide selector for backward compatibility; use this method to turn OFF Narrow Field Mode by passing FALSE.

Parameters

$narrowField
TRUE = Narrow Field FALSE = Wide Field
public static
# setSQLFilters( array $sqlFilters, $safeMode = false )

Sets SQL filters. This is a lowlevel method to set the SQL filter array. The format of this array is:

Sets SQL filters. This is a lowlevel method to set the SQL filter array. The format of this array is:

array(
        '<MODE, i.e. 'r' for read, 'w' for write>' => array(
            '<TABLE NAME>' => array(
                '<COLUMN NAME>' => '<SQL>'
            )
        )
)

Example:

array(
  QueryWriter::C_SQLFILTER_READ => array(
    'book' => array(
        'title' => ' LOWER(book.title) '
    )
)

Note that you can use constants instead of magical chars as keys for the uppermost array. This is a lowlevel method. For a more friendly method please take a look at the facade: R::bindFunc().

Parameters

$sqlFilters
of filters to set
$safeMode
public static array
# getSQLFilters( )

Returns current SQL Filters. This method returns the raw SQL filter array. This is a lowlevel method. For a more friendly method please take a look at the facade: R::bindFunc().

Returns current SQL Filters. This method returns the raw SQL filter array. This is a lowlevel method. For a more friendly method please take a look at the facade: R::bindFunc().

Returns

array
protected array|null
# getForeignKeyForTypeProperty( string $type, string $property )

Given a type and a property name this method returns the foreign key map section associated with this pair.

Given a type and a property name this method returns the foreign key map section associated with this pair.

Parameters

$type
name of the type
$property
name of the property

Returns

array|null
protected array
# getKeyMapForType( string $type )

Returns the foreign key map (FKM) for a type. A foreign key map describes the foreign keys in a table. A FKM always has the same structure:

Returns the foreign key map (FKM) for a type. A foreign key map describes the foreign keys in a table. A FKM always has the same structure:

array(
    'name'      => <name of the foreign key>
   'from'      => <name of the column on the source table>
   'table'     => <name of the target table>
   'to'        => <name of the target column> (most of the time 'id')
   'on_update' => <update rule: 'SET NULL','CASCADE' or 'RESTRICT'>
   'on_delete' => <delete rule: 'SET NULL','CASCADE' or 'RESTRICT'>
)

Parameters

$type
the bean type you wish to obtain a key map of

Returns

array

Note

the keys in the result array are FKDLs, i.e. descriptive unique keys per source table. Also see: AQueryWriter::makeFKLabel for details.


protected string
# makeFKLabel( string $from, string $type, string $to )

This method makes a key for a foreign key description array. This key is a readable string unique for every source table. This uniform key is called the FKDL Foreign Key Description Label. Note that the source table is not part of the FKDL because this key is supposed to be 'per source table'. If you wish to include a source table, prefix the key with 'on_table__'.

This method makes a key for a foreign key description array. This key is a readable string unique for every source table. This uniform key is called the FKDL Foreign Key Description Label. Note that the source table is not part of the FKDL because this key is supposed to be 'per source table'. If you wish to include a source table, prefix the key with 'on_table__'.

Parameters

$from
the column of the key in the source table
$type
the type (table) where the key points to
$to
the target column of the foreign key (mostly just 'id')

Returns

string
protected string
# getSQLFilterSnippet( string $type )

Returns an SQL Filter snippet for reading.

Returns an SQL Filter snippet for reading.

Parameters

$type
type of bean

Returns

string
protected string
# getParametersForInClause( array & $valueList, array $otherBindings, integer $offset = 0 )

Generates a list of parameters (slots) for an SQL snippet. This method calculates the correct number of slots to insert in the SQL snippet and determines the correct type of slot. If the bindings array contains named parameters this method will return named ones and update the keys in the value list accordingly (that's why we use the &).

Generates a list of parameters (slots) for an SQL snippet. This method calculates the correct number of slots to insert in the SQL snippet and determines the correct type of slot. If the bindings array contains named parameters this method will return named ones and update the keys in the value list accordingly (that's why we use the &).

If you pass an offset the bindings will be re-added to the value list. Some databases cant handle duplicate parameter names in queries.

Parameters

$valueList
$valueList list of values to generate slots for (gets modified if needed)
$otherBindings
list of additional bindings
$offset
start counter at...

Returns

string
protected RedBeanPHP\QueryWriter\AQueryWriter
# addDataType( integer $dataTypeID, string $SQLDefinition )

Adds a data type to the list of data types. Use this method to add a new column type definition to the writer. Used for UUID support.

Adds a data type to the list of data types. Use this method to add a new column type definition to the writer. Used for UUID support.

Parameters

$dataTypeID
magic number constant assigned to this data type
$SQLDefinition
SQL column definition (i.e. INT(11))

Returns

RedBeanPHP\QueryWriter\AQueryWriter
protected string
# getInsertSuffix( string $table )

Returns the sql that should follow an insert statement.

Returns the sql that should follow an insert statement.

Parameters

$table
name

Returns

string
protected boolean
# startsWithZeros( string $value )

Checks whether a value starts with zeros. In this case the value should probably be stored using a text datatype instead of a numerical type in order to preserve the zeros.

Checks whether a value starts with zeros. In this case the value should probably be stored using a text datatype instead of a numerical type in order to preserve the zeros.

Parameters

$value
value to be checked.

Returns

boolean
protected integer
# insertRecord( string $type, array $insertcolumns, array $insertvalues )

Inserts a record into the database using a series of insert columns and corresponding insertvalues. Returns the insert id.

Inserts a record into the database using a series of insert columns and corresponding insertvalues. Returns the insert id.

Parameters

$type
$table table to perform query on
$insertcolumns
columns to be inserted
$insertvalues
values to be inserted

Returns

integer
protected string
# check( string $struct )

Checks table name or column name.

Checks table name or column name.

Parameters

$struct
$table table string

Returns

string
public boolean
# tableExists( string $table )

Checks whether the specified type (i.e. table) already exists in the database. Not part of the Object Database interface!

Checks whether the specified type (i.e. table) already exists in the database. Not part of the Object Database interface!

Parameters

$table
table name

Returns

boolean
public
# glueSQLCondition( $sql, $glue = NULL )

See

QueryWriter::glueSQLCondition
public
# glueLimitOne( $sql = '' )

See

QueryWriter::glueLimitOne
public
# esc( $dbStructure, $dontQuote = FALSE )

See

QueryWriter::esc
public
# addColumn( $type, $column, $field )

See

QueryWriter::addColumn
public
# updateRecord( $type, $updatevalues, $id = NULL )

See

QueryWriter::updateRecord
public
# writeJoin( $type, $targetType, $leftRight = 'LEFT' )

See

QueryWriter::writeJoin
public
# queryRecord( $type, $conditions = array(), $addSql = NULL, $bindings = array() )

See

QueryWriter::queryRecord
public
# queryRecordWithCursor( $type, $addSql = NULL, $bindings = array() )

See

QueryWriter::queryRecordWithCursor
public
# queryRecordRelated( $sourceType, $destType, $linkIDs, $addSql = '', $bindings = array() )

See

QueryWriter::queryRecordRelated
public
# queryRecordLink( $sourceType, $destType, $sourceID, $destID )

See

QueryWriter::queryRecordLink
public
# queryTagged( $type, $tagList, $all = FALSE, $addSql = '', $bindings = array() )

See

QueryWriter::queryTagged
public
# queryRecordCount( $type, $conditions = array(), $addSql = NULL, $bindings = array() )

See

QueryWriter::queryRecordCount
public
# queryRecordCountRelated( $sourceType, $destType, $linkID, $addSql = '', $bindings = array() )

See

QueryWriter::queryRecordCountRelated
public
# deleteRecord( $type, $conditions = array(), $addSql = NULL, $bindings = array() )

See

QueryWriter::deleteRecord
public
# deleteRelations( $sourceType, $destType, $sourceID )

See

QueryWriter::deleteRelations
public
# widenColumn( $type, $property, $dataType )

See

QueryWriter::widenColumn
public
# wipe( $type )

See

QueryWriter::wipe
public
# renameAssocTable( $from, $to = NULL )

See

QueryWriter::renameAssocTable
public
# getAssocTable( $types )

See

QueryWriter::getAssocTable
public
# setUseCache( boolean $yesNo )

Turns caching on or off. Default: off. If caching is turned on retrieval queries fired after eachother will use a result row cache.

Turns caching on or off. Default: off. If caching is turned on retrieval queries fired after eachother will use a result row cache.

Parameters

$yesNo
public integer
# flushCache( $newMaxCacheSizePerType = NULL )

Flushes the Query Writer Cache. Clears the internal query cache array and returns its overall size.

Flushes the Query Writer Cache. Clears the internal query cache array and returns its overall size.

Returns

integer
public string
# safeColumn( string $column, boolean $noQuotes = FALSE )

Deprecated

Use esc() instead.

Parameters

$column
column to be escaped
$noQuotes
omit quotes

Returns

string
public string
# safeTable( string $table, boolean $noQuotes = FALSE )

Deprecated

Use esc() instead.

Parameters

$table
table to be escaped
$noQuotes
omit quotes

Returns

string
public
# inferFetchType( $type, $property )

See

QueryWriter::inferFetchType
public
# addUniqueIndex( $type, $properties )

See

QueryWriter::addUniqueConstraint
Properties summary
public static array $renames
# array()
protected RedBeanPHP\Adapter\DBAdapter $adapter
#
protected string $defaultValue
# 'NULL'
protected string $quoteCharacter
# ''
protected boolean $flagUseCache
# TRUE
protected array $cache
# array()
protected integer $maxCacheSizePerType
# 20
public array $typeno_sqltype
# array()
API documentation generated by ApiGen