Пример #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;
 }
Пример #2
0
 /**
  * @test
  */
 public function saveCanSaveFloatDataToStringColumn()
 {
     $model = new Tx_Oelib_Tests_Unit_Fixtures_TestingModel();
     $model->setData(array('string_data' => 9.5));
     $this->subject->save($model);
     self::assertSame(array('string_data' => '9.5'), Tx_Oelib_Db::selectSingle('string_data', 'tx_oelib_test', 'uid = ' . $model->getUid()));
 }
Пример #3
0
 /**
  * @test
  */
 public function increaseRelationCounterIncreasesNonZeroFieldValueByOne()
 {
     $uid = $this->subject->createRecord('tx_oelib_test', array('related_records' => 41));
     $this->subject->increaseRelationCounter('tx_oelib_test', $uid, 'related_records');
     $row = Tx_Oelib_Db::selectSingle('related_records', 'tx_oelib_test', 'uid = ' . $uid);
     self::assertSame(42, (int) $row['related_records']);
 }
Пример #4
0
 /**
  * @test
  */
 public function selectSingleCanUseOffset()
 {
     $this->testingFramework->createRecord('tx_oelib_test', array('title' => 'Title A'));
     $uid = $this->testingFramework->createRecord('tx_oelib_test', array('title' => 'Title B'));
     self::assertSame(array('uid' => (string) $uid), Tx_Oelib_Db::selectSingle('uid', 'tx_oelib_test', '', '', 'title', 1));
 }
Пример #5
0
 /**
  * Reads the highest UID for a database table.
  *
  * This function may only be called after that the provided table name
  * has been checked to be non-empty, valid and pointing to an existing
  * database table that has the "uid" column.
  *
  * @param string $table the name of an existing table that has the "uid" column
  *
  * @return int the highest UID from this table, will be >= 0
  */
 protected function getMaximumUidFromTable($table)
 {
     $row = Tx_Oelib_Db::selectSingle('MAX(uid) AS uid', $table);
     return (int) $row['uid'];
 }