Project

General

Profile

Feature #23051 » 14937_caching_dbal.diff

Administrator Admin, 2010-07-17 16:20

View differences:

class.ux_t3lib_sqlparser.php (working copy)
}
/**
* Checks if the submitted feature index contains a default value definition and the default value
*
* @param array $featureIndex A feature index as produced by parseFieldDef()
* @return boolean
* @see t3lib_sqlparser::parseFieldDef()
*/
public function checkEmptyDefaultValue($featureIndex) {
if (is_array($featureIndex['DEFAULT']['value'])) {
if (!is_numeric($featureIndex['DEFAULT']['value'][0]) && empty($featureIndex['DEFAULT']['value'][0])) {
return TRUE;
} else {
return FALSE;
}
}
return TRUE;
}
/**
* Implodes an array of WHERE clause configuration into a WHERE clause.
*
* DBAL-specific: The only(!) handled "calc" operators supported by parseWhereClause() are:
class.ux_t3lib_db.php (working copy)
// Internal, caching:
var $cache_handlerKeyFromTableList = array(); // Caching handlerKeys for table lists
var $cache_mappingFromTableList = array(); // Caching mapping information for table lists
var $cache_autoIncFields = array(); // parsed SQL from standard DB dump file
var $cache_fieldType = array(); // field types for tables/fields
var $cache_primaryKeys = array(); // primary keys
/**
* SQL parser
*
* @var tx_dbal_sqlengine
*/
var $SQLparser;
/**
* Installer
*
* @var t3lib_install
*/
var $Installer;
/**
* Constructor.
* Creates SQL parser object and imports configuration from $TYPO3_CONF_VARS['EXTCONF']['dbal']
......
}
/**
* Clears the cached field information file.
*
* @return void
* This function builds all definitions for mapped tables and fields
* @see cacheFieldInfo()
*/
public function clearCachedFieldInfo() {
if (file_exists(PATH_typo3conf . 'temp_fieldInfo.php')) {
unlink(PATH_typo3conf . 'temp_fieldInfo.php');
}
}
/**
* Caches the field information.
*
* @return void
*/
public function cacheFieldInfo() {
$extSQL = '';
$parsedExtSQL = array();
// try to fetch cached file first
// file is removed when admin_query() is called
if (file_exists(PATH_typo3conf . 'temp_fieldInfo.php')) {
$fdata = unserialize(t3lib_div::getUrl(PATH_typo3conf . 'temp_fieldInfo.php'));
$this->cache_autoIncFields = $fdata['incFields'];
$this->cache_fieldType = $fdata['fieldTypes'];
$this->cache_primaryKeys = $fdata['primaryKeys'];
} else {
// handle stddb.sql, parse and analyze
$extSQL = t3lib_div::getUrl(PATH_site . 't3lib/stddb/tables.sql');
$parsedExtSQL = $this->Installer->getFieldDefinitions_fileContent($extSQL);
$this->analyzeFields($parsedExtSQL);
// loop over all installed extensions
foreach ($GLOBALS['TYPO3_LOADED_EXT'] as $ext => $v) {
if (!is_array($v) || !isset($v['ext_tables.sql'])) {
continue;
}
// fetch db dump (if any) and parse it, then analyze
$extSQL = t3lib_div::getUrl($v['ext_tables.sql']);
$parsedExtSQL = $this->Installer->getFieldDefinitions_fileContent($extSQL);
$this->analyzeFields($parsedExtSQL);
}
$cachedFieldInfo = array('incFields' => $this->cache_autoIncFields, 'fieldTypes' => $this->cache_fieldType, 'primaryKeys' => $this->cache_primaryKeys);
$cachedFieldInfo = serialize($this->mapCachedFieldInfo($cachedFieldInfo));
// write serialized content to file
t3lib_div::writeFile(PATH_typo3conf . 'temp_fieldInfo.php', $cachedFieldInfo);
if (strcmp(t3lib_div::getUrl(PATH_typo3conf . 'temp_fieldInfo.php'), $cachedFieldInfo)) {
die('typo3temp/temp_incfields.php was NOT updated properly (written content didn\'t match file content) - maybe write access problem?');
}
}
}
/**
* Analyzes fields and adds the extracted information to the field type, auto increment and primary key info caches.
*
* @param array $parsedExtSQL The output produced by t3lib_install::getFieldDefinitions_fileContent()
* @return void
* @see t3lib_install::getFieldDefinitions_fileContent()
*/
protected function analyzeFields($parsedExtSQL) {
foreach ($parsedExtSQL as $table => $tdef) {
if (is_array($tdef['fields'])) {
foreach ($tdef['fields'] as $field => $fdef) {
$fdef = $this->SQLparser->parseFieldDef($fdef);
$this->cache_fieldType[$table][$field]['type'] = $fdef['fieldType'];
$this->cache_fieldType[$table][$field]['metaType'] = $this->MySQLMetaType($fdef['fieldType']);
$this->cache_fieldType[$table][$field]['notnull'] = (isset($fdef['featureIndex']['NOTNULL']) && !$this->SQLparser->checkEmptyDefaultValue($fdef['featureIndex'])) ? 1 : 0;
if (isset($fdef['featureIndex']['DEFAULT'])) {
$default = $fdef['featureIndex']['DEFAULT']['value'][0];
if (isset($fdef['featureIndex']['DEFAULT']['value'][1])) {
$default = $fdef['featureIndex']['DEFAULT']['value'][1] . $default . $fdef['featureIndex']['DEFAULT']['value'][1];
}
$this->cache_fieldType[$table][$field]['default'] = $default;
}
if (isset($fdef['featureIndex']['AUTO_INCREMENT'])) {
$this->cache_autoIncFields[$table] = $field;
}
if (isset($tdef['keys']['PRIMARY'])) {
$this->cache_primaryKeys[$table] = substr($tdef['keys']['PRIMARY'], 13, -1);
}
}
}
}
}
/**
* This function builds all definitions for mapped tables and fields
* @see cacheFieldInfo()
*/
protected function mapCachedFieldInfo($fieldInfo) {
if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['dbal']['mapping'])) {
foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['dbal']['mapping'] as $mappedTable => $mappedConf) {
......
return $str;
}
/**
* Return MetaType for native MySQL field type
*
* @param string native type as reported as in mysqldump files
* @return string Meta type (currenly ADOdb syntax only, http://phplens.com/lens/adodb/docs-adodb.htm#metatype)
*/
public function MySQLMetaType($t) {
switch (strtoupper($t)) {
case 'STRING':
case 'CHAR':
case 'VARCHAR':
case 'TINYBLOB':
case 'TINYTEXT':
case 'ENUM':
case 'SET': return 'C';
case 'TEXT':
case 'LONGTEXT':
case 'MEDIUMTEXT': return 'XL';
case 'IMAGE':
case 'LONGBLOB':
case 'BLOB':
case 'MEDIUMBLOB': return 'B';
case 'YEAR':
case 'DATE': return 'D';
case 'TIME':
case 'DATETIME':
case 'TIMESTAMP': return 'T';
case 'FLOAT':
case 'DOUBLE': return 'F';
case 'INT':
case 'INTEGER':
case 'TINYINT':
case 'SMALLINT':
case 'MEDIUMINT':
case 'BIGINT': return 'I8'; // we always return I8 to be on the safe side. Under some circumstances the fields are to small otherwise...
default: return 'N';
}
}
/**
* Return actual MySQL type for meta field type
*
* @param string Meta type (currenly ADOdb syntax only, http://phplens.com/lens/adodb/docs-adodb.htm#metatype)
(4-4/5)