Skip to content

Developer Guide: Data Access Objects (DAO's)

CVi edited this page Sep 13, 2010 · 18 revisions

All of ThinkTank’s database interactions are encapsulated in DAO’s (Data Access Objects), contained in the model (the common directory).

DAO Method Interfaces

Let’s draft what all DAO methods should return.

Method return format draft as of now is as follows:

  • INSERT: last inserted ID (where there is an AUTO_INCREMENT primary key)
  • UPDATE/DELETE: number of affected rows
  • SELECT Multiple rows: array with objects, or arrays if no appropriate class exist, empty array on no rows returned.
  • SELECT Single row: object, array if no appropriate class exist, null on no rows returned.
  • IF: True if the data exist, otherwise false.

As seen above multiple SELECT formats does exist:

  • SELECT Single row” is for methods that expect only/exactly one result.
  • SELECT Multiple rows” is for methods expecting any number of results.

Return objects/classes

When you create a class to contain return data, make sure to make the construct so it can handle no-data-input.
Some return methods slipstreams the data directly into the properties, but the construct is still called with no arguments.
For classes that expect arbitrary (no-standard) data, try overloading

Clone this wiki locally