PHP Class RedBeanPHP\QueryWriter\AQueryWriter

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.
Author: Gabor de Mooij and the RedBeanPHP Community
显示文件 Open project: gabordemooij/redbean Class Usage Examples

Public Properties

Property Type Description
$renames array
$typeno_sqltype array

Protected Properties

Property Type Description
$adapter RedBeanPHP\Adapter\DBAdapter
$cache array
$defaultValue string
$flagUseCache boolean
$maxCacheSizePerType integer
$quoteCharacter string

Public Methods

Method Description
addColumn ( $type, $column, $field )
addUniqueIndex ( $type, $properties )
camelsSnake ( string $camel ) : string Globally available service method for RedBeanPHP.
canBeTreatedAsInt ( string $value ) : boolean Checks whether a number can be treated like an int.
clearRenames ( ) : void Clears renames.
deleteRecord ( $type, $conditions = [], $addSql = NULL, $bindings = [] )
deleteRelations ( $sourceType, $destType, $sourceID )
esc ( $dbStructure, $dontQuote = FALSE )
flushCache ( $newMaxCacheSizePerType = NULL ) : integer Flushes the Query Writer Cache.
getAssocTable ( $types )
getAssocTableFormat ( $types )
getSQLFilters ( ) : array Returns current SQL Filters.
glueLimitOne ( $sql = '' )
glueSQLCondition ( $sql, $glue = NULL )
inferFetchType ( $type, $property )
queryRecord ( $type, $conditions = [], $addSql = NULL, $bindings = [] )
queryRecordCount ( $type, $conditions = [], $addSql = NULL, $bindings = [] )
queryRecordCountRelated ( $sourceType, $destType, $linkID, $addSql = '', $bindings = [] )
queryRecordLink ( $sourceType, $destType, $sourceID, $destID )
queryRecordRelated ( $sourceType, $destType, $linkIDs, $addSql = '', $bindings = [] )
queryRecordWithCursor ( $type, $addSql = NULL, $bindings = [] )
queryTagged ( $type, $tagList, $all = FALSE, $addSql = '', $bindings = [] )
renameAssocTable ( $from, $to = NULL )
renameAssociation ( $from, $to = NULL )
safeColumn ( string $column, boolean $noQuotes = FALSE ) : string
safeTable ( string $table, boolean $noQuotes = FALSE ) : string
setNarrowFieldMode ( boolean $narrowField ) : void Toggles 'Narrow Field Mode'.
setSQLFilters ( $sqlFilters, $safeMode = false ) : void Sets SQL filters.
setUseCache ( $yesNo ) : void Turns caching on or off. Default: off.
tableExists ( string $table ) : boolean Checks whether the specified type (i.e. table) already exists in the database.
updateRecord ( $type, $updatevalues, $id = NULL )
widenColumn ( $type, $property, $dataType )
wipe ( $type )
writeJoin ( $type, $targetType, $leftRight = 'LEFT' )

Protected Methods

Method Description
addDataType ( integer $dataTypeID, string $SQLDefinition ) : self Adds a data type to the list of data types.
check ( $struct ) : string Checks table name or column name.
getForeignKeyForTypeProperty ( string $type, string $property ) : array | null Given a type and a property name this method returns the foreign key map section associated with this pair.
getInsertSuffix ( string $table ) : string Returns the sql that should follow an insert statement.
getKeyMapForType ( string $type ) : array Returns the foreign key map (FKM) for a type.
getParametersForInClause ( &$valueList, array $otherBindings, integer $offset ) : string Generates a list of parameters (slots) for an SQL snippet.
getSQLFilterSnippet ( string $type ) : string Returns an SQL Filter snippet for reading.
insertRecord ( $type, array $insertcolumns, array $insertvalues ) : integer Inserts a record into the database using a series of insert columns and corresponding insertvalues. Returns the insert id.
makeFKLabel ( string $from, string $type, string $to ) : string This method makes a key for a foreign key description array.
startsWithZeros ( string $value ) : boolean 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.

Private Methods

