예제 #1
0
 /**
  * Clears URL cache if it is found in the alias table.
  *
  * @param string $tableName
  * @param int $recordId
  * @return void
  */
 protected function clearUrlCacheForAliasChanges($tableName, $recordId)
 {
     if (!preg_match('/^(?:pages|sys_|cf_)/', $tableName)) {
         $expirationTime = time() + 30 * 24 * 60 * 60;
         // This check would be sufficient for most cases but only when id_field is 'uid' in the configuration
         $result = $this->databaseConnection->sql_query('SELECT uid,expire,url_cache_id FROM ' . 'tx_realurl_uniqalias LEFT JOIN tx_realurl_uniqalias_cache_map ON uid=alias_uid ' . 'WHERE tablename=' . $this->databaseConnection->fullQuoteStr($tableName, 'tx_realurl_uniqalias') . ' ' . 'AND value_id=' . $recordId);
         while (FALSE !== ($data = $this->databaseConnection->sql_fetch_assoc($result))) {
             if ($data['url_cache_id']) {
                 $this->cache->clearUrlCacheById($data['url_cache_id']);
                 $this->databaseConnection->exec_DELETEquery('tx_realurl_uniqalias_cache_map', 'uid=' . (int) $data['uid']);
             }
             if ((int) $data['expire'] === 0) {
                 $this->databaseConnection->exec_UPDATEquery('tx_realurl_uniqalias', 'uid=' . (int) $data['uid'], array('expire' => $expirationTime));
             }
         }
         $this->databaseConnection->sql_free_result($result);
     }
 }
 /**
  * @test
  * @see http://forge.typo3.org/issues/21902
  */
 public function locateStatementWithExternalTableIsProperlyRemapped()
 {
     $selectFields = '*, CASE WHEN' . ' LOCATE(' . $this->subject->fullQuoteStr('(fce)', 'tx_templavoila_tmplobj') . ', tx_templavoila_tmplobj.datastructure, 4)>0 THEN 2' . ' ELSE 1' . ' END AS scope';
     $fromTables = 'tx_templavoila_tmplobj';
     $whereClause = '1=1';
     $groupBy = '';
     $orderBy = '';
     $remappedParameters = $this->subject->_call('map_remapSELECTQueryParts', $selectFields, $fromTables, $whereClause, $groupBy, $orderBy);
     $result = $this->subject->_call('SELECTqueryFromArray', $remappedParameters);
     $expected = 'SELECT *, CASE WHEN CHARINDEX(\'(fce)\', "tx_templavoila_tmplobj"."ds", 4) > 0 THEN 2 ELSE 1 END AS "scope" FROM "tx_templavoila_tmplobj" WHERE 1 = 1';
     $this->assertEquals($expected, $this->cleanSql($result));
 }
 /**
  * @test
  * @see http://forge.typo3.org/issues/21902
  */
 public function locateStatementWithPositionIsProperlyQuoted()
 {
     $result = $this->subject->SELECTquery('*, CASE WHEN' . ' LOCATE(' . $this->subject->fullQuoteStr('(fce)', 'tx_templavoila_tmplobj') . ', datastructure, 4)>0 THEN 2' . ' ELSE 1' . ' END AS scope', 'tx_templavoila_tmplobj', '1=1');
     $expected = 'SELECT *, CASE WHEN INSTR("datastructure", \'(fce)\', 4) > 0 THEN 2 ELSE 1 END AS "scope" FROM "tx_templavoila_tmplobj" WHERE 1 = 1';
     $this->assertEquals($expected, $this->cleanSql($result));
 }
예제 #4
0
 /**
  * Executes a prepared query.
  *
  * @return bool TRUE on success or FALSE on failure
  */
 public function execute()
 {
     $queryParts = $this->queryComponents['queryParts'];
     $numberOfParameters = count($this->parameters);
     for ($i = 0; $i < $numberOfParameters; $i++) {
         $value = $this->parameters[$i]['value'];
         switch ($this->parameters[$i]['type']) {
             case 's':
                 if ($value !== NULL) {
                     $value = $this->databaseConnection->fullQuoteStr($value, $this->queryComponents['ORIG_tableName']);
                 }
                 break;
             case 'i':
                 $value = (int) $value;
                 break;
             default:
                 // Same error as in \TYPO3\CMS\Core\Database\PreparedStatement::execute()
                 throw new \InvalidArgumentException(sprintf('Unknown type %s used for parameter %s.', $this->parameters[$i]['type'], $i + 1), 1281859196);
         }
         $queryParts[$i * 2 + 1] = $value;
     }
     // Standard query from now on
     $query = implode('', $queryParts);
     $limit = $this->queryComponents['LIMIT'];
     if ($this->databaseConnection->runningADOdbDriver('postgres')) {
         // Possibly rewrite the LIMIT to be PostgreSQL-compatible
         $splitLimit = GeneralUtility::intExplode(',', $limit);
         // Splitting the limit values:
         if ($splitLimit[1]) {
             // If there are two parameters, do mapping differently than otherwise:
             $numRows = $splitLimit[1];
             $offset = $splitLimit[0];
             $limit = $numRows . ' OFFSET ' . $offset;
         }
     }
     if ($limit !== '') {
         $splitLimit = GeneralUtility::intExplode(',', $limit);
         // Splitting the limit values:
         if ($splitLimit[1]) {
             // If there are two parameters, do mapping differently than otherwise:
             $numRows = $splitLimit[1];
             $offset = $splitLimit[0];
         } else {
             $numRows = $splitLimit[0];
             $offset = 0;
         }
         $this->recordSet = $this->databaseConnection->handlerInstance[$this->databaseConnection->lastHandlerKey]->SelectLimit($query, $numRows, $offset);
         $this->databaseConnection->lastQuery = $this->recordSet->sql;
     } else {
         $this->databaseConnection->lastQuery = $query;
         $this->recordSet = $this->databaseConnection->handlerInstance[$this->databaseConnection->lastHandlerKey]->_Execute($this->databaseConnection->lastQuery);
     }
     if ($this->recordSet !== FALSE) {
         $success = TRUE;
         $this->recordSet->TYPO3_DBAL_handlerType = 'adodb';
         // Setting handler type in result object (for later recognition!)
         //$this->recordSet->TYPO3_DBAL_tableList = $queryComponents['ORIG_tableName'];
     } else {
         $success = FALSE;
     }
     return $success;
 }