Alpha Framework 4.0.0 API Documentation

ActiveRecordProviderSQLite
in package
implements ActiveRecordProviderInterface

SQLite active record provider (uses the SQLite3 native API in PHP).

Tags
since
1.2
author

John Collins dev@alphaframework.org

license

http://www.opensource.org/licenses/bsd-license.php The BSD License

copyright

Copyright (c) 2021, John Collins (founder of Alpha Framework). All rights reserved.

Redistribution and use in source and binary forms, with or
without modification, are permitted provided that the
following conditions are met:

* Redistributions of source code must retain the above
  copyright notice, this list of conditions and the
  following disclaimer.
* Redistributions in binary form must reproduce the above
  copyright notice, this list of conditions and the
  following disclaimer in the documentation and/or other
  materials provided with the distribution.
* Neither the name of the Alpha Framework nor the names
  of its contributors may be used to endorse or promote
  products derived from this software without specific
  prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Table of Contents

Interfaces

ActiveRecordProviderInterface
An interface that defines all of the active record methods that should be included in a provider that implements this interface.

Properties

$connection  : SQLite3
Database connection.
$foreignKeys  : array<string|int, mixed>
An array of new foreign keys that need to be created.
$logger  : Logger
Trace logger.
$record  : ActiveRecord
The business object that we are mapping back to.

Methods

__construct()  : mixed
The constructor.
addProperty()  : void
(non-PHPdoc).
backupDatabase()  : void
(non-PHPdoc).
begin()  : void
(non-PHPdoc).
checkDatabaseExists()  : bool
(non-PHPdoc).
checkRecordExists()  : bool
(non-PHPdoc).
checkRecordTableExists()  : bool
(non-PHPdoc).
checkTableExists()  : bool
(non-PHPdoc).
checkTableNeedsUpdate()  : bool
(non-PHPdoc).
commit()  : void
(non-PHPdoc).
createDatabase()  : void
(non-PHPdoc).
createForeignIndex()  : void
Note that SQLite 3.6.19 is requrired for foreign key support.
createUniqueIndex()  : void
(non-PHPdoc).
delete()  : void
(non-PHPdoc).
disconnect()  : void
(non-PHPdoc).
dropDatabase()  : void
(non-PHPdoc).
dropTable()  : void
(non-PHPdoc).
findMissingFields()  : array<string|int, mixed>
(non-PHPdoc).
getConnection()  : SQLite3
(non-PHPdoc).
getCount()  : int
(non-PHPdoc).
getHistoryCount()  : int
(non-PHPdoc).
getIndexes()  : array<string|int, mixed>
(non-PHPdoc).
getLastDatabaseError()  : string
(non-PHPdoc).
getMAX()  : int
(non-PHPdoc).
getVersion()  : int
(non-PHPdoc).
isTableOverloaded()  : bool
(non-PHPdoc).
load()  : void
(non-PHPdoc).
loadAll()  : array<string|int, mixed>
(non-PHPdoc).
loadAllByAttribute()  : array<string|int, mixed>
(non-PHPdoc).
loadAllByAttributes()  : array<string|int, mixed>
(non-PHPdoc).
loadAllByDayUpdated()  : array<string|int, mixed>
(non-PHPdoc).
loadAllFieldValuesByAttribute()  : array<string|int, mixed>
(non-PHPdoc).
loadAllOldVersions()  : array<string|int, mixed>
(non-PHPdoc).
loadByAttribute()  : void
(non-PHPdoc).
makeHistoryTable()  : void
(non-PHPdoc).
makeTable()  : void
(non-PHPdoc).
query()  : array<string|int, mixed>
(non-PHPdoc).
rebuildTable()  : void
(non-PHPdoc).
reload()  : void
(non-PHPdoc).
rollback()  : void
(non-PHPdoc).
save()  : void
(non-PHPdoc).
saveAttribute()  : void
(non-PHPdoc).
saveHistory()  : void
(non-PHPdoc).
setEnumOptions()  : void
Given that Enum values are not saved in the database for SQLite, an implementation is not required here.
setRecord()  : void
(non-PHPdoc).
checkIndexes()  : void
Checks to see if all of the indexes are in place for the record's table, creates those that are missing.

Properties

$foreignKeys

An array of new foreign keys that need to be created.

private array<string|int, mixed> $foreignKeys = array()
Tags
since
2.0.1

Methods

addProperty()

(non-PHPdoc).