Method Description
getCacheKey ( array $keyValues ) : string Returns a cache key for the cache values passed.
getCached ( string $cacheTag, string $key ) : mixed Returns the values associated with the provided cache tag and key.
getRelationalTablesAndColumns ( string $sourceType, string $destType, boolean $noQuote = FALSE ) : array Returns the table names and column names for a relational query.
makeSQLFromConditions ( array $conditions, array &$bindings, string $addSql = '' ) : string Creates an SQL snippet from a list of conditions of format:
putResultInCache ( string $cacheTag, string $key, array $values ) : void Stores data from the writer in the cache under a specific key and cache tag.
updateCache ( ) : boolean Checks if the previous query had a keep-cache tag.

Method Details

addColumn() public method

See also: QueryWriter::addColumn
public addColumn ( $type, $column, $field )

addDataType() protected method

Use this method to add a new column type definition to the writer. Used for UUID support.
protected addDataType ( integer $dataTypeID, string $SQLDefinition ) : self
$dataTypeID integer magic number constant assigned to this data type
$SQLDefinition string SQL column definition (i.e. INT(11))
return self

addUniqueIndex() public method

See also: QueryWriter::addUniqueConstraint
public addUniqueIndex ( $type, $properties )

camelsSnake() public static method

Converts a camel cased string to a snake cased string.
public static camelsSnake ( string $camel ) : string
$camel string camelCased string to converty to snake case
return string

canBeTreatedAsInt() public static method

Checks whether a number can be treated like an int.
public static canBeTreatedAsInt ( string $value ) : boolean
$value string string representation of a certain value
return boolean

check() protected method

Checks table name or column name.
protected check ( $struct ) : string
return string

clearRenames() public static method

Clears renames.
public static clearRenames ( ) : void
return void

deleteRecord() public method

See also: QueryWriter::deleteRecord
public deleteRecord ( $type, $conditions = [], $addSql = NULL, $bindings = [] )

deleteRelations() public method

See also: QueryWriter::deleteRelations
public deleteRelations ( $sourceType, $destType, $sourceID )

esc() public method

See also: QueryWriter::esc
public esc ( $dbStructure, $dontQuote = FALSE )

flushCache() public method

Clears the internal query cache array and returns its overall size.
public flushCache ( $newMaxCacheSizePerType = NULL ) : integer
return integer

getAssocTable() public method

See also: QueryWriter::getAssocTable
public getAssocTable ( $types )

getAssocTableFormat() public static method

See also: QueryWriter::getAssocTableFormat
public static getAssocTableFormat ( $types )

getForeignKeyForTypeProperty() protected method

Given a type and a property name this method returns the foreign key map section associated with this pair.
protected getForeignKeyForTypeProperty ( string $type, string $property ) : array | null
$type string name of the type
$property string name of the property
return array | null

getInsertSuffix() protected method

Returns the sql that should follow an insert statement.
protected getInsertSuffix ( string $table ) : string
$table string name
return string

getKeyMapForType() protected method

A foreign key map describes the foreign keys in a table. A FKM always has the same structure: array( 'name' => 'from' => 'table' => 'to' => (most of the time 'id') 'on_update' => 'on_delete' => )
protected getKeyMapForType ( string $type ) : array
$type string the bean type you wish to obtain a key map of
return array

getParametersForInClause() protected method

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.
protected getParametersForInClause ( &$valueList, array $otherBindings, integer $offset ) : string
$otherBindings array list of additional bindings
$offset integer start counter at...
return string

getSQLFilterSnippet() protected method

Returns an SQL Filter snippet for reading.
protected getSQLFilterSnippet ( string $type ) : string
$type string type of bean
return string

getSQLFilters() public static method

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().
public static getSQLFilters ( ) : array
return array

glueLimitOne() public method

See also: QueryWriter::glueLimitOne
public glueLimitOne ( $sql = '' )

glueSQLCondition() public method

See also: QueryWriter::glueSQLCondition
public glueSQLCondition ( $sql, $glue = NULL )

inferFetchType() public method

See also: QueryWriter::inferFetchType
public inferFetchType ( $type, $property )

insertRecord() protected method

