[TYPO3-dev] DBAL Usuage

Martin Kutschker martin.kutschker-n0spam at no5pam-blackbox.net
Sat Nov 17 11:04:55 CET 2007


belbono schrieb:
> Hi,
> 
> i´m having some problems with DBAL. Its makeing quotes where I don't 
> want them and this chrashes the wohle query.
> 
> 1st problem.
> $res = 
> $GLOBALS['TYPO3_DB']->exec_SELECTquery('MAX(UID)',strtoupper($table),'','','',''); 
> 
> As you can see I want the maximum UID from the $table.

I wouldn't do the strtoupper. If Oracle needs uppercase table names then 
DBAL should do the conversion automatically. Use table and column names 
as they are defined.

MAX() is a common function so in theory DBAL should know it and support 
it correctly, ie do the quoting for you.

If it doesn't try:

$GLOBALS['TYPO3_DB']->exec_query("SELECT max(uid) FROM $table");

Maybe this works better.

> 2nd problem
> Thats a bit harder I think
> 
> For a search function I´m building up query strings before I use them 
> with $GLOBALS['TYPO3_DB']->exec_SELECTquery()
> 
> I´m using several INNER JOIN statements which are causing trouble with 
> DBAL - Example:
> 
> $from= 'TAB1 INNER JOIN '.$tabname.' ON TAB1.UID = '.$tabname.'.TAB1_UID ';
> 
> I need to write the tablename before the attributes to avoid ambiguous 
> columns !
> 
> After this I´m calling 
> $GLOBALS['TYPO3_DB']->exec_SELECTquery($select,$from,$where,'','','');
> 
> Under MySQL there is no trouble and I get a from part in my statement 
> like this:
> TAB1 INNER JOIN TAB2 ON TAB1.UID = TAB2.TAB1_UID
> 
> When using the extension under Oracle it makes something weird like:
> 
> TAB1 INNER JOIN TAB2 ON "TAB1.UID = "TAB2.TAB1_UID"
> 
> At first I tried to quote the UID by hand - but this made it just worse.
> ...JOIN TAB2 ON "TAB1."UID" = TAB2.........
> 
> My question: Is it generally possible to build such statements in a 
> proper way so that MySQL and Oracle can handle them? - and if yes whats 
> wrong here ?

Try using barackets around the ON part of the JOIN:

TAB1 INNER JOIN TAB2 ON (TAB1.UID = TAB2.TAB1_UID)

Also try spelling the tables names as found in the ext_tables.sql files.

Masi




More information about the TYPO3-dev mailing list