phpsqldatabase-abstraction

SQL Query State


I came by some code written by another developer. it's a php database abstraction layer, i am trying to study the code and i can't understand some of it.

class QueryBuilderBase
{
    /*
     * The builder SQLStates.
     */
    const STATE_DIRTY = 0;
    const STATE_CLEAN = 1;
    /**
     * @var array The array of SQL parts collected.
     */
    private $SQLBlocks = [
        'select' => [],
        'from' => [],
        'join' => [],
        'set' => [],
        'where' => null,
        'groupBy' => [],
        'having' => null,
        'orderBy' => [],
        'values' => [],
        'limit' => null
    ];
      /**
 *
 * Either appends to or replaces a single, generic query part.
 *
 * The available parts are: 'select', 'from', 'set', 'where',
 * 'groupBy', 'having' and 'orderBy'.
 *
 * @param $sqlPartName
 * @param $sqlPart
 * @param bool $append
 * @return $this
 */

    private function addSQLBlock($sqlPartName, $sqlPart, $append = false)
    {
        $isArray = is_array($sqlPart);
        $isMultiple = is_array($this->SQLBlocks[$sqlPartName]);
        if ($isMultiple && !$isArray)
            $sqlPart = array($sqlPart);
        $this->SQLState = self::STATE_DIRTY;
        .....(some other code that's not relevant)
    }
}

so please can anyone tell me what's he's doing and what is the purpose of the STATE_CLEAN and STATE_DIRTY consts thank you.


Solution

  • All i could think of is that STATE_DIRTY/STATE_CLEAN are some kind of a flag to tell that the Query body which is represented by $this->SQLBlocks has been changed or not from the last use of the object. someone correct me if i am wrong