[TYPO3-core] RFC #11119: DBAL: Mapping in query does not takes care of remapping "table.field" in a WHERE clause

Michael Miousse mmiousse at infoglobe.ca
Tue May 19 14:59:38 CEST 2009


Le Mon, 18 May 2009 14:52:00 +0200, Xavier Perseguers a écrit :

> Hi,
> 
> This is a SVN patch request.
> 
> Type: Bugfix
> 
> Branches: trunk
> 
> BT reference:
> http://bugs.typo3.org/view.php?id=11119
> 
> Problem:
> When remapping name of table X, any query selecting data from table Y
> and having a WHERE condition on some field of table X won't get the name
> of table X remapped if it is given as a value of a comparison.
> 
> E.g. when using TemplaVoila with Oracle, one has to remap a table to
> prevent name length overflow:
> 
> $TYPO3_CONF_VARS['EXTCONF']['dbal']['mapping'] = array(
>      'tx_templavoila_datastructure' => array(
>          'mapTableName' => 'tx_templavoila_ds',
>      ),
> );
> 
> Any query selecting data on tx_templavoila_datastructure is in fact
> issued on table tx_templavoila_ds when accessing the database.
> 
> But if we edit a page, a query is issued on table pages with a condition
> on a field of tx_templavoila_datastructure in the "value" part of the
> comparison:
> 
> SELECT * FROM pages WHERE pages.uid = tx_templavoila_datastructure.pid
> 
> The current implementation of the mapping is not able to remap a table
> *and* a field name in the value part of the comparison, it handles a
> "table + field" value definition but only remap the field part.
> 
> Solution:
> Do not assume that the table name for the value part is the table used
> in the "FROM" part of the query and map both table and field names if
> needed.
> 
> --
> Xavier Perseguers
> DBAL-Member
> 
> http://xavier.perseguers.ch/en/tutorials/typo3.html Index:
> typo3/sysext/dbal/class.ux_t3lib_db.php
> =================================================================== ---
> typo3/sysext/dbal/class.ux_t3lib_db.php	(revision 5387) +++
> typo3/sysext/dbal/class.ux_t3lib_db.php	(working copy) @@ -2406,12
> +2406,22 @@
>  
>  						// do we have a field name in the value? // this is a very
>  						simplistic check, beware
> -					if(is_array($this->mapping[$t]['mapFieldNames']) &&
> (!is_numeric($sqlPartArray[$k]['value'][0]) &&
> !isset($sqlPartArray[$k]['value'][1]))) { +					if
> (!is_numeric($sqlPartArray[$k]['value'][0]) &&
> !isset($sqlPartArray[$k]['value'][1])) {
>  						$fieldArray = explode('.', $sqlPartArray[$k]['value'][0]);
> -						if(count($fieldArray)==1 &&
> isset($this->mapping[$t]['mapFieldNames'][$fieldArray[0]])) { +						if
> (count($fieldArray) == 1 &&
> is_array($this->mapping[$t]['mapFieldNames']) &&
> isset($this->mapping[$t]['mapFieldNames'][$fieldArray[0]])) {
>  							$sqlPartArray[$k]['value'][0] =
>  							$this->mapping[$t]['mapFieldNames'][$fieldArray[0]];
> -						} elseif(count($fieldArray)==2 &&
> isset($this->mapping[$t]['mapFieldNames'][$fieldArray[1]])) { -						
> $sqlPartArray[$k]['value'][0] =
> $fieldArray[0].'.'.$this->mapping[$t]['mapFieldNames'][$fieldArray[1]];
> +						} elseif (count($fieldArray) == 2) { +								// Map the external
> table
> +							$table = $fieldArray[0];
> +							if (isset($this->mapping[$fieldArray[0]]['mapTableName'])) { +		
> 					$table = $this->mapping[$fieldArray[0]]['mapTableName']; +							}
> +								// Map the field itself
> +							$field = $fieldArray[1];
> +							if (is_array($this->mapping[$fieldArray[0]]['mapFieldNames']) &&
> isset($this->mapping[$fieldArray[0]]['mapFieldNames'][$fieldArray[1]]))
> { +								$field =
> $this->mapping[$fieldArray[0]]['mapFieldNames'][$fieldArray[1]]; +						
> }
> +							$sqlPartArray[$k]['value'][0] = $table . '.' . $field;
>  						}
>  					}
>

+1 by reading and ill test it on thursday 
but im prety shure that it works fine cause i have juste realise that i
mad the prety same patch a while ago but did not submit it( i thought i did)
and it work fine for me. i have been using it for 3 month for now with no problem. 


More information about the TYPO3-team-core mailing list