public addProperty(mixed $propName) : void
Parameters
$propName : mixed

The name of the new field to add to the database table.

Tags
see
ActiveRecordProviderInterface::addProperty()

backupDatabase()

(non-PHPdoc).

public static backupDatabase(mixed $targetFile) : void
Parameters
$targetFile : mixed
Tags
see
ActiveRecordProviderInterface::backupDatabase()

checkDatabaseExists()

(non-PHPdoc).

public static checkDatabaseExists() : bool
Tags
see
ActiveRecordProviderInterface::checkDatabaseExists()
Return values
bool

checkRecordExists()

(non-PHPdoc).

public checkRecordExists(mixed $ID) : bool
Parameters
$ID : mixed

The Object ID of the object we want to see whether it exists or not.

Tags
see
ActiveRecordProviderInterface::checkRecordExists()
Return values
bool

checkRecordTableExists()

(non-PHPdoc).

public static checkRecordTableExists(mixed $RecordClassName[, mixed $checkHistoryTable = false ]) : bool
Parameters
$RecordClassName : mixed

The name of the business object class we are checking.

$checkHistoryTable : mixed = false

Set to true if you want to check for the existance of the _history table for this DAO.

Tags
see
ActiveRecordProviderInterface::checkRecordTableExists()
Return values
bool

checkTableExists()

(non-PHPdoc).

public checkTableExists([mixed $checkHistoryTable = false ]) : bool
Parameters
$checkHistoryTable : mixed = false

Set to true if you want to check for the existance of the _history table for this DAO.

Tags
see
ActiveRecordProviderInterface::checkTableExists()
Return values
bool

checkTableNeedsUpdate()

(non-PHPdoc).

public checkTableNeedsUpdate() : bool
Tags
see
ActiveRecordProviderInterface::checkTableNeedsUpdate()
Return values
bool

createDatabase()

(non-PHPdoc).

public static createDatabase() : void
Tags
see
ActiveRecordProviderInterface::createDatabase()

createForeignIndex()

Note that SQLite 3.6.19 is requrired for foreign key support.

public createForeignIndex(mixed $attributeName, mixed $relatedClass, mixed $relatedClassAttribute[, mixed $indexName = null ]) : void

(non-PHPdoc)

Parameters
$attributeName : mixed

The name of the attribute to apply the index on.

$relatedClass : mixed

The fully-qualified name of the related class.

$relatedClassAttribute : mixed

The name of the field to relate to on the related class.

$indexName : mixed = null

The optional name for the index, will calculate if not provided.

Tags
see
ActiveRecordProviderInterface::createForeignIndex()

createUniqueIndex()

(non-PHPdoc).

public createUniqueIndex(mixed $attribute1Name[, mixed $attribute2Name = '' ][, mixed $attribute3Name = '' ]) : void
Parameters
$attribute1Name : mixed

The first attribute to mark unique in the database.

$attribute2Name : mixed = ''

The second attribute to mark unique in the databse (optional, use only for composite keys).

$attribute3Name : mixed = ''

The third attribute to mark unique in the databse (optional, use only for composite keys).

Tags
see
ActiveRecordProviderInterface::createUniqueIndex()

disconnect()

(non-PHPdoc).

public static disconnect() : void
Tags
see
ActiveRecordProviderInterface::disconnect()

dropDatabase()

(non-PHPdoc).

public static dropDatabase() : void
Tags
see
ActiveRecordProviderInterface::dropDatabase()

dropTable()

(non-PHPdoc).

public dropTable([mixed $tableName = null ]) : void
Parameters
$tableName : mixed = null

Optional table name, leave blank for the defined table for this class to be dropped

Tags
see
ActiveRecordProviderInterface::dropTable()

findMissingFields()

(non-PHPdoc).

public findMissingFields() : array<string|int, mixed>
Tags
see
ActiveRecordProviderInterface::findMissingFields()
Return values
array<string|int, mixed>

getConnection()

(non-PHPdoc).

public static getConnection() : SQLite3
Tags
see
ActiveRecordProviderInterface::getConnection()
Return values
SQLite3

getCount()

(non-PHPdoc).

public getCount([mixed $attributes = array() ][, mixed $values = array() ]) : int
Parameters
$attributes : mixed = array()

The attributes to count the objects by (optional).

$values : mixed = array()

The values of the attributes to count the objects by (optional).

Tags
see
ActiveRecordProviderInterface::getCount()
Return values
int