Inserts a record into the database using a series of insert columns and corresponding insertvalues. Returns the insert id.
protected insertRecord ( $type, array $insertcolumns, array $insertvalues ) : integer
$insertcolumns array columns to be inserted
$insertvalues array values to be inserted
return integer

makeFKLabel() protected method

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__'.
protected makeFKLabel ( string $from, string $type, string $to ) : string
$from string the column of the key in the source table
$type string the type (table) where the key points to
$to string the target column of the foreign key (mostly just 'id')
return string

queryRecord() public method

See also: QueryWriter::queryRecord
public queryRecord ( $type, $conditions = [], $addSql = NULL, $bindings = [] )

queryRecordCount() public method

See also: QueryWriter::queryRecordCount
public queryRecordCount ( $type, $conditions = [], $addSql = NULL, $bindings = [] )

queryRecordCountRelated() public method

See also: QueryWriter::queryRecordCountRelated
public queryRecordCountRelated ( $sourceType, $destType, $linkID, $addSql = '', $bindings = [] )

queryRecordRelated() public method

See also: QueryWriter::queryRecordRelated
public queryRecordRelated ( $sourceType, $destType, $linkIDs, $addSql = '', $bindings = [] )

queryRecordWithCursor() public method

See also: QueryWriter::queryRecordWithCursor
public queryRecordWithCursor ( $type, $addSql = NULL, $bindings = [] )

queryTagged() public method

See also: QueryWriter::queryTagged
public queryTagged ( $type, $tagList, $all = FALSE, $addSql = '', $bindings = [] )

renameAssocTable() public method

See also: QueryWriter::renameAssocTable
public renameAssocTable ( $from, $to = NULL )

renameAssociation() public static method

See also: QueryWriter::renameAssociation
public static renameAssociation ( $from, $to = NULL )

safeColumn() public method

Deprecation: Use esc() instead.
public safeColumn ( string $column, boolean $noQuotes = FALSE ) : string
$column string column to be escaped
$noQuotes boolean omit quotes
return string

safeTable() public method

Deprecation: Use esc() instead.
public safeTable ( string $table, boolean $noQuotes = FALSE ) : string
$table string table to be escaped
$noQuotes boolean omit quotes
return string

setNarrowFieldMode() public static method

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.
public static setNarrowFieldMode ( boolean $narrowField ) : void
$narrowField boolean TRUE = Narrow Field FALSE = Wide Field
return void

setSQLFilters() public static method

This is a lowlevel method to set the SQL filter array. The format of this array is: array( '' => array( '' => array( '' => '' ) ) ) 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().
public static setSQLFilters ( $sqlFilters, $safeMode = false ) : void
return void

setUseCache() public method

If caching is turned on retrieval queries fired after eachother will use a result row cache.
public setUseCache ( $yesNo ) : void
return void

startsWithZeros() protected method

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.
protected startsWithZeros ( string $value ) : boolean
$value string value to be checked.
return boolean

tableExists() public method

Not part of the Object Database interface!
public tableExists ( string $table ) : boolean
$table string table name
return boolean

updateRecord() public method

See also: QueryWriter::updateRecord
public updateRecord ( $type, $updatevalues, $id = NULL )

widenColumn() public method

See also: QueryWriter::widenColumn
public widenColumn ( $type, $property, $dataType )

wipe() public method

See also: QueryWriter::wipe
public wipe ( $type )

writeJoin() public method

See also: QueryWriter::writeJoin
public writeJoin ( $type, $targetType, $leftRight = 'LEFT' )

Property Details

$adapter protected_oe property

protected DBAdapter,RedBeanPHP\Adapter $adapter
return RedBeanPHP\Adapter\DBAdapter

$cache protected_oe property

protected array $cache
return array

$defaultValue protected_oe property

protected string $defaultValue
return string

$flagUseCache protected_oe property

protected bool $flagUseCache
return boolean

$maxCacheSizePerType protected_oe property

protected int $maxCacheSizePerType
return integer

$quoteCharacter protected_oe property

protected string $quoteCharacter
return string

$renames public_oe static_oe property

public static array $renames
return array

$typeno_sqltype public_oe property

public array $typeno_sqltype
return array