\Dewdrop\Db\DriverMock

A mock DB adpater driver for use during testing. You can certainly create a mock of a normal driver class, but this is a little easier to use in some situations.

Summary

Methods
Properties
Constants
listMissingForeignKeyIndexes()
generateCreateIndexStatement()
generateAnalyzeTableStatement()
__construct()
getConnection()
fetchAll()
fetchAllWithGenerator()
fetchCol()
fetchOne()
query()
lastInsertId()
getQuoteIdentifierSymbol()
listTables()
listForeignKeyReferences()
listUniqueConstraints()
describeTable()
beginTransaction()
commit()
rollback()
mapNativeTypeToGenericType()
prepareSelectForTotalRowCalculation()
fetchTotalRowCount()
getCaseInsensitiveLikeOperator()
truncateTimeStampToDate()
quoteInternal()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
No private methods found
$adapter
N/A

Properties

$adapter

$adapter : \Dewdrop\Db\Adapter

The adapter this driver is attached to.

Type

\Dewdrop\Db\Adapter

Methods

listMissingForeignKeyIndexes()

listMissingForeignKeyIndexes(  $tableName) : mixed

List all missing foreign key indexes on the supplied table.

The resulting array has the following shape:

[
    ['foreign_key_id'],
    ['multi_column_foreign_key_id', 'second_column_foreign_key_id']
]

Parameters

$tableName

Returns

mixed

generateCreateIndexStatement()

generateCreateIndexStatement(string  $tableName, array  $columnNames) : string

Generate an SQL statement to create an index on the supplied table and column(s).

Parameters

string $tableName
array $columnNames

Returns

string

generateAnalyzeTableStatement()

generateAnalyzeTableStatement(string  $tableName) : string

Generate an SQL statement to analyze a table.

Parameters

string $tableName

Returns

string

__construct()

__construct(\Dewdrop\Db\Adapter  $adapter) 

Create new instance with the supplied adapter.

Parameters

\Dewdrop\Db\Adapter $adapter

getConnection()

getConnection() : null

Grab the actual DB connection object (nothing in the case of the mock driver).

Returns

null

fetchAll()

fetchAll(string|\Dewdrop\Db\Select  $sql, array  $bind = array(), string  $fetchMode = null) : array

Fetch all results for the supplied SQL statement.

The SQL query can be a simple string or a Select object. The bind array should supply values for all the parameters, either named or numeric, in the query. And the fetch mode should match one of these 4 class constants from \Dewdrop\Db\Adapter: ARRAY_A, ARRAY_N, OBJECT, or OBJECT_K.

Parameters

string|\Dewdrop\Db\Select $sql
array $bind
string $fetchMode

Returns

array

fetchAllWithGenerator()

fetchAllWithGenerator(string|\Dewdrop\Db\Select  $sql, array  $bind = array(), string  $fetchMode = null) : \Generator

Fetch all results for the supplied SQL query using a PHP generator.

This approach uses less memory, but the result set has a forward-only cursor.

The SQL query can be a simple string or a Select object. The bind array should supply values for all the parameters, either named or numeric, in the query. And the fetch mode should match one of these 4 class constants from \Dewdrop\Db\Adapter: ARRAY_A, ARRAY_N, OBJECT, or OBJECT_K.

Parameters

string|\Dewdrop\Db\Select $sql
array $bind
string $fetchMode

Returns

\Generator

fetchCol()

fetchCol(string|\Dewdrop\Db\Select  $sql, array  $bind = array()) : array

Fetch a single column of the results from the supplied SQL statement.

Parameters

string|\Dewdrop\Db\Select $sql
array $bind

Returns

array

fetchOne()

fetchOne(string|\Dewdrop\Db\Select  $sql, array  $bind = array()) : mixed

Fetch a single scalar value from the results of the supplied SQL statement.

Parameters

string|\Dewdrop\Db\Select $sql
array $bind

Returns

mixed

query()

query(string|\Dewdrop\Db\Select  $sql, array  $bind = array()) : mixed

Run the supplied query, binding the supplied data to the statement prior to execution.

Parameters

string|\Dewdrop\Db\Select $sql
array $bind

Returns

mixed

