---
title: "von exec_SELECTquery zu pi_exec_query mit Tabellenrelation"
url: "https://www.typo3.net/d/62848-von-exec-selectquery-zu-pi-exec-query-mit-tabellenrelation"
source: "typo3.net"
tags: ["Extensions","Entwicklung","Frage"]
created: "2007-05-22"
last_reply: "2007-05-24"
replies: 15
solved: false
page: 1
pages: 1
lang: "de"
---

# von exec_SELECTquery zu pi_exec_query mit Tabellenrelation

Extensions › Entwicklung · 15 Antworten · gestartet 2007-05-22

## Eröffnungsbeitrag

**michelsweb** · 2007-05-22 · [Beitrag #1](https://www.typo3.net/d/62848-von-exec-selectquery-zu-pi-exec-query-mit-tabellenrelation/1)

Ich habe in meine Extension folgende exec_SELECTquery eingebaut:

```php
$res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
  'm.*, s.shipname AS ship_clear',
  'tx_kreuzfahrtspecials_main m, tx_kreuzfahrtspecials_ship s',
  'm.ship=s.uid and m.hidden=0 and m.deleted=0',
  '',
  'm.priority ASC',
  '');
```

Das Problem hierbei ist, dass die Start- und Endzeit nicht abgefragt werden. Also dachte ich an die pi_exec_query.
Nur: Wie kann ich die Datenbankrelation, die ich hier eingebaut habe, in der pi_exec_query parametrisieren?
Ich bin echt überfragt und mir qualmt der Kopf.

Hat jemand eine Idee?

## Antworten

### [#2](https://www.typo3.net/d/62848-von-exec-selectquery-zu-pi-exec-query-mit-tabellenrelation/2) · jenses · 2007-05-22

> **michelsweb schrieb:**
>
> Das Problem hierbei ist, dass die Start- und Endzeit nicht abgefragt werden.

Dafür gibt´s die feine Funktion cObj->enableFields.
Installiere dir am besten die Extension extdeveval,
dann hast du immer Zugriff auf Funktionsbeschreibungen der wichtigsten Klassen und Funktionen.

### [#3](https://www.typo3.net/d/62848-von-exec-selectquery-zu-pi-exec-query-mit-tabellenrelation/3) · michelsweb · 2007-05-22

Danke für den Hinweis, ich sehe mir das mal an!

### [#4](https://www.typo3.net/d/62848-von-exec-selectquery-zu-pi-exec-query-mit-tabellenrelation/4) · steffenk · 2007-05-23

um das auch für andere nochmal zu vertiefen:

$this->cObj->enableFields($table)

setzt das in eine SQL-Anweisung um, das im TCA in 'enableColumns' steht.
i.d.R. sind das die Felder
hidden, starttime, endtime und fe_group.
Zusätzlich wird noch deleted mit ausgewertet.

Man erreicht so mit einem Aufruf, das nur die tatsächlich sichtbaren Datensätze ausgewertet werden - erspart Tipperei und ist äussest praktisch.

### [#5](https://www.typo3.net/d/62848-von-exec-selectquery-zu-pi-exec-query-mit-tabellenrelation/5) · michelsweb · 2007-05-23

Danke für die Hinweise.
Kleine Frage zur Syntax:
Setze ich enableFields hinter die where clause?
Das würde dann so aussehen:

```php
$res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
  'm.*, s.shipname AS ship_clear',
  'tx_kreuzfahrtspecials_main m, tx_kreuzfahrtspecials_ship s',
  'm.ship=s.uid'.$this->cObj->enableFields('tx_kreuzfahrtspecials_main'),
  '',
  'm.priority ASC',
  '');
```

Oder setze ich das hinter die gesamte Query, also so:

```php
$res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
  'm.*, s.shipname AS ship_clear',
  'tx_kreuzfahrtspecials_main m, tx_kreuzfahrtspecials_ship s',
  'm.ship=s.uid',
  '',
  'm.priority ASC',
  '');
  $this->cObj->enableFields('tx_kreuzfahrtspecials_main')
```

???

Ich habe viele Threads gelesen (und mir natürlich auch ExtDevEval angesehen!) und bin dabei auf beide Varianten gestoßen. Keine davon scheint bei mir zu funktionieren, obwohl die entsprechenden enableColumns im TCA stehen.

### [#6](https://www.typo3.net/d/62848-von-exec-selectquery-zu-pi-exec-query-mit-tabellenrelation/6) · steffenk · 2007-05-23

Der erste Syntax ist richtig.
Lass Dir die Query doch mal ausgeben:

```php
t3lib_div::debug($GLOBALS['TYPO3_DB']->SELECTquery(
'm.*, s.shipname AS ship_clear',
'tx_kreuzfahrtspecials_main m, tx_kreuzfahrtspecials_ship s',
'm.ship=s.uid'.$this->cObj->enableFields('tx_kreuzfahrtspecials_main'),
'',
'm.priority ASC',
''));
```

### [#7](https://www.typo3.net/d/62848-von-exec-selectquery-zu-pi-exec-query-mit-tabellenrelation/7) · jenses · 2007-05-23

$this->cObj->enableFields() kommt nicht mit den Tabellen-Aliassen(heißen die so? also m und s) klar.
Also return von $this->cObj->enableFields per RegExp bearbeiten,
oder Abfrage selber konstruieren,
die Vorlage liefert ja class.t3lib_page.php->enableFields().
Oder aber die Relation zwischen deinen Tabellen auf solidere Füße stellen,
z.B. mit mm-Relationen. Dafür gibt´s dann auch wieder die passenden Abfragefunktionen.

### [#8](https://www.typo3.net/d/62848-von-exec-selectquery-zu-pi-exec-query-mit-tabellenrelation/8) · steffenk · 2007-05-23

stimmt. (Aliases sollte es sein :) )
da hilft z.B.

