\OCP\AppFramework\DbMapper

Simple parent class for inheriting your data access layer from. This class may be subject to change in the future

Summary

Methods
Properties
Constants
__construct()
getTableName()
delete()
insert()
update()
No public properties found
No constants found
execute()
findOneQuery()
mapRowToEntity()
findEntities()
findEntity()
$tableName
$entityClass
$db
N/A
isAssocArray()
getPDOType()
buildDebugMessage()
No private properties found
N/A

Properties

$tableName

$tableName : 

Type

$entityClass

$entityClass : 

Type

$db

$db : 

Type

Methods

__construct()

__construct(\OCP\IDBConnection  $db, string  $tableName, string  $entityClass = null) 

Parameters

\OCP\IDBConnection $db

Instance of the Db abstraction layer

string $tableName

the name of the table. set this to allow entity

string $entityClass

the name of the entity that the sql should be mapped to queries without using sql

getTableName()

getTableName() : string

Returns

string —

the table name

insert()

insert(\OCP\AppFramework\Db\Entity  $entity) : \OCP\AppFramework\Db\Entity

Creates a new entry in the db from an entity

Parameters

\OCP\AppFramework\Db\Entity $entity

the entity that should be created

Returns

\OCP\AppFramework\Db\Entity

the saved entity with the set id

update()

update(\OCP\AppFramework\Db\Entity  $entity) : \OCP\AppFramework\Db\Entity

Updates an entry in the db from an entity

Parameters

\OCP\AppFramework\Db\Entity $entity

the entity that should be created

Throws

\InvalidArgumentException

if entity has no id

Returns

\OCP\AppFramework\Db\Entity

the saved entity with the set id

execute()

execute(string  $sql, array  $params = array(), integer  $limit = null, integer  $offset = null) : \PDOStatement

Runs an sql query

Parameters

string $sql

the prepare string

array $params

the params which should replace the ? in the sql query

integer $limit

the maximum number of rows

integer $offset

from which row we want to start

Returns

\PDOStatement —

the database query result

findOneQuery()

findOneQuery(string  $sql, array  $params = array(), integer  $limit = null, integer  $offset = null) : array

Returns an db result and throws exceptions when there are more or less results

Parameters

string $sql

the sql query

array $params

the parameters of the sql query

integer $limit

the maximum number of rows

integer $offset

from which row we want to start

Throws

\OCP\AppFramework\Db\DoesNotExistException

if the item does not exist

\OCP\AppFramework\Db\MultipleObjectsReturnedException

if more than one item exist

Returns

array —

the result as row

mapRowToEntity()

mapRowToEntity(array  $row) : \OCP\AppFramework\Db\Entity

Creates an entity from a row. Automatically determines the entity class from the current mapper name (MyEntityMapper -> MyEntity)

Parameters

array $row

the row which should be converted to an entity

Returns

\OCP\AppFramework\Db\Entity

the entity

findEntities()

findEntities(string  $sql, array  $params = array(), integer  $limit = null, integer  $offset = null) : array

Runs a sql query and returns an array of entities

Parameters

string $sql

the prepare string

array $params

the params which should replace the ? in the sql query

integer $limit

the maximum number of rows

integer $offset

from which row we want to start

Returns

array —

all fetched entities

findEntity()

findEntity(string  $sql, array  $params = array(), integer  $limit = null, integer  $offset = null) : \OCP\AppFramework\Db\Entity

Returns an db result and throws exceptions when there are more or less results

Parameters

string $sql

the sql query

array $params

the parameters of the sql query

integer $limit

the maximum number of rows

integer $offset

from which row we want to start

Throws

\OCP\AppFramework\Db\DoesNotExistException

if the item does not exist

\OCP\AppFramework\Db\MultipleObjectsReturnedException

if more than one item exist

Returns

\OCP\AppFramework\Db\Entity

the entity

isAssocArray()

isAssocArray(array  $array) : boolean

Checks if an array is associative

Parameters

array $array

Returns

boolean —

true if associative

getPDOType()

getPDOType(  $value) : integer

Returns the correct PDO constant based on the value type

Parameters

$value

Returns

integer —

PDO constant

buildDebugMessage()

buildDebugMessage(  $msg, string  $sql, array  $params = array(), integer  $limit = null, integer  $offset = null) : string

Builds an error message by prepending the $msg to an error message which has the parameters

Parameters

$msg
string $sql

the sql query

array $params

the parameters of the sql query

integer $limit

the maximum number of rows

integer $offset

from which row we want to start

Returns

string —

formatted error message string