/** * @test */ public function getAutoIncrementReturnsOneForTruncatedTable() { Tx_Oelib_Db::enableQueryLogging(); $dbResult = Tx_Oelib_Db::getDatabaseConnection()->sql_query('TRUNCATE TABLE tx_oelib_test;'); if ($dbResult === FALSE) { throw new tx_oelib_Exception_Database(1418586819); } self::assertSame(1, $this->subject->getAutoIncrement('tx_oelib_test')); }
/** * Updates an integer field of a database table by one. This is mainly needed * for counting up the relation counter when creating a database relation. * * The field to update must be of type integer. * * @param string $tableName name of the table, must not be empty * @param int $uid the UID of the record to modify, must be > 0 * @param string $fieldName the field name of the field to modify, must not be empty * * @return void * * @throws tx_oelib_Exception_Database * @throws InvalidArgumentException * @throws BadMethodCallException */ public function increaseRelationCounter($tableName, $uid, $fieldName) { if (!$this->isTableNameAllowed($tableName)) { throw new InvalidArgumentException('The table name "' . $tableName . '" is invalid. This means it is either empty or not in the list of allowed tables.', 1331490960); } if (!Tx_Oelib_Db::tableHasColumn($tableName, $fieldName)) { throw new InvalidArgumentException('The table ' . $tableName . ' has no column ' . $fieldName . '.', 1331490986); } Tx_Oelib_Db::enableQueryLogging(); $databaseConnection = Tx_Oelib_Db::getDatabaseConnection(); $dbResult = $databaseConnection->sql_query('UPDATE ' . $tableName . ' SET ' . $fieldName . '=' . $fieldName . '+1 WHERE uid=' . $uid); if ($dbResult === FALSE) { throw new tx_oelib_Exception_Database(1418586263); } if ($databaseConnection->sql_affected_rows() === 0) { throw new BadMethodCallException('The table ' . $tableName . ' does not contain a record with UID ' . $uid . '.', 1331491003); } $this->markTableAsDirty($tableName); }