[TYPO3-dev] DBAL Usuage
belbono
belbono at gmx.de
Thu Nov 15 11:47:10 CET 2007
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.
In SQL it would be : SELECT MAX(UID) FROM MYTABLE;
This works fine with MySQL, but i´m using DBAL, because I want to run my
extension on a ORACLE System.
In Oracle I need it like this: SELECT MAX("UID") FROM MYTABLE;
So using $GLOBALS['TYPO3_DB']->fullQuoteStr() is recommended and
hopefully might solve my problem by changing my code to
$res =
$GLOBALS['TYPO3_DB']->exec_SELECTquery('MAX($GLOBALS['TYPO3_DB']->fullQuoteStr(
'UID', 'MYTABLE' ))',strtoupper($table),'','','','');
So far to the first thing... if there is still something wrong with my
idea, plase let me know.
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 ?
regards,
Alex
More information about the TYPO3-dev
mailing list