getHistoryCount()

(non-PHPdoc).

public getHistoryCount() : int
Tags
see
ActiveRecordProviderInterface::getHistoryCount()
Return values
int

getIndexes()

(non-PHPdoc).

public getIndexes() : array<string|int, mixed>
Tags
see
ActiveRecordProviderInterface::getIndexes()
Return values
array<string|int, mixed>

getLastDatabaseError()

(non-PHPdoc).

public static getLastDatabaseError() : string
Tags
see
ActiveRecordProviderInterface::getLastDatabaseError()
Return values
string

getMAX()

(non-PHPdoc).

public getMAX() : int
Tags
see
ActiveRecordProviderInterface::getMAX()
Return values
int

getVersion()

(non-PHPdoc).

public getVersion() : int
Tags
see
ActiveRecordProviderInterface::getVersion()
Return values
int

isTableOverloaded()

(non-PHPdoc).

public isTableOverloaded() : bool
Tags
see
ActiveRecordProviderInterface::isTableOverloaded()
Return values
bool

load()

(non-PHPdoc).

public load(mixed $ID[, mixed $version = 0 ]) : void
Parameters
$ID : mixed

The object ID of the record to load.

$version : mixed = 0

Optionaly, provide the version to load that version from the [tablename]_history table.

Tags
see
ActiveRecordProviderInterface::load()

loadAll()

(non-PHPdoc).

public loadAll([mixed $start = 0 ][, mixed $limit = 0 ][, mixed $orderBy = 'ID' ][, mixed $order = 'ASC' ][, mixed $ignoreClassType = false ]) : array<string|int, mixed>
Parameters
$start : mixed = 0

The start of the SQL LIMIT clause, useful for pagination.

$limit : mixed = 0

The amount (limit) of records to load, useful for pagination.

$orderBy : mixed = 'ID'

The name of the field to sort the records by.

$order : mixed = 'ASC'

The order to sort the records by.

$ignoreClassType : mixed = false

Default is false, set to true if you want to load from overloaded tables and ignore the class type

Tags
see
ActiveRecordProviderInterface::loadAll()
Return values
array<string|int, mixed>

loadAllByAttribute()

(non-PHPdoc).

public loadAllByAttribute(mixed $attribute, mixed $value[, mixed $start = 0 ][, mixed $limit = 0 ][, mixed $orderBy = 'ID' ][, mixed $order = 'ASC' ][, mixed $ignoreClassType = false ][, mixed $constructorArgs = array() ]) : array<string|int, mixed>
Parameters
$attribute : mixed

The attribute to load the objects by.

$value : mixed

The value of the attribute to load the objects by.

$start : mixed = 0

The start of the SQL LIMIT clause, useful for pagination.

$limit : mixed = 0

The amount (limit) of objects to load, useful for pagination.

$orderBy : mixed = 'ID'

The name of the field to sort the objects by.

$order : mixed = 'ASC'

The order to sort the objects by.

$ignoreClassType : mixed = false

Default is false, set to true if you want to load from overloaded tables and ignore the class type.

$constructorArgs : mixed = array()

An optional array of contructor arguements to pass to the records that will be generated and returned. Supports a maximum of 5 arguements.

Tags
see
ActiveRecordProviderInterface::loadAllByAttribute()
Return values
array<string|int, mixed>

loadAllByAttributes()

(non-PHPdoc).

public loadAllByAttributes([mixed $attributes = array() ][, mixed $values = array() ][, mixed $start = 0 ][, mixed $limit = 0 ][, mixed $orderBy = 'ID' ][, mixed $order = 'ASC' ][, mixed $ignoreClassType = false ][, mixed $constructorArgs = array() ]) : array<string|int, mixed>
Parameters
$attributes : mixed = array()

The attributes to load the records by.

$values : mixed = array()

The values of the attributes to load the records by.

$start : mixed = 0

The start of the SQL LIMIT clause, useful for pagination.

$limit : mixed = 0

The amount (limit) of records to load, useful for pagination.

$orderBy : mixed = 'ID'

The name of the field to sort the records by.

$order : mixed = 'ASC'

The order to sort the records by.

$ignoreClassType : mixed = false

Default is false, set to true if you want to load from overloaded tables and ignore the class type

$constructorArgs : mixed = array()

An optional array of contructor arguements to pass to the records that will be generated and returned. Supports a maximum of 5 arguements.

Tags
see
ActiveRecordProviderInterface::loadAllByAttributes()
Return values
array<string|int, mixed>

