PHP Classes

File: DATA/MySQL5/PrimaryKeyIndexingStrategy.php

Recommend this page to a friend!
  Classes of Martin Alterisio   DATA   DATA/MySQL5/PrimaryKeyIndexingStrategy.php   Download  
File: DATA/MySQL5/PrimaryKeyIndexingStrategy.php
Role: Class source
Content type: text/plain
Description: Strategy for mapping array offsets to primary key values.
Class: DATA
Access data stored in MySQL tables like arrays
Author: By
Last change: + anonymous access
Date: 17 years ago
Size: 1,502 bytes
 

Contents

Class file image Download
<?php
/**
 * @package DATA_MySQL5
 */

/**
 * Strategy for mapping array offsets to primary key values.
 */
class DATA_MySQL5_PrimaryKeyIndexingStrategy implements DATA_AssociativeIndexingStrategy {
   
/**
     * Stores table name on construction for future operations.
     * @var string
     */
   
protected $table;
   
   
/**
     * Constructor.
     *
     * @param string $table The table name.
     */
   
public function __construct($table) {
       
$this->table = $table;
    }
   
    public function
isSingleRowIndexing() {
        return
true;
    }
   
    protected function
getIndexField() {
       
$keys = DATA_MySQL5_Schema::getPrimaryKey($this->table);
        return
$keys[0];
    }
   
    public function
inboxRowOffset($row) {
       
$indexField = $this->getIndexField();
        try {
            return
DATA_MySQL5_Schema::getSQLTypeFactory($this->table, $indexField)->inbox($row);
        } catch (
DATA_SQLTypeConstraintFailed $exception) {
           
$exception->setTable($this->table);
           
$exception->setField($indexField);
            throw
$exception;
        }
    }
   
    public function
buildWhereConditions($row) {
       
$indexField = $this->getIndexField();
        return
"`{$indexField}` = " . DATA_MySQL5_Access::prepareData($row);
    }
   
    public function
getAdditionalInsertFields($row) {
        return array(
           
$this->getIndexField() => $row
       
);
    }
}
?>