lastInsertId()

lastInsertId() : integer

Get the last insert ID from \wpdb after performing an insert on a table with an auto-incrementing primary key.

Returns

integer

getQuoteIdentifierSymbol()

getQuoteIdentifierSymbol() : string

Returns the symbol the adapter uses for delimited identifiers.

Returns

string

listTables()

listTables() : array

Returns a list of the tables in the database.

Returns

array

listForeignKeyReferences()

listForeignKeyReferences(string  $tableName) : array

Returns an associative array containing all the foreign key relationships associated with the supplied table.

The array has the following format:

array(
    'column_name' => array(
        'table'  => 'foreign_table',
        'column' => 'foreign_column'
    )
)

Parameters

string $tableName

Returns

array

listUniqueConstraints()

listUniqueConstraints(string  $tableName) : array

Returns an associative array containing all the unique constraints on a table.

The array has the following format:

array(
    'key_name' => array(
        sequence_in_index => 'column_name'
    )
)

Parameters

string $tableName

Returns

array

describeTable()

describeTable(string  $tableName) : array

Returns the column descriptions for a table.

The return value is an associative array keyed by the column name, as returned by the RDBMS.

The value of each array element is an associative array with the following keys:

SCHEMA_NAME => string; name of database or schema TABLE_NAME => string; COLUMN_NAME => string; column name COLUMN_POSITION => number; ordinal position of column in table DATA_TYPE => string; SQL datatype name of column DEFAULT => string; default expression of column, null if none NULLABLE => boolean; true if column can have nulls LENGTH => number; length of CHAR/VARCHAR SCALE => number; scale of NUMERIC/DECIMAL PRECISION => number; precision of NUMERIC/DECIMAL UNSIGNED => boolean; unsigned property of an integer type PRIMARY => boolean; true if column is part of the primary key PRIMARY_POSITION => integer; position of column in primary key IDENTITY => integer; true if column is auto-generated with unique values

Parameters

string $tableName

Returns

array

beginTransaction()

beginTransaction() : void

Start a new transaction.

commit()

commit() : void

Commit the current transaction.

rollback()

rollback() : void

Rollback the current transaction.

mapNativeTypeToGenericType()

mapNativeTypeToGenericType(string  $nativeType, mixed  $length) : string

Given the supplied native data type, return a generic data type that can be used in Dewdrop to make decisions about columns/fields:

1) boolean - A true/false value. 2) integer - Whole number. 3) float - Floating point number. 4) text - Fixed-length, shorter text value. 5) clob - Character large object. Large text field. 6) timestamp - Date and time combined. 7) date - Just a date. 8) time - Just the time. 9) money - Get money, get paid. 10) blob - Binary large object.

Parameters

string $nativeType
mixed $length

Returns

string

prepareSelectForTotalRowCalculation()

prepareSelectForTotalRowCalculation(\Dewdrop\Db\Select  $select) : void

Modify a \Dewdrop\Db\Select object so that the RDBMS can calculate the total number of rows that would have been returned if no LIMIT was present.

Parameters

\Dewdrop\Db\Select $select

fetchTotalRowCount()

fetchTotalRowCount(array  $resultSet) : integer

Fetch the number of rows that would have been fetched had no LIMIT clause been applied to a statement. The result set is supplied here for RDBMS types (e.g. Postgres) where the total count is embedded in the result set. However, some systems (e.g. MySQL) will not need to reference it.

Parameters

array $resultSet

Returns

integer

getCaseInsensitiveLikeOperator()

getCaseInsensitiveLikeOperator() : string

Return the operator that can be used for case-insensitive LIKE comparisons.

Returns

string

truncateTimeStampToDate()

truncateTimeStampToDate(string  $timestamp) : string

Use the functions available in the RDBMS to truncate the provided timestamp column to a date.

Parameters

string $timestamp

Returns

string

quoteInternal()

quoteInternal(string  $input) : string

Quote the supplied input using the appropriate method for your database platform/driver. We're using addslashes() in the Mock driver because it allows us to test that quoteInternal() is being called during tests without using MySQL or Postgres functions directly. addslashes() in production would be inappropriate.

Parameters

string $input

Returns

string