loadAllByDayUpdated()

(non-PHPdoc).

public loadAllByDayUpdated(mixed $date[, mixed $start = 0 ][, mixed $limit = 0 ][, mixed $orderBy = 'ID' ][, mixed $order = 'ASC' ][, mixed $ignoreClassType = false ]) : array<string|int, mixed>
Parameters
$date : mixed

The date for which to load the records updated on, in the format 'YYYY-MM-DD'.

$start : mixed = 0

The start of the SQL LIMIT clause, useful for pagination.

$limit : mixed = 0

The amount (limit) of records to load, useful for pagination.

$orderBy : mixed = 'ID'

The name of the field to sort the records by.

$order : mixed = 'ASC'

The order to sort the records by.

$ignoreClassType : mixed = false

Default is false, set to true if you want to load from overloaded tables and ignore the class type

Tags
see
ActiveRecordProviderInterface::loadAllByDayUpdated()
Return values
array<string|int, mixed>

loadAllFieldValuesByAttribute()

(non-PHPdoc).

public loadAllFieldValuesByAttribute(mixed $attribute, mixed $value, mixed $returnAttribute[, mixed $order = 'ASC' ][, mixed $ignoreClassType = false ]) : array<string|int, mixed>
Parameters
$attribute : mixed

The attribute name to load the field values by.

$value : mixed

The value of the attribute to load the field values by.

$returnAttribute : mixed

The name of the attribute to return.

$order : mixed = 'ASC'

The order to sort the records by.

$ignoreClassType : mixed = false

Default is false, set to true if you want to load from overloaded tables and ignore the class type.

Tags
see
ActiveRecordProviderInterface::loadAllFieldValuesByAttribute()
Return values
array<string|int, mixed>

loadAllOldVersions()

(non-PHPdoc).

public loadAllOldVersions(mixed $ID) : array<string|int, mixed>
Parameters
$ID : mixed

The object ID of the record to load.

Tags
see
ActiveRecordProviderInterface::loadAllOldVersions()
Return values
array<string|int, mixed>

loadByAttribute()

(non-PHPdoc).

public loadByAttribute(mixed $attribute, mixed $value[, mixed $ignoreClassType = false ][, mixed $loadAttributes = array() ]) : void
Parameters
$attribute : mixed

The name of the attribute to load the record by.

$value : mixed

The value of the attribute to load the record by.

$ignoreClassType : mixed = false

Default is false, set to true if you want to load from overloaded tables and ignore the class type

$loadAttributes : mixed = array()

The attributes to load from the database to this object (leave blank to load all attributes)

Tags
see
ActiveRecordProviderInterface::loadByAttribute()

makeHistoryTable()

(non-PHPdoc).

public makeHistoryTable() : void
Tags
see
ActiveRecordProviderInterface::makeHistoryTable()

makeTable()

(non-PHPdoc).

public makeTable([mixed $checkIndexes = true ]) : void
Parameters
$checkIndexes : mixed = true

Set to false if you do not want to check for any additional required indexes while creating the table (default is true).

Tags
see
ActiveRecordProviderInterface::makeTable()

query()

(non-PHPdoc).

public query(mixed $sqlQuery) : array<string|int, mixed>
Parameters
$sqlQuery : mixed
Tags
see
ActiveRecordProviderInterface::query()
Return values
array<string|int, mixed>

rebuildTable()

(non-PHPdoc).

public rebuildTable() : void
Tags
see
ActiveRecordProviderInterface::rebuildTable()

saveAttribute()

(non-PHPdoc).

public saveAttribute(mixed $attribute, mixed $value) : void
Parameters
$attribute : mixed

The name of the attribute to save.

$value : mixed

The value of the attribute to save.

Tags
see
ActiveRecordProviderInterface::saveAttribute()

setEnumOptions()

Given that Enum values are not saved in the database for SQLite, an implementation is not required here.

public setEnumOptions() : void

(non-PHPdoc)

Tags
see
ActiveRecordProviderInterface::setEnumOptions()
throws
NotImplementedException

setRecord()

(non-PHPdoc).

public setRecord(mixed $record) : void
Parameters
$record : mixed
Tags
see
ActiveRecordProviderInterface::setRecord()

checkIndexes()

Checks to see if all of the indexes are in place for the record's table, creates those that are missing.

private checkIndexes() : void
Tags
since
1.2

        
On this page

Search results