Class Sqlserver
Dbo layer for Microsoft's official SQLServer driver
A Dbo layer for MS SQL Server 2005 and higher. Requires the
pdo_sqlsrv
extension to be enabled.
- Object
- DataSource
- DboSource
- Sqlserver
Link: http://www.php.net/manual/en/ref.pdo-sqlsrv.php
Copyright: Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
License: MIT License
Location: Cake/Model/Datasource/Database/Sqlserver.php
Constants summary
-
string
ROW_COUNTER
¶'_cake_page_rownum_'
Properties summary
-
$_baseConfig
protectedarray
Base configuration settings for MS SQL driver -
$_fieldMappings
protectedarray
Creates a map between field aliases and numeric indexes. Workaround for the SQL Server driver's 30-character column name limitation.
-
$_lastAffected
protectedmixed
Storing the last affected value -
$columns
publicarray
MS SQL column definition -
$description
publicstring
Driver description -
$endQuote
publicstring
Ending quote character for quoted identifiers -
$startQuote
publicstring
Starting quote character for quoted identifiers
Inherited Properties
-
_connection
,_methodCacheChange
,_queriesCnt
,_queriesLog
,_queriesLogMax
,_queriesTime
,_queryCache
,_queryDefaults
,_result
,_sqlOps
,_transactionNesting
,affected
,alias
,cacheMethods
,configKeyName
,fieldParameters
,fullDebug
,index
,methodCache
,numRows
,tableParameters
,took
,useNestedTransactions
,virtualFieldSeparator
_descriptions
,_sources
,_transactionStarted
,cacheSources
,config
,connected
Method Summary
-
_dropTable() protected
Generate a "drop table" statement for the given table -
_execute() protected
Executes given SQL statement. -
_getPrimaryKey() protected
Makes sure it will return the primary key -
buildColumn() public
Generate a database-native column schema string -
buildIndex() public
Format indexes for create table -
column() public
Converts database-layer column types to basic types -
connect() public
Connects to the database using options in the given configuration array. -
create() public
Generates and executes an SQL INSERT statement for given model, fields, and values. Removes Identity (primary key) column from update data before returning to parent, if value is empty.
-
describe() public
Returns an array of the fields in given table name. -
enabled() public
Check that PDO SQL Server is installed/loaded -
fetchResult() public
Fetches the next row from the current result set. Eats the magic ROW_COUNTER variable.
-
fields() public
Generates the fields list of an SQL query. -
getSchemaName() public
Gets the schema name -
insertMulti() public
Inserts multiple values into a table -
lastAffected() public
Returns number of affected rows in previous database operation. If no previous operation exists, this returns false.
-
length() public
Handle SQLServer specific length properties. SQLServer handles text types as nvarchar/varchar with a length of -1.
-
limit() public
Returns a limit statement in the correct format for the particular database. -
listSources() public
Returns an array of sources (tables) in the database. -
read() public
Returns an array of all result rows for a given SQL query. Returns false if no rows matched.
-
renderStatement() public
Builds final SQL statement -
resultSet() public
Builds a map of the columns contained in a result -
update() public
Generates and executes an SQL UPDATE statement for given model, fields, and values. Removes Identity (primary key) column from update data before returning to parent.
-
value() public
Returns a quoted and escaped string of $data for use in an SQL statement.
Method Detail
_dropTable() protected ¶
_dropTable( type $table )
Generate a "drop table" statement for the given table
Parameters
- type $table
- Name of the table to drop
Returns
Drop table SQL statement
Overrides
_execute() protected ¶
_execute( string $sql , array $params = array() , array $prepareOptions = array() )
Executes given SQL statement.
Parameters
- string $sql
- SQL statement
- array $params optional array()
- list of params to be bound to query (supported only in select)
- array $prepareOptions optional array()
- Options to be used in the prepare statement
Returns
PDOStatement if query executes with no problem, true as the result of a successful, false on error query returning no rows, such as a CREATE statement, false otherwise
Throws
Overrides
_getPrimaryKey() protected ¶
_getPrimaryKey( Model
|string $model )
Makes sure it will return the primary key
Parameters
-
Model
|string $model - Model instance of table name
Returns
buildColumn() public ¶
buildColumn( array $column )
Generate a database-native column schema string
Parameters
- array $column
An array structured like the following: array('name'=>'value', 'type'=>'value'[, options]), where options can be 'default', 'length', or 'key'.
Returns
Overrides
buildIndex() public ¶
buildIndex( array $indexes , string $table = null )
Format indexes for create table
Parameters
- array $indexes
- The indexes to build
- string $table optional null
- The table to make indexes for.
Returns
Overrides
column() public ¶
column( mixed $real )
Converts database-layer column types to basic types
Parameters
- mixed $real
Either the string value of the fields type. or the Result object from Sqlserver::describe()
Returns
Abstract column type (i.e. "string")
Overrides
connect() public ¶
connect( )
Connects to the database using options in the given configuration array.
Returns
True if the database could be connected, else false
Throws
create() public ¶
create( Model
$model , array $fields = null , array $values = null )
Generates and executes an SQL INSERT statement for given model, fields, and values. Removes Identity (primary key) column from update data before returning to parent, if value is empty.
Parameters
-
Model
$model - The model to insert into.
- array $fields optional null
- The fields to set.
- array $values optional null
- The values to set.
Returns
Overrides
describe() public ¶
describe( Model
|string $model )
Returns an array of the fields in given table name.
Parameters
-
Model
|string $model - Model object to describe, or a string table name.
Returns
Fields in table. Keys are name and type
Throws
Overrides
fetchResult() public ¶
fetchResult( )
Fetches the next row from the current result set. Eats the magic ROW_COUNTER variable.
Returns
Overrides
fields() public ¶
fields( Model
$model , string $alias = null , array $fields = array() , boolean $quote = true )
Generates the fields list of an SQL query.
Parameters
-
Model
$model - The model to get fields for.
- string $alias optional null
- Alias table name
- array $fields optional array()
- The fields so far.
- boolean $quote optional true
- Whether or not to quote identfiers.
Returns
Overrides
insertMulti() public ¶
insertMulti( string $table , string $fields , array $values )
Inserts multiple values into a table
Parameters
- string $table
- The table to insert into.
- string $fields
- The fields to set.
- array $values
- The values to set.
Overrides
lastAffected() public ¶
lastAffected( mixed $source = null )
Returns number of affected rows in previous database operation. If no previous operation exists, this returns false.
Parameters
- mixed $source optional null
- Unused
Returns
Number of affected rows
Overrides
length() public ¶
length( mixed $length )
Handle SQLServer specific length properties. SQLServer handles text types as nvarchar/varchar with a length of -1.
Parameters
- mixed $length
- Either the length as a string, or a Column descriptor object.
Returns
null|integer with length of column.
Overrides
limit() public ¶
limit( integer $limit , integer $offset = null )
Returns a limit statement in the correct format for the particular database.
Parameters
- integer $limit
- Limit of results returned
- integer $offset optional null
- Offset from which to start results
Returns
SQL limit/offset statement
Overrides
listSources() public ¶
listSources( mixed $data = null )
Returns an array of sources (tables) in the database.
Parameters
- mixed $data optional null
- The names
Returns
Array of table names in the database
Overrides
read() public ¶
read( Model
$model , array $queryData = array() , integer $recursive = null )
Returns an array of all result rows for a given SQL query. Returns false if no rows matched.
Parameters
-
Model
$model - The model to read from
- array $queryData optional array()
- The query data
- integer $recursive optional null
- How many layers to go.
Returns
Array of resultset rows, or false if no rows matched
Overrides
renderStatement() public ¶
renderStatement( string $type , array $data )
Builds final SQL statement
Parameters
- string $type
- Query type
- array $data
- Query data
Returns
Overrides
resultSet() public ¶
resultSet( PDOStatement $results )
Builds a map of the columns contained in a result
Parameters
- PDOStatement $results
- The result to modify.
update() public ¶
update( Model
$model , array $fields = array() , array $values = null , mixed $conditions = null )
Generates and executes an SQL UPDATE statement for given model, fields, and values. Removes Identity (primary key) column from update data before returning to parent.
Parameters
-
Model
$model - The model to update.
- array $fields optional array()
- The fields to set.
- array $values optional null
- The values to set.
- mixed $conditions optional null
- The conditions to use.
Returns
Overrides
value() public ¶
value( string $data , string $column = null )
Returns a quoted and escaped string of $data for use in an SQL statement.
Parameters
- string $data
- String to be prepared for use in an SQL statement
- string $column optional null
- The column into which this data will be inserted
Returns
Quoted and escaped data
Overrides
Methods inherited from DboSource
__construct() public ¶
__construct( array $config = null , boolean $autoConnect = true )
Constructor
Parameters
- array $config optional null
- Array of configuration information for the Datasource.
- boolean $autoConnect optional true
- Whether or not the datasource should automatically connect.
Throws
Overrides
__destruct() public ¶
__destruct( )
Used for storing in cache the results of the in-memory methodCache
Overrides
_buildFieldParameters() protected ¶
_buildFieldParameters( string $columnString , array $columnData , string $position )
Build the field parameters, in a position
Parameters
- string $columnString
- The partially built column string
- array $columnData
- The array of column data.
- string $position
- The position type to use. 'beforeDefault' or 'afterDefault' are common
Returns
a built column with the field parameters added.
_constructVirtualFields() protected ¶
_constructVirtualFields( Model
$Model , string $alias , array $fields )
Converts model virtual fields into sql expressions to be fetched later
Parameters
-
Model
$Model - The model to get virtual fields for.
- string $alias
- Alias table name
- array $fields
- virtual fields to be used on query
Returns
_fetchHasAndBelongsToMany() protected ¶
_fetchHasAndBelongsToMany( Model
$Model , string $query , array $ids , string $association )
Fetch 'hasAndBelongsToMany' associations.
Parameters
-
Model
$Model - Primary model object.
- string $query
- Association query.
- array $ids
- Array of IDs of associated records.
- string $association
- Association name.
Returns
Association results.
_fetchHasMany() protected ¶
_fetchHasMany( Model
$Model , string $query , array $ids )
Fetch 'hasMany' associations.
Parameters
-
Model
$Model - Primary model object.
- string $query
- Association query template.
- array $ids
- Array of IDs of associated records.
Returns
Association results.
_filterResults() protected ¶
_filterResults( array $resultSet , Model
$Model , array $filtered = array() )
Passes association results through afterFind filters of the corresponding model.
The primary model is always excluded, because the filtering is later done by Model::_filterResults().
Parameters
- array $resultSet
- $resultSet Reference of resultset to be filtered.
-
Model
$Model - Instance of model to operate against.
- array $filtered optional array()
- List of classes already filtered, to be skipped.
Returns
Array of results that have been filtered through $Model->afterFind.
_getJoins() protected ¶
_getJoins( Model
$Model )
Returns an array of SQL JOIN conditions from a model's associations.
Parameters
-
Model
$Model - The model to get joins for.2
Returns
_matchRecords() protected ¶
_matchRecords( Model
$Model , mixed $conditions = null )
Gets a list of record IDs for the given conditions. Used for multi-record updates and deletes in databases that do not support aliases in UPDATE/DELETE queries.
Parameters
-
Model
$Model - The model to find matching records for.
- mixed $conditions optional null
- The conditions to match against.
Returns
List of record IDs
_mergeAssociation() protected ¶
_mergeAssociation( array $data , array $merge , string $association , string $type , boolean $selfJoin = false )
Merge association of merge into data
Parameters
- array $data
- $data The data to merge.
- array $merge
- $merge The data to merge.
- string $association
- The association name to merge.
- string $type
- The type of association
- boolean $selfJoin optional false
- Whether or not this is a self join.
_mergeConditions() protected ¶
_mergeConditions( mixed $query , mixed $assoc )
Merges a mixed set of string/array conditions.
Parameters
- mixed $query
- The query to merge conditions for.
- mixed $assoc
- The association names.
Returns
_mergeHasMany() protected ¶
_mergeHasMany( array $resultSet , array $assocResultSet , string $association , Model
$Model )
Merge the results of 'hasMany' associations.
Note: this function also deals with the formatting of the data.
Parameters
- array $resultSet
- $resultSet Data to merge into.
- array $assocResultSet
- Data to merge.
- string $association
- Name of Model being merged.
-
Model
$Model - Model being merged onto.
_parseKey() protected ¶
_parseKey( string $key , mixed $value , Model
$Model = null )
Extracts a Model.field identifier and an SQL condition operator from a string, formats and inserts values, and composes them into an SQL snippet.
Parameters
- string $key
- An SQL key snippet containing a field and optional SQL operator
- mixed $value
- The value(s) to be inserted in the string
-
Model
$Model optional null - Model object initiating the query
Returns
_prepareUpdateFields() protected ¶
_prepareUpdateFields( Model
$Model , array $fields , boolean $quoteValues = true , boolean $alias = false )
Quotes and prepares fields and values for an SQL UPDATE statement
Parameters
-
Model
$Model - The model to prepare fields for.
- array $fields
- The fields to update.
- boolean $quoteValues optional true
- If values should be quoted, or treated as SQL snippets
- boolean $alias optional false
- Include the model alias in the field name
Returns
Fields and values, quoted and prepared
_quoteFields() protected ¶
_quoteFields( string $conditions )
Quotes Model.fields
Parameters
- string $conditions
- The conditions to quote.
Returns
or false if no match
_quoteMatchedField() protected ¶
_quoteMatchedField( string $match )
Auxiliary function to quote matches Model.fields
from a preg_replace_callback call
Parameters
- string $match
- matched string
Returns
quoted string
_scrubQueryData() protected ¶
_scrubQueryData( array $data )
Private helper method to remove query metadata in given data array.
Parameters
- array $data
- The data to scrub.
Returns
_writeQueryCache() protected ¶
_writeQueryCache( string $sql , mixed $data , array $params = array() )
Writes a new key for the in memory sql query cache
Parameters
- string $sql
- SQL query
- mixed $data
- result of $sql query
- array $params optional array()
- query params bound as values
alterSchema() public ¶
alterSchema( mixed $compare , string $table = null )
Generate an alter syntax from CakeSchema::compare()
Parameters
- mixed $compare
- The comparison data.
- string $table optional null
- The table name.
Returns
begin() public ¶
begin( )
Begin a transaction
Returns
True on success, false on fail (i.e. if the database/model does not support transactions, or a transaction has not started).
Overrides
boolean() public ¶
boolean( mixed $data , boolean $quote = false )
Translates between PHP boolean values and Database (faked) boolean values
Parameters
- mixed $data
- Value to be translated
- boolean $quote optional false
- Whether or not the field should be cast to a string.
Returns
Converted boolean value
buildAssociationQuery() public ¶
buildAssociationQuery( Model
$Model , array $queryData )
Builds an SQL statement.
This is merely a convenient wrapper to DboSource::buildStatement().
Parameters
-
Model
$Model - The model to build an association query for.
- array $queryData
- An array of queryData information containing keys similar to Model::find().
Returns
String containing an SQL statement.
See
buildJoinStatement() public ¶
buildJoinStatement( array $join )
Builds and generates a JOIN condition from an array. Handles final clean-up before conversion.
Parameters
- array $join
- An array defining a JOIN condition in a query.
Returns
An SQL JOIN condition to be used in a query.
See
DboSource::buildStatement()
buildStatement() public ¶
buildStatement( array $query , Model
$Model )
Builds and generates an SQL statement from an array. Handles final clean-up before conversion.
Parameters
- array $query
- An array defining an SQL query.
-
Model
$Model - The model object which initiated the query.
Returns
An executable SQL statement.
See
buildTableParameters() public ¶
buildTableParameters( array $parameters , string $table = null )
Format parameters for create table
Parameters
- array $parameters
- The parameters to create SQL for.
- string $table optional null
- The table name.
Returns
cacheMethod() public ¶
cacheMethod( string $method , string $key , mixed $value = null )
Cache a value into the methodCaches. Will respect the value of DboSource::$cacheMethods. Will retrieve a value from the cache if $value is null.
If caching is disabled and a write is attempted, the $value will be returned. A read will either return the value or null.
Parameters
- string $method
- Name of the method being cached.
- string $key
- The key name for the cache operation.
- mixed $value optional null
- The value to cache into memory.
Returns
Either null on failure, or the value if its set.
calculate() public ¶
calculate( Model
$Model , string $func , array $params = array() )
Returns an SQL calculation, i.e. COUNT() or MAX()
Parameters
-
Model
$Model - The model to get a calculated field for.
- string $func
- Lowercase name of SQL function, i.e. 'count' or 'max'
- array $params optional array()
- Function parameters (any values must be quoted manually)
Returns
An SQL calculation function
close() public ¶
close( )
Disconnects database, kills the connection and says the connection is closed.
Overrides
commit() public ¶
commit( )
Commit a transaction
Returns
True on success, false on fail (i.e. if the database/model does not support transactions, or a transaction has not started).
Overrides
conditionKeysToString() public ¶
conditionKeysToString( array $conditions , boolean $quoteValues = true , Model
$Model = null )
Creates a WHERE clause by parsing given conditions array. Used by DboSource::conditions().
Parameters
- array $conditions
- Array or string of conditions
- boolean $quoteValues optional true
- If true, values should be quoted
-
Model
$Model optional null - A reference to the Model instance making the query
Returns
SQL fragment
conditions() public ¶
conditions( mixed $conditions , boolean $quoteValues = true , boolean $where = true , Model
$Model = null )
Creates a WHERE clause by parsing given conditions data. If an array or string conditions are provided those conditions will be parsed and quoted. If a boolean is given it will be integer cast as condition. Null will return 1 = 1.
Results of this method are stored in a memory cache. This improves performance, but because the method uses a hashing algorithm it can have collisions. Setting DboSource::$cacheMethods to false will disable the memory cache.
Parameters
- mixed $conditions
- Array or string of conditions, or any value.
- boolean $quoteValues optional true
- If true, values should be quoted
- boolean $where optional true
- If true, "WHERE " will be prepended to the return value
-
Model
$Model optional null - A reference to the Model instance making the query
Returns
SQL fragment
createSchema() public ¶
createSchema( CakeSchema
$schema , string $tableName = null )
Generate a database-native schema for the given Schema object
Parameters
-
CakeSchema
$schema - An instance of a subclass of CakeSchema
- string $tableName optional null
Optional. If specified only the table name given will be generated. Otherwise, all tables defined in the schema are generated.
Returns
defaultConditions() public ¶
defaultConditions( Model
$Model , string|array|boolean $conditions , boolean $useAlias = true )
Creates a default set of conditions from the model if $conditions is null/empty. If conditions are supplied then they will be returned. If a model doesn't exist and no conditions were provided either null or false will be returned based on what was input.
Parameters
-
Model
$Model - The model to get conditions for.
- string|array|boolean $conditions
Array of conditions, conditions string, null or false. If an array of conditions, or string conditions those conditions will be returned. With other values the model's existence will be checked. If the model doesn't exist a null or false will be returned depending on the input value.
- boolean $useAlias optional true
- Use model aliases rather than table names when generating conditions
Returns
Either null, false, $conditions or an array of default conditions to use.
See
DboSource::conditions()
delete() public ¶
delete( Model
$Model , mixed $conditions = null )
Generates and executes an SQL DELETE statement. For databases that do not support aliases in UPDATE queries.
Parameters
-
Model
$Model - The model to delete from
- mixed $conditions optional null
- The conditions to use. If empty the model's primary key will be used.
Returns
Success
Overrides
dropSchema() public ¶
dropSchema( CakeSchema
$schema , string $table = null )
Generate a "drop table" statement for the given Schema object
Parameters
-
CakeSchema
$schema - An instance of a subclass of CakeSchema
- string $table optional null
Optional. If specified only the table name given will be generated. Otherwise, all tables defined in the schema are generated.
Returns
execute() public ¶
execute( string $sql , array $options = array() , array $params = array() )
Queries the database with given SQL statement, and obtains some metadata about the result (rows affected, timing, any errors, number of rows in resultset). The query is also logged. If Configure::read('debug') is set, the log is shown all the time, else it is only shown on errors.
Options
- log - Whether or not the query should be logged to the memory log.
Parameters
- string $sql
- SQL statement
- array $options optional array()
- The options for executing the query.
- array $params optional array()
- values to be bound to the query.
Returns
Resource or object representing the result set, or false on failure
expression() public ¶
expression( string $expression )
Returns an object to represent a database expression in a query. Expression objects are not sanitized or escaped.
Parameters
- string $expression
- An arbitrary SQL expression to be inserted into a query.
Returns
An object representing a database expression to be used in a query
fetchAll() public ¶
fetchAll( string $sql , array|boolean $params = array() , array $options = array() )
Returns an array of all result rows for a given SQL query.
Returns false if no rows matched.
Options
cache
- Returns the cached version of the query, if exists and stores the result in cache. This is a non-persistent cache, and only lasts for a single request. This option defaults to true. If you are directly calling this method, you can disable caching by setting $options tofalse
Parameters
- string $sql
- SQL statement
- array|boolean $params optional array()
Either parameters to be bound as values for the SQL statement, or a boolean to control query caching.
- array $options optional array()
- additional options for the query.
Returns
Array of resultset rows, or false if no rows matched
fetchAssociated() public ¶
fetchAssociated( Model
$Model , string $query , array $ids )
Fetch 'hasMany' associations.
This is just a proxy to maintain BC.
Parameters
-
Model
$Model - Primary model object.
- string $query
- Association query template.
- array $ids
- Array of IDs of associated records.
Returns
Association results.
See
fetchRow() public ¶
fetchRow( string $sql = null )
Returns a row from current resultset as an array
Parameters
- string $sql optional null
- Some SQL to be executed.
Returns
The fetched row as an array
fetchVirtualField() public ¶
fetchVirtualField( array $result )
Modifies $result array to place virtual fields in model entry where they belongs to
Parameters
- array $result
- $result Reference to the fetched row
field() public ¶
field( string $name , string $sql )
Returns a single field of the first of query results for a given SQL query, or false if empty.
Parameters
- string $name
- Name of the field
- string $sql
- SQL query
Returns
Value of field read.
flushMethodCache() public ¶
flushMethodCache( )
Empties the method caches. These caches are used by DboSource::name() and DboSource::conditions()
fullTableName() public ¶
fullTableName( Model
|string $model , boolean $quote = true , boolean $schema = true )
Gets full table name including prefix
Parameters
-
Model
|string $model - Either a Model object or a string table name.
- boolean $quote optional true
- Whether you want the table name quoted.
- boolean $schema optional true
- Whether you want the schema name included.
Returns
Full quoted table name
generateAssociationQuery() public ¶
generateAssociationQuery( Model
$Model , Model
|null $LinkModel , string $type , string $association , array $assocData , array $queryData , boolean $external )
Generates a query or part of a query from a single model or two associated models.
Builds a string containing an SQL statement template.
Parameters
-
Model
$Model - Primary Model object.
-
Model
|null $LinkModel - Linked model object.
- string $type
- Association type, one of the model association types ie. hasMany.
- string $association
- Association name.
- array $assocData
- Association data.
- array $queryData
- $queryData An array of queryData information containing keys similar to Model::find().
- boolean $external
- Whether or not the association query is on an external datasource.
Returns
String representing a query. True, when $external is false and association $type is 'hasOne' or 'belongsTo'.
getConstraint() public ¶
getConstraint( string $type , Model
$Model , Model
$LinkModel , string $association , array $assocData , string $association2 = null )
Returns a conditions array for the constraint between two models.
Parameters
Returns
Conditions array defining the constraint between $Model and $LinkModel.
getLog() public ¶
getLog( boolean $sorted = false , boolean $clear = true )
Get the query log as an array.
Parameters
- boolean $sorted optional false
- Get the queries sorted by time taken, defaults to false.
- boolean $clear optional true
- If True the existing log will cleared.
Returns
Array of queries run as an array
getQueryCache() public ¶
getQueryCache( string $sql , array $params = array() )
Returns the result for a sql query if it is already cached
Parameters
- string $sql
- SQL query
- array $params optional array()
- query params bound as values
Returns
results for query if it is cached, false otherwise
getVersion() public ¶
getVersion( )
Gets the version string of the database server
Returns
The database version
group() public ¶
group( string|array $fields , Model
$Model = null )
Create a GROUP BY SQL clause.
Parameters
- string|array $fields
- Group By fields
-
Model
$Model optional null - The model to get group by fields for.
Returns
Group By clause or null.
hasAny() public ¶
hasAny( Model
$Model , string $sql )
Checks if the specified table contains any record matching specified SQL
Parameters
-
Model
$Model - Model to search
- string $sql
- SQL WHERE clause (condition only, not the "WHERE" part)
Returns
True if the table has a matching record, else false
hasResult() public ¶
hasResult( )
Checks if the result is valid
Returns
True if the result is valid else false
identifier() public ¶
identifier( string $identifier )
Returns an object to represent a database identifier in a query. Expression objects are not sanitized or escaped.
Parameters
- string $identifier
- A SQL expression to be used as an identifier
Returns
An object representing a database identifier to be used in a query
index() public ¶
index( string $model )
Returns an array of the indexes in given datasource name.
Parameters
- string $model
- Name of model to inspect
Returns
Fields in table. Keys are column and unique
introspectType() public ¶
introspectType( string $value )
Guesses the data type of an array
Parameters
- string $value
- The value to introspect for type data.
Returns
isConnected() public ¶
isConnected( )
Checks if the source is connected to the database.
Returns
True if the database is connected, else false
lastError() public ¶
lastError( PDOStatement $query = null )
Returns a formatted error message from previous database operation.
Parameters
- PDOStatement $query optional null
- the query to extract the error from if any
Returns
Error message with error number
lastInsertId() public ¶
lastInsertId( mixed $source = null )
Returns the ID generated from the previous INSERT operation.
Parameters
- mixed $source optional null
- The source to get an id for.
Returns
Overrides
lastNumRows() public ¶
lastNumRows( mixed $source = null )
Returns number of rows in previous resultset. If no previous resultset exists, this returns false.
Parameters
- mixed $source optional null
- Not used
Returns
Number of rows in resultset
Overrides
logQuery() public ¶
logQuery( string $sql , array $params = array() )
Log given SQL query.
Parameters
- string $sql
- SQL statement
- array $params optional array()
- Values binded to the query (prepared statements)
name() public ¶
name( mixed $data )
Returns a quoted name of $data for use in an SQL statement. Strips fields out of SQL functions before quoting.
Results of this method are stored in a memory cache. This improves performance, but because the method uses a hashing algorithm it can have collisions. Setting DboSource::$cacheMethods to false will disable the memory cache.
Parameters
- mixed $data
Either a string with a column to quote. An array of columns to quote or an object from DboSource::expression() or DboSource::identifier()
Returns
SQL field
nestedTransactionSupported() public ¶
nestedTransactionSupported( )
Check if the server support nested transactions
Returns
order() public ¶
order( array|string $keys , string $direction = 'ASC' , Model
$Model = null )
Returns an ORDER BY clause as a string.
Parameters
- array|string $keys
- Field reference, as a key (i.e. Post.title)
- string $direction optional 'ASC'
- Direction (ASC or DESC)
-
Model
$Model optional null - Model reference (used to look for virtual field)
Returns
ORDER BY clause
prepareFields() public ¶
prepareFields( Model
$Model , array $queryData )
Prepares fields required by an SQL statement.
When no fields are set, all the $Model fields are returned.
Parameters
-
Model
$Model - The model to prepare.
- array $queryData
- An array of queryData information containing keys similar to Model::find().
Returns
Array containing SQL fields.
queryAssociation() public ¶
queryAssociation( Model
$Model , Model
$LinkModel , string $type , string $association , array $assocData , array $queryData , boolean $external , array $resultSet , integer $recursive , array $stack )
Queries associations.
Used to fetch results on recursive models.
'hasMany' associations with no limit set: Fetch, filter and merge is done recursively for every level.
'hasAndBelongsToMany' associations: Fetch and filter is done unaffected by the (recursive) level set.
Parameters
-
Model
$Model - Primary Model object.
-
Model
$LinkModel - Linked model object.
- string $type
- Association type, one of the model association types ie. hasMany.
- string $association
- Association name.
- array $assocData
- Association data.
- array $queryData
- $queryData An array of queryData information containing keys similar to Model::find().
- boolean $external
- Whether or not the association query is on an external datasource.
- array $resultSet
- $resultSet Existing results.
- integer $recursive
- Number of levels of association.
- array $stack
- A list with joined models.
Returns
Throws
rawQuery() public ¶
rawQuery( string $sql , array $params = array() )
Executes given SQL statement.
Parameters
- string $sql
- SQL statement
- array $params optional array()
- Additional options for the query.
Returns
Resource or object representing the result set, or false on failure
readTableParameters() public ¶
readTableParameters( string $name )
Read additional table parameters
Parameters
- string $name
- The table name to read.
Returns
reconnect() public ¶
reconnect( array $config = array() )
Reconnects to database server with optional new settings
Parameters
- array $config optional array()
- An array defining the new configuration settings
Returns
True on success, false on failure
renderJoinStatement() public ¶
renderJoinStatement( array $data )
Renders a final SQL JOIN statement
Parameters
- array $data
- The data to generate a join statement for.
Returns
resetSequence() public ¶
resetSequence( string $table , string $column )
Reset a sequence based on the MAX() value of $column. Useful for resetting sequences after using insertMulti().
This method should be implemented by datasources that require sequences to be used.
Parameters
- string $table
- The name of the table to update.
- string $column
- The column to use when resetting the sequence value.
Returns
success.
resolveKey() public ¶
resolveKey( Model
$Model , string $key , string $assoc = null )
Returns a key formatted like a string Model.fieldname(i.e. Post.title, or Country.name)
Parameters
-
Model
$Model - The model to get a key for.
- string $key
- The key field.
- string $assoc optional null
- The association name.
Returns
Overrides
rollback() public ¶
rollback( )
Rollback a transaction
Returns
True on success, false on fail (i.e. if the database/model does not support transactions, or a transaction has not started).
Overrides
showLog() public ¶
showLog( boolean $sorted = false )
Outputs the contents of the queries log. If in a non-CLI environment the sql_log element will be rendered and output. If in a CLI environment, a plain text log is generated.
Parameters
- boolean $sorted optional false
- Get the queries sorted by time taken, defaults to false.
truncate() public ¶
truncate( Model
|string $table )
Deletes all the records in a table and resets the count of the auto-incrementing primary key, where applicable.
Parameters
-
Model
|string $table - A string or model class representing the table to be truncated
Returns
SQL TRUNCATE TABLE statement, false if not applicable.
Methods inherited from DataSource
_cacheDescription() protected ¶
_cacheDescription( string $object , mixed $data = null )
Cache the DataSource description
Parameters
- string $object
- The name of the object (model) to cache
- mixed $data optional null
- The description of the model, usually a string or array
Returns
insertQueryData() public ¶
insertQueryData( string $query , array $data , string $association , Model
$Model , array $stack )
Replaces {$__cakeID__$}
and {$__cakeForeignKey__$}
placeholders in query data.
Parameters
- string $query
- Query string needing replacements done.
- array $data
- Array of data with values that will be inserted in placeholders.
- string $association
- Name of association model being replaced.
-
Model
$Model - Model instance.
- array $stack
- The context stack.
Returns
String of query data with placeholders replaced, or false on failure.
setConfig() public ¶
setConfig( array $config = array() )
Sets the configuration for the DataSource. Merges the $config information with the _baseConfig and the existing $config property.
Parameters
- array $config optional array()
- The configuration array
Methods inherited from Object
_mergeVars() protected ¶
_mergeVars( array $properties , string $class , boolean $normalize = true )
Merges this objects $property with the property in $class' definition. This classes value for the property will be merged on top of $class'
This provides some of the DRY magic CakePHP provides. If you want to shut it off, redefine this method as an empty function.
Parameters
- array $properties
- The name of the properties to merge.
- string $class
- The class to merge the property with.
- boolean $normalize optional true
- Set to true to run the properties through Hash::normalize() before merging.
_set() protected ¶
_set( array $properties = array() )
Allows setting of multiple properties of the object in a single line of code. Will only set properties that are part of a class declaration.
Parameters
- array $properties optional array()
- An associative array containing properties and corresponding values.
_stop() protected ¶
_stop( integer|string $status = 0 )
Stop execution of the current script. Wraps exit() making testing easier.
Parameters
- integer|string $status optional 0
- see http://php.net/exit for values
dispatchMethod() public ¶
dispatchMethod( string $method , array $params = array() )
Calls a method on this object with the given parameters. Provides an OO wrapper
for call_user_func_array
Parameters
- string $method
- Name of the method to call
- array $params optional array()
- Parameter list to use when calling $method
Returns
Returns the result of the method call
log() public ¶
log( string $msg , integer $type = LOG_ERR , null|string|array $scope = null )
Convenience method to write a message to CakeLog. See CakeLog::write() for more information on writing to logs.
Parameters
- string $msg
- Log message
- integer $type optional LOG_ERR
- Error type constant. Defined in app/Config/core.php.
- null|string|array $scope optional null
The scope(s) a log message is being created in. See CakeLog::config() for more information on logging scopes.
Returns
Success of log write
requestAction() public ¶
requestAction( string|array $url , array $extra = array() )
Calls a controller's method from any location. Can be used to connect controllers together or tie plugins into a main application. requestAction can be used to return rendered views or fetch the return value from controller actions.
Under the hood this method uses Router::reverse() to convert the $url parameter into a string URL. You should use URL formats that are compatible with Router::reverse()
Passing POST and GET data
POST and GET data can be simulated in requestAction. Use $extra['url']
for
GET data. The $extra['data']
parameter allows POST data simulation.
Parameters
- string|array $url
String or array-based URL. Unlike other URL arrays in CakePHP, this URL will not automatically handle passed and named arguments in the $url parameter.
- array $extra optional array()
if array includes the key "return" it sets the AutoRender to true. Can also be used to submit GET/POST data, and named/passed arguments.
Returns
Boolean true or false on success/failure, or contents of rendered action if 'return' is set in $extra.
toString() public ¶
toString( )
Object-to-string conversion. Each class can override this method as necessary.
Returns
The name of this class
Properties detail
$_baseConfig ¶
Base configuration settings for MS SQL driver
array( 'persistent' => true, 'host' => 'localhost\SQLEXPRESS', 'login' => '', 'password' => '', 'database' => 'cake', 'schema' => '', 'flags' => array() )
$_fieldMappings ¶
Creates a map between field aliases and numeric indexes. Workaround for the SQL Server driver's 30-character column name limitation.
array()
$columns ¶
MS SQL column definition
array( 'primary_key' => array('name' => 'IDENTITY (1, 1) NOT NULL'), 'string' => array('name' => 'nvarchar', 'limit' => '255'), 'text' => array('name' => 'nvarchar', 'limit' => 'MAX'), 'integer' => array('name' => 'int', 'formatter' => 'intval'), 'biginteger' => array('name' => 'bigint'), 'numeric' => array('name' => 'decimal', 'formatter' => 'floatval'), 'decimal' => array('name' => 'decimal', 'formatter' => 'floatval'), 'float' => array('name' => 'float', 'formatter' => 'floatval'), 'real' => array('name' => 'float', 'formatter' => 'floatval'), 'datetime' => array('name' => 'datetime', 'format' => 'Y-m-d H:i:s', 'formatter' => 'date'), 'timestamp' => array('name' => 'timestamp', 'format' => 'Y-m-d H:i:s', 'formatter' => 'date'), 'time' => array('name' => 'datetime', 'format' => 'H:i:s', 'formatter' => 'date'), 'date' => array('name' => 'datetime', 'format' => 'Y-m-d', 'formatter' => 'date'), 'binary' => array('name' => 'varbinary'), 'boolean' => array('name' => 'bit') )