C_SELECT_SNIPPET_FOR_UPDATE
C_SELECT_SNIPPET_FOR_UPDATE
Constant: Select Snippet 'FOR UPDATE'
RedBeanPHP PostgreSQL Query Writer.
This is a QueryWriter class for RedBeanPHP. This QueryWriter provides support for the PostgreSQL database platform.
$adapter : \RedBeanPHP\Adapter\DBAdapter
setDDLTemplate(string $type, string $beanType, string $template) : void
Sets a data definition template to change the data creation statements per type.
For instance to add ROW_FORMAT=DYNAMIC to all MySQL tables upon creation:
$sql = $writer->getDDLTemplate( 'createTable', '' );
$writer->setDDLTemplate( 'createTable', '', $sql . ' ROW_FORMAT=DYNAMIC ' );
For property-specific templates set $beanType to: account.username -- then the template will only be applied to SQL statements relating to that column/property.
string | $type | ( 'createTable' | 'widenColumn' | 'addColumn' ) |
string | $beanType | ( type of bean or '*' to apply to all types ) |
string | $template | SQL template, contains %s for slots |
getDDLTemplate(string $type, string $beanType = '*', string|NULL $property = NULL) : string
Returns the specified data definition template.
If no template can be found for the specified type, the template for '*' will be returned instead.
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 |
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.
boolean | $flag | TRUE or FALSE |
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.
boolean | $flag | TRUE or FALSE |
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.
boolean | $narrowField | TRUE = Narrow Field FALSE = Wide Field |
setSQLFilters( $sqlFilters, $safeMode = FALSE) : void
Sets SQL filters.
This is a lowlevel method to set the SQL filter array. The format of this array is:
Example: 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(). 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.
table to be escaped omit quotes Constructor
Most of the time, you do not need to use this constructor,
since the facade takes care of constructing and wiring the
RedBeanPHP core objects. However if you would like to
assemble an OODB instance yourself, this is how it works: Usage: The example above creates the 3 RedBeanPHP core objects:
the Adapter, the Query Writer and the OODB instance and
wires them together. The example also demonstrates some of
the methods that can be used with OODB, as you see, they
closely resemble their facade counterparts. The wiring process: create an RPDO instance using your database
connection parameters. Create a database adapter from the RPDO
object and pass that to the constructor of the writer. Next,
create an OODB instance from the writer. Now you have an OODB
object. Database Adapter This method returns the datatype to be used for primary key IDS and
foreign keys. Returns one if the data type constants. This method will create a table for the bean. This methods accepts a type and infers the corresponding table name. type of bean you want to create a table for 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. 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. value 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. description whether you want to get codes for special columns as well This method will add a UNIQUE constraint index to a table on columns $columns. This methods accepts a type and infers the corresponding table name. target bean type 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. SQL state to consider list of standardized SQL state constants to check against 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 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. type to add index to name of the new index field to index 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. type that will have a foreign key field points to this type field that contains the foreign key value field where the fk points to whether target is dependent and should cascade on update/delete Determines whether a string can be considered JSON or not. This is used by writers that support JSON columns. However
we don't want that code duplicated over all JSON supporting
Query Writers. value to determine 'JSONness' of. Given a type and a property name this method
returns the foreign key map section associated with this pair. name of the type name of the property 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: the bean type you wish to obtain a key map of 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 the column of the key in the source table the type (table) where the key points to the target column of the foreign key (mostly just 'id') Returns an SQL Filter snippet for reading. type of bean 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. list of additional bindings start counter at... 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. magic number constant assigned to this data type SQL column definition (e.g. INT(11)) Returns the insert suffix SQL Snippet table $sql SQL Snippet 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. value to be checked. Inserts a record into the database using a series of insert columns
and corresponding insertvalues. Returns the insert id. columns to be inserted values to be inserted Checks table name or column name. Returns a cache key for the cache values passed. This method returns a fingerprint string to be used as a key to store
data in the writer cache. key-value to generate key for Returns the values associated with the provided cache tag and key. cache tag to use for lookup key to use for lookup Checks if the previous query had a keep-cache tag. If so, the cache will persist, otherwise the cache will be flushed. Returns TRUE if the cache will remain and FALSE if a flush has
been performed. 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). cache tag (secondary key) key to store values under rows or count to be stored Creates an SQL snippet from a list of conditions of format: list of conditions parameter bindings for SQL snippet additional SQL snippet to append to result Returns the table names and column names for a relational query. type of the source bean type of the bean you want to obtain using the relation TRUE if you want to omit quotes Returns or counts 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. the bean type you want to query an array of strings, each string containing a tag title if TRUE only return records that have been associated with ALL the tags in the list addition SQL snippet, for pagination parameter bindings for additional SQL snippet SQL wrapper string (use %s for subquery)
array(
'<MODE, i.e. 'r' for read, 'w' for write>' => array(
'
' => array(
'
array(
QueryWriter::C_SQLFILTER_READ => array(
'book' => array(
'title' => ' LOWER(book.title) '
)
)
Parameters
$sqlFilters
$safeMode
setSQLSelectSnippet()
setSQLSelectSnippet( $sqlSelectSnippet = '')
Parameters
$sqlSelectSnippet
safeTable()
safeTable(string $table, boolean $noQuotes = FALSE) : string
Parameters
string
$table
boolean
$noQuotes
Returns
string
Deprecated
Use esc() instead.
Tags
None found
Tags
None found __construct()
__construct(\RedBeanPHP\Adapter $adapter)
$database = new RPDO( $dsn, $user, $pass );
$adapter = new DBAdapter( $database );
$writer = new PostgresWriter( $adapter );
$oodb = new OODB( $writer, FALSE );
$bean = $oodb->dispense( 'bean' );
$bean->name = 'coffeeBean';
$id = $oodb->store( $bean );
$bean = $oodb->load( 'bean', $id );
Parameters
\RedBeanPHP\Adapter
$adapter
Tags
None found getTypeForID()
getTypeForID() : integer
Returns
integer
Tags
None found
Tags
None found createTable()
createTable(string $type) : void
Parameters
string
$type
Tags
None found getColumns()
getColumns( $table) : array
Parameters
$table
Returns
array
Tags
None found scanType()
scanType(mixed $value, $flagSpecial = FALSE) : integer
Parameters
mixed
$value
$flagSpecial
Returns
integer
Tags
None found code()
code(string $typedescription, boolean $includeSpecials = FALSE) : integer
Parameters
string
$typedescription
boolean
$includeSpecials
Returns
integer
Tags
None found addUniqueConstraint()
addUniqueConstraint(string $type, $properties) : void
Parameters
string
$type
$properties
Tags
None found sqlStateIn()
sqlStateIn(string $state, array $list, array $extraDriverDetails = array()) : boolean
Parameters
string
$state
array
$list
array
$extraDriverDetails
Returns
boolean
Tags
None found addIndex()
addIndex(string $type, string $name, string $property) : void
Parameters
string
$type
string
$name
string
$property
Tags
None found addFK()
addFK(string $type, string $targetType, string $property, string $targetProperty, boolean $isDep = FALSE) : void
Parameters
string
$type
string
$targetType
string
$property
string
$targetProperty
boolean
$isDep
Tags
None found
Tags
None found isJSON()
isJSON(string $value) : boolean
Parameters
string
$value
Returns
boolean
Tags
None found getForeignKeyForTypeProperty()
getForeignKeyForTypeProperty(string $type, string $property) : array|NULL
Parameters
string
$type
string
$property
Returns
array|NULL
Tags
None found getKeyMapForType()
getKeyMapForType(string $type) : array
array(
'name' =>
Parameters
string
$type
Returns
array
Tags
None found makeFKLabel()
makeFKLabel(string $from, string $type, string $to) : string
Parameters
string
$from
string
$type
string
$to
Returns
string
Tags
None found getSQLFilterSnippet()
getSQLFilterSnippet(string $type) : string
Parameters
string
$type
Returns
string
Tags
None found getParametersForInClause()
getParametersForInClause( $valueList, array $otherBindings, integer $offset) : string
Parameters
$valueList
array
$otherBindings
integer
$offset
Returns
string
Tags
None found addDataType()
addDataType(integer $dataTypeID, string $SQLDefinition) : self
Parameters
integer
$dataTypeID
string
$SQLDefinition
Returns
self
Tags
None found getInsertSuffix()
getInsertSuffix(string $table) : string
Parameters
string
$table
Returns
string
—
Tags
None found startsWithZeros()
startsWithZeros(string $value) : boolean
Parameters
string
$value
Returns
boolean
Tags
None found insertRecord()
insertRecord( $type, array $insertcolumns, array $insertvalues) : integer
Parameters
$type
array
$insertcolumns
array
$insertvalues
Returns
integer
Tags
None found check()
check( $struct) : string
Parameters
$struct
Returns
string
Tags
None found getCacheKey()
getCacheKey(array $keyValues) : string
Parameters
array
$keyValues
Returns
string
Tags
None found getCached()
getCached(string $cacheTag, string $key) : mixed
Parameters
string
$cacheTag
string
$key
Returns
mixed
Tags
None found updateCache()
updateCache() : boolean
Returns
boolean
Tags
None found putResultInCache()
putResultInCache(string $cacheTag, string $key, array|integer $values) : void
Parameters
string
$cacheTag
string
$key
array|integer
$values
Tags
None found makeSQLFromConditions()
makeSQLFromConditions(array $conditions, array $bindings, string $addSql = '') : string
array(
key => array(
value1, value2, value3 ....
)
)
Parameters
array
$conditions
array
$bindings
string
$addSql
Returns
string
Tags
None found getRelationalTablesAndColumns()
getRelationalTablesAndColumns(string $sourceType, string $destType, boolean $noQuote = FALSE) : array
Parameters
string
$sourceType
string
$destType
boolean
$noQuote
Returns
array
Tags
None found queryTaggedGeneric()
queryTaggedGeneric(string $type, array $tagList, boolean $all = FALSE, string $addSql = '', array $bindings = array(), string $wrap = '%s') : array
Parameters
string
$type
array
$tagList
boolean
$all
string
$addSql
array
$bindings
string
$wrap
Returns
array
Tags
None found