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
Afficher le fichier Open project: gabordemooij/redbean Class Usage Examples

Méthodes publiques

Свойство Type Description
$renames array
$typeno_sqltype array

Protected Properties

Свойство Type Description
$adapter RedBeanPHP\Adapter\DBAdapter
$cache array
$defaultValue string
$flagUseCache boolean
$maxCacheSizePerType integer
$quoteCharacter string

Méthodes publiques

Méthode 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' )

Méthodes protégées

Méthode 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

Méthode 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 méthode

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

addDataType() protected méthode

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))
Résultat self

addUniqueIndex() public méthode

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

camelsSnake() public static méthode

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
Résultat string

canBeTreatedAsInt() public static méthode

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

check() protected méthode

Checks table name or column name.
protected check ( $struct ) : string
Résultat string

clearRenames() public static méthode

Clears renames.
public static clearRenames ( ) : void
Résultat void

deleteRecord() public méthode

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

deleteRelations() public méthode

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

esc() public méthode

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

flushCache() public méthode

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

getAssocTable() public méthode

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

getAssocTableFormat() public static méthode

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

getForeignKeyForTypeProperty() protected méthode

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
Résultat array | null

getInsertSuffix() protected méthode

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

getKeyMapForType() protected méthode

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
Résultat array

getParametersForInClause() protected méthode

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...
Résultat string

getSQLFilterSnippet() protected méthode

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

getSQLFilters() public static méthode

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
Résultat array

glueLimitOne() public méthode

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

glueSQLCondition() public méthode

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

inferFetchType() public méthode

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

insertRecord() protected méthode

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
Résultat integer

makeFKLabel() protected méthode

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')
Résultat string

queryRecord() public méthode

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

queryRecordCount() public méthode

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

queryRecordCountRelated() public méthode

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

queryRecordRelated() public méthode

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

queryRecordWithCursor() public méthode

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

queryTagged() public méthode

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

renameAssocTable() public méthode

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

renameAssociation() public static méthode

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

safeColumn() public méthode

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

safeTable() public méthode

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

setNarrowFieldMode() public static méthode

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
Résultat void

setSQLFilters() public static méthode

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
Résultat void

setUseCache() public méthode

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

startsWithZeros() protected méthode

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.
Résultat boolean

tableExists() public méthode

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

updateRecord() public méthode

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

widenColumn() public méthode

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

wipe() public méthode

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

writeJoin() public méthode

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

Property Details

$adapter protected_oe property

protected DBAdapter,RedBeanPHP\Adapter $adapter
Résultat RedBeanPHP\Adapter\DBAdapter

$cache protected_oe property

protected array $cache
Résultat array

$defaultValue protected_oe property

protected string $defaultValue
Résultat string

$flagUseCache protected_oe property

protected bool $flagUseCache
Résultat boolean

$maxCacheSizePerType protected_oe property

protected int $maxCacheSizePerType
Résultat integer

$quoteCharacter protected_oe property

protected string $quoteCharacter
Résultat string

$renames public_oe static_oe property

public static array $renames
Résultat array

$typeno_sqltype public_oe property

public array $typeno_sqltype
Résultat array