Class DboAdodb
AdoDB DBO implementation.
Database abstraction implementation for the AdoDB library.
- Object
- DataSource
- DboSource
- DboAdodb
Copyright: Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
License: The MIT License
Location: model/datasources/dbo/dbo_adodb.php
Properties summary
-
$_adodb
publicADOConnection
ADOConnection object with which we connect. -
$_adodbColumnTypes
publicarray
Array translating ADOdb column MetaTypes to cake-supported metatypes -
$columns
publicarray
ADOdb column definition -
$description
publicstring
Enter description here...
Inherited Properties
-
__bypass
,__sqlOps
,_commands
,alias
,fieldCache
,index
__descriptions
,_baseConfig
,_queriesCnt
,_queriesLog
,_queriesLogMax
,_queriesTime
,_queryCache
,_result
,_sources
,_transactionStarted
,affected
,cacheSources
,config
,configKeyName
,connected
,connection
,endQuote
,error
,fullDebug
,numRows
,startQuote
,took
_log
Method Summary
-
_execute() public
Executes given SQL statement. -
begin() public
Begin a transaction -
buildColumn() public
Generate a database-native column schema string -
column() public
Converts database-layer column types to basic types -
commit() public
Commit a transaction -
connect() public
Connects to the database using options in the given configuration array. -
describe() public
Returns an array of the fields in the table used by the given model. -
disconnect() public
Disconnects from database. -
enabled() public
Check that AdoDB is available. -
fetchResult() public
Fetches the next row from the current result set -
fetchRow() public
Returns a row from current resultset as an array . -
fields() public
Generates the fields list of an SQL query. -
hasResult() public
Checks if the result is valid -
lastAffected() public
Returns number of affected rows in previous database operation, or false if no previous operation exists. -
lastError() public
Returns a formatted error message from previous database operation. -
lastInsertId() public
Returns the ID generated from the previous INSERT operation. -
lastNumRows() public
Returns number of rows in previous resultset, or false if no previous resultset exists. -
limit() public
Returns a LIMIT statement in the correct format for the particular database. -
listSources() public
Returns an array of tables in the database. If there are no tables, an error is raised and the application exits. -
resultSet() public
Build ResultSets and map data -
rollback() public
Rollback a transaction -
value() public
Returns a quoted and escaped string of $data for use in an SQL statement.
Method Detail
_execute() public ¶
_execute( string $sql )
Executes given SQL statement.
Parameters
- string $sql
- SQL statement
Returns
Result resource identifier
begin() public ¶
begin( unknown_type $model )
Begin a transaction
Parameters
- unknown_type $model
Returns
True on success, false on fail (i.e. if the database/model does not support transactions).
Overrides
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
column() public ¶
column( string $real )
Converts database-layer column types to basic types
Parameters
- string $real
- Real database-layer column type (i.e. "varchar(255)")
Returns
Abstract column type (i.e. "string")
Overrides
commit() public ¶
commit( unknown_type $model )
Commit a transaction
Parameters
- unknown_type $model
Returns
True on success, false on fail (i.e. if the database/model does not support transactions, or a transaction has not started).
Overrides
connect() public ¶
connect( array $config ,… )
Connects to the database using options in the given configuration array.
Parameters
- array $config ,…
- Configuration array for connecting
describe() public ¶
describe( AppModel
$model )
Returns an array of the fields in the table used by the given model.
Parameters
-
AppModel
$model - Model object
Returns
Fields in table. Keys are name and type
Overrides
disconnect() public ¶
disconnect( )
Disconnects from database.
Returns
True if the database could be disconnected, else false
fetchResult() public ¶
fetchResult( )
Fetches the next row from the current result set
Returns
fetchRow() public ¶
fetchRow( $sql = null )
Returns a row from current resultset as an array .
Returns
The fetched row as an array
Overrides
fields() public ¶
fields( Model
$model , string $alias = null , mixed $fields = array() , boolean $quote = true )
Generates the fields list of an SQL query.
Parameters
-
Model
$model - string $alias optional null
- Alias tablename
- mixed $fields optional array()
- boolean $quote optional true
- If false, returns fields array unquoted
Returns
Overrides
hasResult() public ¶
hasResult( )
Checks if the result is valid
Returns
True if the result is valid, else false
Overrides
lastAffected() public ¶
lastAffected( )
Returns number of affected rows in previous database operation, or false if no previous operation exists.
Returns
Number of affected rows
Overrides
lastError() public ¶
lastError( )
Returns a formatted error message from previous database operation.
Returns
Error message
lastInsertId() public ¶
lastInsertId( )
Returns the ID generated from the previous INSERT operation.
Returns
Returns
Overrides
lastNumRows() public ¶
lastNumRows( )
Returns number of rows in previous resultset, or false if no previous resultset exists.
Returns
Number of rows in resultset
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( )
Returns an array of tables in the database. If there are no tables, an error is raised and the application exits.
Returns
Array of tablenames in the database
Overrides
resultSet() public ¶
resultSet( array $results )
Build ResultSets and map data
Parameters
- array $results
rollback() public ¶
rollback( unknown_type $model )
Rollback a transaction
Parameters
- unknown_type $model
Returns
True on success, false on fail (i.e. if the database/model does not support transactions, or a transaction has not started).
Overrides
value() public ¶
value( string $data , string $column = null , boolean $safe = false )
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
- $column_type The type of the column into which this data will be inserted
- boolean $safe optional false
- Whether or not numeric data should be handled automagically if no column data is provided
Returns
Quoted and escaped data
Overrides
Methods inherited from DboSource
__filterResults() public ¶
__filterResults( array $results , object $model , array $filtered = array() )
Private method. Passes association results thru afterFind filters of corresponding model
Parameters
- array $results
- Reference of resultset to be filtered
- object $model
- Instance of model to operate against
- array $filtered optional array()
- List of classes already filtered, to be skipped
Returns
__mergeAssociation() public ¶
__mergeAssociation( unknown_type $data , unknown_type $merge , unknown_type $association , unknown_type $type , boolean $selfJoin = false )
Enter description here...
Parameters
- unknown_type $data
- unknown_type $merge
- unknown_type $association
- unknown_type $type
- boolean $selfJoin optional false
__mergeConditions() public ¶
__mergeConditions( $query , $assoc )
Merges a mixed set of string/array conditions
Returns
__mergeHasMany() public ¶
__mergeHasMany( array $resultSet , array $merge , string $association , object $model , object $linkModel )
mergeHasMany - Merge the results of hasMany relations.
Parameters
- array $resultSet
- Data to merge into
- array $merge
- Data to merge
- string $association
- Name of Model being Merged
- object $model
- Model being merged onto
- object $linkModel
- Model being merged
__parseKey() public ¶
__parseKey( Model
$model , string $key , mixed $value )
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
-
Model
$model - Model object initiating the query
- string $key
- An SQL key snippet containing a field and optional SQL operator
- mixed $value
- The value(s) to be inserted in the string
Returns
__quoteFields() public ¶
__quoteFields( string $conditions )
Quotes Model.fields
Parameters
- string $conditions
Returns
or false if no match
__scrubQueryData() public ¶
__scrubQueryData( array $data )
Private helper method to remove query metadata in given data array.
Parameters
- array $data
Returns
_getJoins() public ¶
_getJoins( object $model )
Returns an array of SQL JOIN fragments from a model's associations
Parameters
- object $model
Returns
_matchRecords() public ¶
_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 - mixed $conditions optional null
Returns
List of record IDs
_prepareUpdateFields() public ¶
_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 - array $fields
- 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 preparted
alterSchema() public ¶
alterSchema( unknown_type $compare , $table = null )
Generate a alter syntax from CakeSchema::compare()
Parameters
- unknown_type $compare
- $schema
- $table optional null
Returns
boolean() public ¶
boolean( mixed $data )
Translates between PHP boolean values and Database (faked) boolean values
Parameters
- mixed $data
- Value to be translated
Returns
Converted boolean value
buildIndex() public ¶
buildIndex( array $indexes , string $table = null )
Format indexes for create table
Parameters
- array $indexes
- string $table optional null
Returns
buildJoinStatement() public ¶
buildJoinStatement( array $join )
Builds and generates a JOIN statement from an array. Handles final clean-up before conversion.
Parameters
- array $join
- An array defining a JOIN statement in a query
Returns
An SQL JOIN statement to be used in a query
See
DboSource::buildStatement()
buildStatement() public ¶
buildStatement( array $query , object $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
- object $model
- The model object which initiated the query
Returns
An executable SQL statement
See
calculate() public ¶
calculate( model $model , string $func , array $params = array() )
Returns an SQL calculation, i.e. COUNT() or MAX()
Parameters
- model $model
- 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, and if DEBUG is turned on, the log for this object is shown.
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.
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
create() public ¶
create( Model
$model , array $fields = null , array $values = null )
The "C" in CRUD
Parameters
-
Model
$model - array $fields optional null
- array $values optional null
Returns
Success
Overrides
createSchema() public ¶
createSchema( object $schema , string $tableName = null )
Generate a database-native schema for the given Schema object
Parameters
- object $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( object $model , mixed $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
- object $model
- mixed $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 existance 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 - mixed $conditions optional null
Returns
Success
Overrides
dropSchema() public ¶
dropSchema( object $schema , string $table = null )
Generate a "drop table" statement for the given Schema object
Parameters
- object $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() )
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 DEBUG is set, the log is shown all the time, else it is only shown on errors.
Parameters
- string $sql
- array $options optional array()
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
Parameters
- string $expression
Returns
An object representing a database expression to be used in a query
fetchAll() public ¶
fetchAll( string $sql , boolean $cache = true , $modelName = null )
Returns an array of all result rows for a given SQL query. Returns false if no rows matched.
Parameters
- string $sql
- SQL statement
- boolean $cache optional true
- Enables returning/storing cached query results
- $modelName optional null
Returns
Array of resultset rows, or false if no rows matched
fetchAssociated() public ¶
fetchAssociated( model $model , string $query , array $ids )
A more efficient way to fetch associations. Woohoo!
Parameters
- model $model
- Primary model object
- string $query
- Association query
- array $ids
- Array of IDs of associated records
Returns
Association results
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
fullTableName() public ¶
fullTableName( mixed $model , boolean $quote = true )
Gets full table name including prefix
Parameters
- mixed $model
- boolean $quote optional true
Returns
Full quoted table name
generateAssociationQuery() public ¶
generateAssociationQuery( Model
$model , Model
$linkModel , string $type , string $association , array $assocData , array $queryData , boolean $external , array $resultSet )
getConstraint() public ¶
getConstraint( string $type , object $model , array $linkModel , $alias , $assoc , $alias2 = null )
Returns a conditions array for the constraint between two models
Parameters
- string $type
- Association type
- object $model
- Model object
- array $linkModel
- $association Association array
- $alias
- $assoc
- $alias2 optional null
Returns
Conditions array defining the constraint between $model and $association
group() public ¶
group( string $group )
Create a GROUP BY SQL clause
Parameters
- string $group
- Group By Condition
Returns
string condition 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
identifier() public ¶
identifier( string $identifier )
Returns an object to represent a database identifier in a query
Parameters
- string $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
insertMulti() public ¶
insertMulti( string $table , string $fields , array $values )
Inserts multiple values into a table
Parameters
- string $table
- string $fields
- array $values
introspectType() public ¶
introspectType( string $value )
Guesses the data type of an array
Parameters
- string $value
isConnected() public ¶
isConnected( )
Checks if it's connected to the database
Returns
True if the database is connected, else false
length() public ¶
length( string $real )
Gets the length of a database-native column description, or null if no length
Parameters
- string $real
- Real database-layer column type (i.e. "varchar(255)")
Returns
An integer or string representing the length of the column
logQuery() public ¶
logQuery( string $sql )
Log given SQL query.
Parameters
- string $sql
- SQL statement
Todo:
name() public ¶
name( string $data )
Returns a quoted name of $data for use in an SQL statement. Strips fields out of SQL functions before quoting.
Parameters
- string $data
Returns
SQL field
order() public ¶
order( string $keys , string $direction = 'ASC' )
Returns an ORDER BY clause as a string.
Parameters
- string $keys
- $key Field reference, as a key (i.e. Post.title)
- string $direction optional 'ASC'
- Direction (ASC or DESC)
Returns
ORDER BY clause
queryAssociation() public ¶
queryAssociation( Model
$model , unknown_type $linkModel , string $type , unknown_type $association , unknown_type $assocData , unknown_type $queryData , unknown_type $external , unknown_type $resultSet , integer $recursive , array $stack )
Enter description here...
Parameters
-
Model
$model - unknown_type $linkModel
- string $type
- Association type
- unknown_type $association
- unknown_type $assocData
- unknown_type $queryData
- unknown_type $external
- unknown_type $resultSet
- integer $recursive
- Number of levels of association
- array $stack
rawQuery() public ¶
rawQuery( string $sql )
Executes given SQL statement.
Parameters
- string $sql
- SQL statement
Returns
read() public ¶
read( Model
$model , array $queryData = array() , integer $recursive = null )
The "R" in CRUD
Parameters
-
Model
$model - array $queryData optional array()
- integer $recursive optional null
- Number of levels of association
Returns
Overrides
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
Returns
renderStatement() public ¶
renderStatement( string $type , array $data )
Renders a final SQL statement by putting together the component parts in the correct order
Parameters
- string $type
- array $data
Returns
resolveKey() public ¶
resolveKey( unknown_type $model , unknown_type $key , unknown_type $assoc = null )
Returns a key formatted like a string Model.fieldname(i.e. Post.title, or Country.name)
Parameters
- unknown_type $model
- unknown_type $key
- unknown_type $assoc optional null
Returns
Overrides
showLog() public ¶
showLog( boolean $sorted = false )
Outputs the contents of the queries log.
Parameters
- boolean $sorted optional false
showQuery() public ¶
showQuery( string $sql )
Output information about an SQL query. The SQL statement, number of rows in resultset, and execution time in microseconds. If the query fails, an error is output instead.
Parameters
- string $sql
- Query to show information on.
truncate() public ¶
truncate( mixed $table )
Deletes all the records in a table and resets the count of the auto-incrementing primary key, where applicable.
Parameters
- mixed $table
- A string or model class representing the table to be truncated
Returns
SQL TRUNCATE TABLE statement, false if not applicable.
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. For databases that do not support aliases in UPDATE queries.
Parameters
-
Model
$model - array $fields optional array()
- array $values optional null
- mixed $conditions optional null
Returns
Success
Overrides
Methods inherited from DataSource
__cacheDescription() public ¶
__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
insertQueryData() public ¶
insertQueryData( unknown_type $query , unknown_type $data , unknown_type $association , unknown_type $assocData , Model
$model , Model
$linkModel , array $stack )
isInterfaceSupported() public ¶
isInterfaceSupported( string $interface )
Returns true if the DataSource supports the given interface (method)
Parameters
- string $interface
- The name of the interface (method)
Returns
True on success
setConfig() public ¶
setConfig( array $config = array() )
Sets the configuration for the DataSource
Parameters
- array $config optional array()
- The configuration array
Methods inherited from Object
Object() public ¶
Object( )
A hack to support __construct() on PHP 4 Hint: descendant classes have no PHP4 class_name() constructors, so this constructor gets called first and calls the top-layer __construct() which (if present) should call parent::__construct()
Returns
__openPersistent() public ¶
__openPersistent( string $name , string $type = null )
Open the persistent class file for reading Used by Object::_persist()
Parameters
- string $name
- Name of persisted class
- string $type optional null
- Type of persistance (e.g: registry)
_persist() public ¶
_persist( string $name , string $return , $object , $type = null )
Checks for a persistent class file, if found file is opened and true returned If file is not found a file is created and false returned If used in other locations of the model you should choose a unique name for the persistent file There are many uses for this method, see manual for examples
Parameters
- string $name
- name of the class to persist
- string $return
- $object the object to persist
- $object
- $type optional null
Returns
Success
_savePersistent() public ¶
_savePersistent( string $name , object $object )
You should choose a unique name for the persistent file
There are many uses for this method, see manual for examples
Parameters
- string $name
- name used for object to cache
- object $object
- the object to persist
Returns
true on save, throws error if file can not be created
_set() public ¶
_set( array $properties = array() )
Allows setting of multiple properties of the object in a single line of code.
Parameters
- array $properties optional array()
- An associative array containing properties and corresponding values.
_stop() public ¶
_stop( $status = 0 )
Stop execution of the current script
Parameters
- $status optional 0
- http://php.net/exit for values
cakeError() public ¶
cakeError( string $method , array $messages = array() )
Used to report user friendly errors. If there is a file app/error.php or app/app_error.php this file will be loaded error.php is the AppError class it should extend ErrorHandler class.
Parameters
- string $method
- Method to be called in the error class (AppError or ErrorHandler classes)
- array $messages optional array()
- Message that is to be displayed by the error class
Returns
message
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, and improves performance by using straight method calls in most cases.
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_ERROR )
API for logging events.
Parameters
- string $msg
- Log message
- integer $type optional LOG_ERROR
- Error type constant. Defined in app/config/core.php.
Returns
Success of log write
requestAction() public ¶
requestAction( mixed $url , array $extra = array() )
Calls a controller's method from any location.
Parameters
- mixed $url
- String or array-based url.
- array $extra optional array()
- if array includes the key "return" it sets the AutoRender to true.
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
$_adodbColumnTypes ¶
Array translating ADOdb column MetaTypes to cake-supported metatypes
array( 'string' => 'C', 'text' => 'X', 'date' => 'D', 'timestamp' => 'T', 'time' => 'T', 'datetime' => 'T', 'boolean' => 'L', 'float' => 'N', 'integer' => 'I', 'binary' => 'R', )
$columns ¶
ADOdb column definition
array( 'primary_key' => array('name' => 'R', 'limit' => 11), 'string' => array('name' => 'C', 'limit' => '255'), 'text' => array('name' => 'X'), 'integer' => array('name' => 'I', 'limit' => '11', 'formatter' => 'intval'), 'float' => array('name' => 'N', 'formatter' => 'floatval'), 'timestamp' => array('name' => 'T', 'format' => 'Y-m-d H:i:s', 'formatter' => 'date'), 'time' => array('name' => 'T', 'format' => 'H:i:s', 'formatter' => 'date'), 'datetime' => array('name' => 'T', 'format' => 'Y-m-d H:i:s', 'formatter' => 'date'), 'date' => array('name' => 'D', 'format' => 'Y-m-d', 'formatter' => 'date'), 'binary' => array('name' => 'B'), 'boolean' => array('name' => 'L', 'limit' => '1') )