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.
For property-specific templates set $beanType to:
account.username -- then the template will only be applied to SQL statements relating
to that column/property.
If no template can be found for the specified type, the template for
'*' will be returned instead.
Parameters
string
$type
( 'createTable' | 'widenColumn' | 'addColumn' )
string
$beanType
( type of bean or '*' to apply to all types )
string|NULL
$property
specify if you're looking for a property-specific template
Returns
string
useISNULLConditions()
useISNULLConditions(boolean $flag) : boolean
Toggles support for IS-NULL-conditions.
If IS-NULL-conditions are enabled condition arrays
for functions including findLike() are treated so that
'field' => NULL will be interpreted as field IS NULL
instead of being skipped. Returns the previous
value of the flag.
Parameters
boolean
$flag
TRUE or FALSE
Returns
boolean
useJSONColumns()
useJSONColumns(boolean $flag) : boolean
Toggles support for automatic generation of JSON columns.
Using JSON columns means that strings containing JSON will
cause the column to be created (not modified) as a JSON column.
However it might also trigger exceptions if this means the DB attempts to
convert a non-json column to a JSON column. Returns the previous
value of the flag.
Parameters
boolean
$flag
TRUE or FALSE
Returns
boolean
forbidNuke()
forbidNuke(boolean $flag) : boolean
Toggles support for nuke().
Can be used to turn off the nuke() feature for security reasons.
Returns the old flag value.
Parameters
boolean
$flag
TRUE or FALSE
Returns
boolean
canBeTreatedAsInt()
canBeTreatedAsInt(string $value) : boolean
Checks whether a number can be treated like an int.
Parameters
string
$value
string representation of a certain value
Returns
boolean
getAssocTableFormat()
getAssocTableFormat( $types)
Parameters
$types
renameAssociation()
renameAssociation( $from, $to = NULL)
Parameters
$from
$to
camelsSnake()
camelsSnake(string $camel) : string
Globally available service method for RedBeanPHP.
Converts a camel cased string to a snake cased string.
Converts a snake cased string to a camel cased string.
Parameters
string
$snake
snake_cased string to convert to camelCase
$dolphinMode
Returns
string
clearRenames()
clearRenames() : void
Clears renames.
setNarrowFieldMode()
setNarrowFieldMode(boolean $narrowField) : void
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.
Default is TRUE.
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
$safeMode
getSQLFilters()
getSQLFilters() : array
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
tableExists()
tableExists(string $table) : boolean
Checks whether the specified type (i.e. table) already exists in the database.
Sets an SQL snippet to be used for the next queryRecord() operation.
A select snippet will be inserted at the end of the SQL select statement and
can be used to modify SQL-select commands to enable locking, for instance
using the 'FOR UPDATE' snippet (this will generate an SQL query like:
'SELECT * FROM ... FOR UPDATE'. After the query has been executed the
SQL snippet will be erased. Note that only the first upcoming direct or
indirect invocation of queryRecord() through batch(), find() or load()
will be affected. The SQL snippet will be cached.
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 'ontable
Parameters
string
$from
the column of the key in the source table
string
$type
the type (table) where the key points to
string
$to
the target column of the foreign key (mostly just 'id')
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.
Use this method to add a new column type definition to the writer.
Used for UUID support.
Parameters
integer
$dataTypeID
magic number constant assigned to this data type
string
$SQLDefinition
SQL column definition (e.g. INT(11))
Returns
self
getInsertSuffix()
getInsertSuffix(string $table) : string
Returns the sql that should follow an insert statement.
Parameters
string
$table
name
Returns
string
startsWithZeros()
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.
Stores data from the writer in the cache under a specific key and cache tag.
A cache tag is used to make sure the cache remains consistent. In most cases the cache tag
will be the bean type, this makes sure queries associated with a certain reference type will
never contain conflicting data.
Why not use the cache tag as a key? Well
we need to make sure the cache contents fits the key (and key is based on the cache values).
Otherwise it would be possible to store two different result sets under the same key (the cache tag).
In previous versions you could only store one key-entry, I have changed this to
improve caching efficiency (issue #400).