Example #1
0
 /**
  * Reads a record from the database (from this mapper's table) by the
  * WHERE clause provided. Hidden records will be retrieved as well.
  *
  * @throws tx_oelib_Exception_NotFound if there is no record in the DB
  *                                     which matches the WHERE clause
  * @throws tx_oelib_Exception_NotFound if database access is disabled
  *
  * @param string[] $whereClauseParts
  *        WHERE clause parts for the record to retrieve, each element must consist of a column name as key and a value to
  *        search for as value (will automatically get quoted), must not be empty
  *
  * @return string[] the record from the database, will not be empty
  */
 protected function retrieveRecord(array $whereClauseParts)
 {
     if (!$this->hasDatabaseAccess()) {
         throw new tx_oelib_Exception_NotFound('No record can be retrieved from the database because database' . ' access is disabled for this mapper instance.');
     }
     $databaseConnection = Tx_Oelib_Db::getDatabaseConnection();
     $whereClauses = array($this->getUniversalWhereClause(TRUE));
     foreach ($whereClauseParts as $key => $value) {
         $columnDefinition = Tx_Oelib_Db::getColumnDefinition($this->getTableName(), $key);
         $whereClauses[] = $key . ' = ' . (strpos($columnDefinition['Type'], 'int') !== FALSE ? $value : $databaseConnection->fullQuoteStr($value, $this->getTableName()));
     }
     $whereClause = implode(' AND ', $whereClauses);
     try {
         $data = Tx_Oelib_Db::selectSingle($this->columns, $this->getTableName(), $whereClause);
     } catch (tx_oelib_Exception_EmptyQueryResult $exception) {
         throw new tx_oelib_Exception_NotFound('The record where "' . $whereClause . '" could not be retrieved from the table ' . $this->getTableName() . '.');
     }
     return $data;
 }
Example #2
0
 /**
  * @test
  */
 public function getColumnDefinitionReturnsArrayThatContainsFieldName()
 {
     $definition = Tx_Oelib_Db::getColumnDefinition('tx_oelib_test', 'title');
     self::assertSame('title', $definition['Field']);
 }