Project

General

Profile

Bug #22104 » 13504_dbal.diff

Administrator Admin, 2010-02-10 21:16

View differences:

class.ux_t3lib_db.php (working copy)
}
/**
* Truncates a table.
*
* @param string Database tablename
* @return mixed Result from handler
*/
public function exec_TRUNCATETABLEquery($table) {
if ($this->debug) {
$pt = t3lib_div::milliseconds();
}
// Do table/field mapping:
$ORIG_tableName = $table;
if ($tableArray = $this->map_needMapping($table)) {
// Table name:
if ($this->mapping[$table]['mapTableName']) {
$table = $this->mapping[$table]['mapTableName'];
}
}
// Select API
$this->lastHandlerKey = $this->handler_getFromTableList($ORIG_tableName);
switch ((string)$this->handlerCfg[$this->lastHandlerKey]['type']) {
case 'native':
$this->lastQuery = $this->TRUNCATETABLEquery($table);
$sqlResult = mysql_query($this->lastQuery, $this->handlerInstance[$this->lastHandlerKey]['link']);
break;
case 'adodb':
$this->lastQuery = $this->TRUNCATETABLEquery($table);
$sqlResult = $this->handlerInstance[$this->lastHandlerKey]->_query($this->lastQuery, FALSE);
break;
case 'userdefined':
$sqlResult = $this->handlerInstance[$this->lastHandlerKey]->exec_TRUNCATETABLEquery($table,$where);
break;
}
if ($this->printErrors && $this->sql_error()) {
debug(array($this->lastQuery, $this->sql_error()));
}
if ($this->debug) {
$this->debugHandler(
'exec_TRUNCATETABLEquery',
t3lib_div::milliseconds() - $pt,
array(
'handlerType' => $hType,
'args' => array($table),
'ORIG_from_table' => $ORIG_tableName
)
);
}
// Return result:
return $sqlResult;
}
/**
* Executes a query.
* EXPERIMENTAL since TYPO3 4.4.
*
......
$table = $queryParts['TABLE'];
$whereClause = isset($queryParts['WHERE']) ? $this->SQLparser->compileWhereClause($queryParts['WHERE']) : '1=1';
return $this->exec_DELETEquery($table, $whereClause);
case 'TRUNCATETABLE':
$table = $queryParts['TABLE'];
return $this->exec_TRUNCATETABLEquery($table);
}
}
......
return $query;
}
/**
* Creates a TRUNCATE TABLE SQL-statement
*
* @param string See exec_TRUNCATETABLEquery()
* @return string Full SQL query for TRUNCATE TABLE
*/
public function TRUNCATETABLEquery($table) {
$table = $this->quoteFromTables($table);
// Call parent method to build actual query
$query = parent::TRUNCATETABLEquery($table);
if ($this->debugOutput || $this->store_lastBuiltQuery) {
$this->debug_lastBuiltQuery = $query;
}
return $query;
}
/**************************************
*
* Functions for quoting table/field names
......
$this->map_genericQueryParsed($parsedQuery);
break;
case 'INSERT':
case 'TRUNCATETABLE':
$this->map_genericQueryParsed($parsedQuery);
break;
case 'CREATEDATABASE':
......
case 'adodb':
// Compiling query:
$compiledQuery = $this->SQLparser->compileSQL($this->lastParsedAndMappedQueryArray);
if ($this->lastParsedAndMappedQueryArray['type']=='INSERT') {
return $this->exec_INSERTquery($this->lastParsedAndMappedQueryArray['TABLE'],$compiledQuery);
switch ($this->lastParsedAndMappedQueryArray['type']) {
case 'INSERT':
return $this->exec_INSERTquery($this->lastParsedAndMappedQueryArray['TABLE'], $compiledQuery);
case 'TRUNCATETABLE':
return $this->exec_TRUNCATETABLEquery($this->lastParsedAndMappedQueryArray['TABLE']);
}
return $this->handlerInstance[$this->lastHandlerKey]->DataDictionary->ExecuteSQLArray($compiledQuery);
break;
......
$t = $sqlPartArray[$k]['table'] ? $sqlPartArray[$k]['table'] : $defaultTable;
// Mapping field name, if set:
if (is_array($this->mapping[$t]['mapFieldNames']) && $this->mapping[$t]['mapFieldNames'][$sqlPartArray[$k]['field']]) {
if (is_array($this->mapping[$t]['mapFieldNames']) && isset($this->mapping[$t]['mapFieldNames'][$sqlPartArray[$k]['field']])) {
$sqlPartArray[$k]['field'] = $this->mapping[$t]['mapFieldNames'][$sqlPartArray[$k]['field']];
}
tests/sqlparser_general_testcase.php (working copy)
/**
* @test
* http://bugs.typo3.org/view.php?id=13504
*/
public function canParseTruncateTable() {
$sql = 'TRUNCATE TABLE be_users';
$expected = $sql;
$actual = $this->cleanSql($this->fixture->debug_testSQL($sql));
$this->assertEquals($expected, $actual);
}
/**
* @test
* @see http://bugs.typo3.org/view.php?id=13412
*/
public function canParseAndCompileBetweenOperator() {
tests/db_oracle_testcase.php (working copy)
/**
* @test
* http://bugs.typo3.org/view.php?id=13504
*/
public function truncateTableQueryIsProperlyQuoted() {
$query = $this->cleanSql($GLOBALS['TYPO3_DB']->TRUNCATETABLEquery('be_users'));
$expected = 'TRUNCATE TABLE "be_users"';
$this->assertEquals($expected, $query);
}
/**
* @test
* @see http://bugs.typo3.org/view.php?id=2438
*/
public function distinctFieldIsProperlyQuoted() {
(3-3/5)