[TYPO3-core] FYI: bitwise & is not portable SQL

Martin Kutschker Martin.Kutschker at n0spam-blackbox.net
Wed Dec 13 12:07:24 CET 2006

Martin Kutschker schrieb:
> Karsten Dambekalns schrieb:
>> Hi.
>> On 09.11.2006, at 09:05, Dmitry Dulepov wrote:
>> As I write in that thread on the dev list I am working on fixing this 
>> in DBAL. I have not yet found a way to not use & at all in that case. 
>> If anybody has an idea, please tell me...
> For this special case: [NOTE: page permission check]
> Make the Core function so that the code that generates the query can 
> easily be changed in an XCLASS. Make DBAL test explicitely for Oracle an 
> run the query directly, so no SQL parsing code interferes with BITAND().

Currently ADOdb has a few helper functions for generating stuff like 
IFNULL(a,b) in a portable way, but nothing to help avoiding the Oracle 
bitwise AND problem.

I suggest to add a bitwise AND helper to t3lib_db (and possible map the 
ADOdb helpers as well).

// $a and $b must be properly escaped and quuoted by the caller!
function sql_bitand($table,$a,$b) {
   return '('.$a.' & '.$b.')';

DBAL simply has to check if $table is mapped to Oracle:

function sql_bitand($table,$a,$b) {
   if (is_oracle($table) {
     return 'BITAND('.$a.','.$b.')';
   } else {

This is a bugger for Mysql, but portable DB access means we have to use 
kludges sometimes.


More information about the TYPO3-team-core mailing list