```php
str_replace('tx_kreuzfahrtspecials_main','m',$this->cObj->enableFields('tx_kreuzfahrtspecials_main'))
```

### [#9](https://www.typo3.net/d/62848-von-exec-selectquery-zu-pi-exec-query-mit-tabellenrelation/9) · michelsweb · 2007-05-23

**Vielen Dank für die Denkanstöße!!!**
Ich werde mich gleich mal dran machen.

:D

### [#10](https://www.typo3.net/d/62848-von-exec-selectquery-zu-pi-exec-query-mit-tabellenrelation/10) · michelsweb · 2007-05-23

Die Ausgabe der Query lautet übrigens:

```html
|SELECT m.*, s.shipname AS ship_clear FROM tx_kreuzfahrtspecials_main m, tx_kreuzfahrtspecials_ship s WHERE m.ship=s.uid AND m.deleted=0 AND m.hidden=0 AND (m.starttime<=1179940836) AND (m.endtime=0 OR m.endtime>1179940836) AND (m.fe_group='' OR m.fe_group IS NULL OR m.fe_group='0' OR (m.fe_group LIKE '%,0,%' OR m.fe_group LIKE '0,%' OR m.fe_group LIKE '%,0' OR m.fe_group='0') OR (m.fe_group LIKE '%,-1,%' OR m.fe_group LIKE '-1,%' OR m.fe_group LIKE '%,-1' OR m.fe_group='-1')) ORDER BY m.priority ASC|
```

### [#11](https://www.typo3.net/d/62848-von-exec-selectquery-zu-pi-exec-query-mit-tabellenrelation/11) · steffenk · 2007-05-23

sieht doch gut aus :) Das gleiche musst Du allerdings für die 2.Tabelle machen.

### [#12](https://www.typo3.net/d/62848-von-exec-selectquery-zu-pi-exec-query-mit-tabellenrelation/12) · michelsweb · 2007-05-23

Das soll dann vermutlich so aussehen:

