Project

General

Profile

Actions

Bug #97233

closed

TCA: foreign_table_where generates error with more than one placeholder of type ###REC_FIELD_*###

Added by Michael Stopp about 2 years ago. Updated about 2 years ago.

Status:
Closed
Priority:
Should have
Assignee:
-
Category:
FormEngine aka TCEforms
Target version:
-
Start date:
2022-03-24
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
10
PHP Version:
7.3
Tags:
Complexity:
Is Regression:
Sprint Focus:

Description

In a TCA field with renderType selecSingle we tried to restrict data from a foreign table by setting this foreign_table_where clause (table name simplified for readability):

'foreign_table' => 'mytable',
'foreign_table_where' => 'AND {#mytable}.{#otype} = \'###REC_FIELD_otype###\' AND {#mytable}.{#lang} = \'###REC_FIELD_lang###\'',

This generated the following error:

Database Error
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'de'') AND ( 1=1) AND (`pages`.`uid` = `mytable`' at line 1. A SQL error occurred. This may indicate a schema mismatch between TCA and the database. Try running database compare in the Install Tool.

Trying to narrow the problem down, I simplified the foreign_table_where in various ways.

Just using one of the placeholders worked for both of them:

'foreign_table_where' => 'AND {#mytable}.{#otype} = \'###REC_FIELD_otype###\'',
'foreign_table_where' => 'AND {#mytable}.{#lang} = \'###REC_FIELD_lang###\'',

Using both conditions, but setting a hardcoded value for one of them, worked as well:

'foreign_table_where' => 'AND {#mytable}.{#otype} = \'other\' AND {#mytable}.{#lang} = \'###REC_FIELD_lang###\'',
'foreign_table_where' => 'AND {#mytable}.{#otype} = \'###REC_FIELD_otype###\' AND {#mytable}.{#lang} = \'de\'',

So both conditions work in principle and both placeholder of type ###REC_FIELD_*### work on their own, but used in combination an error is thrown.

BTW: in the original file, there is additionally a ###PID### placeholder in use, which doesn't cause any problems (whether it's there or not) and works correctly. So it really seems to be a problem with the ###REC_FIELD_*### placeholders.

Actions #1

Updated by Oliver Bartsch about 2 years ago

  • Status changed from New to Needs Feedback

Hi, thanks for creating this issue.

Is there any reason for adding extra quotes around the placeholders? It seems as they trigger the error. Using the following, I can't reproduce the reported SQL error:

'foreign_table_where' => 'AND {#mytable}.{#otype} = ###REC_FIELD_otype### AND {#mytable}.{#lang} = ###REC_FIELD_lang###',
Actions #2

Updated by Michael Stopp about 2 years ago

Since otype and lang are string values, I assumed I had to quote them in the where clause, as you would for regular SQL.

I just checked and it seems to work without the extra quotes. So thanks for your feedback! :-)

But some questions still remain for me:

Why do the 4 variations I mentioned work, despite having the qoutes?
And do you still have to use quotes, if you use a literal string value (as in my 3rd + 4th option)?

I think the documentation could be clearer in that respect.

Actions #3

Updated by Oliver Bartsch about 2 years ago

As far as I can see does the underlying code only remove leading and trailing quotes. This might lead to this effect. However quoting is always applied on creating the SQL query, see: https://github.com/TYPO3/typo3/blob/main/typo3/sysext/backend/Classes/Form/FormDataProvider/AbstractItemProvider.php#L688.

Actions #4

Updated by Michael Stopp about 2 years ago

Thanks for that! I think this issue can be closed.

Actions #5

Updated by Riccardo De Contardi about 2 years ago

  • Status changed from Needs Feedback to Closed

@Michael Stopp Thank you for your reply!

Closed as requested by the reporter

If you think that this is the wrong decision or I have misunderstood or experience the issue again, please reopen it or open a new issue with a reference to this one.

Thank you.

Actions

Also available in: Atom PDF