```html
|SELECT tx_kreuzfahrtspecials_main.*, tx_kreuzfahrtspecials_ship.shipname AS ship_clear FROM tx_kreuzfahrtspecials_main, tx_kreuzfahrtspecials_ship WHERE tx_kreuzfahrtspecials_main.ship=tx_kreuzfahrtspecials_ship.uid AND tx_kreuzfahrtspecials_main.deleted=0 AND tx_kreuzfahrtspecials_main.hidden=0 AND (tx_kreuzfahrtspecials_main.starttime<=1179942133) AND (tx_kreuzfahrtspecials_main.endtime=0 OR tx_kreuzfahrtspecials_main.endtime>1179942133) AND (tx_kreuzfahrtspecials_main.fe_group='' OR tx_kreuzfahrtspecials_main.fe_group IS NULL OR tx_kreuzfahrtspecials_main.fe_group='0' OR (tx_kreuzfahrtspecials_main.fe_group LIKE '%,0,%' OR tx_kreuzfahrtspecials_main.fe_group LIKE '0,%' OR tx_kreuzfahrtspecials_main.fe_group LIKE '%,0' OR tx_kreuzfahrtspecials_main.fe_group='0') OR (tx_kreuzfahrtspecials_main.fe_group LIKE '%,-1,%' OR tx_kreuzfahrtspecials_main.fe_group LIKE '-1,%' OR tx_kreuzfahrtspecials_main.fe_group LIKE '%,-1' OR tx_kreuzfahrtspecials_main.fe_group='-1')) AND tx_kreuzfahrtspecials_ship.deleted=0 AND tx_kreuzfahrtspecials_ship.hidden=0 AND (tx_kreuzfahrtspecials_ship.starttime<=1179942133) AND (tx_kreuzfahrtspecials_ship.endtime=0 OR tx_kreuzfahrtspecials_ship.endtime>1179942133) AND (tx_kreuzfahrtspecials_ship.fe_group='' OR tx_kreuzfahrtspecials_ship.fe_group IS NULL OR tx_kreuzfahrtspecials_ship.fe_group='0' OR (tx_kreuzfahrtspecials_ship.fe_group LIKE '%,0,%' OR tx_kreuzfahrtspecials_ship.fe_group LIKE '0,%' OR tx_kreuzfahrtspecials_ship.fe_group LIKE '%,0' OR tx_kreuzfahrtspecials_ship.fe_group='0') OR (tx_kreuzfahrtspecials_ship.fe_group LIKE '%,-1,%' OR tx_kreuzfahrtspecials_ship.fe_group LIKE '-1,%' OR tx_kreuzfahrtspecials_ship.fe_group LIKE '%,-1' OR tx_kreuzfahrtspecials_ship.fe_group='-1')) ORDER BY m.priority ASC|
```

### [#13](https://www.typo3.net/d/62848-von-exec-selectquery-zu-pi-exec-query-mit-tabellenrelation/13) · Stoneage · 2007-05-23

Nur so ein Tip: Ich würde so Namen wie tx_kreuzfahrtspecials_main nach t24n abkürzen. 24 ist dabei die Anzahl der Buchstaben zwischen Anfang und Ende. Das erhöht die Lesbarkeit enorm, und ist einfach cooler.

### [#14](https://www.typo3.net/d/62848-von-exec-selectquery-zu-pi-exec-query-mit-tabellenrelation/14) · michelsweb · 2007-05-23

tx_kreuzfahrtspecials_main = t24n bzw. tx_kreuzfahrtspecials_ship = t24p?

### [#15](https://www.typo3.net/d/62848-von-exec-selectquery-zu-pi-exec-query-mit-tabellenrelation/15) · Stoneage · 2007-05-24

japp!

### [#16](https://www.typo3.net/d/62848-von-exec-selectquery-zu-pi-exec-query-mit-tabellenrelation/16) · michelsweb · 2007-05-24

**YUUUUHUUU!!!!!!**

Der Fall ist gelöst!

Dank allen beteiligten Helfern!!!

:D

---

Quelle: „von exec_SELECTquery zu pi_exec_query mit Tabellenrelation“, typo3.net, https://www.typo3.net/d/62848-von-exec-selectquery-zu-pi-exec-query-mit-tabellenrelation
Beiträge von Mitgliedern des Forums. Bitte mit Link auf die Diskussion zitieren.
