codegen bug: compound FK

Login or register to post comments
3 replies [Last post]
Offline
Joined: 06/25/2009

I just tried installing QCubed for the first time and it doesn't like my database.

Codegen chokes on FKs with multiple columns eg

CREATE TABLE `track` ( `track_num` int(11) NOT NULL, `artist_num` varchar(10) NOT NULL, `cd_num` int(10) unsigned NOT NULL, `track_title` varchar(30) NOT NULL, `length` time default NULL, PRIMARY KEY USING BTREE (`track_num`,`artist_num`,`cd_num`), KEY `fk_cd_num` (`cd_num`), KEY `fk_artist_num2` (`artist_num`,`cd_num`), CONSTRAINT `fk_artist_num2` FOREIGN KEY (`artist_num`, `cd_num`) REFERENCES `cd` (`artist_num`, `cd_num`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1

The module QMySqliDatabase.class.php at line 358:

$strTokenArray[2] is:  `cd` (`artist_num`, `cd_num`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1

then

                 $strTokenArray[2] = split(' ', $strTokenArray[2]);

gives

Array
(
    [0] => `cd`
    [1] => (`artist_num`,
    [2] => `cd_num`)
    [3] => )
    [4] => ENGINE=InnoDB
    [5] => DEFAULT
    [6] => CHARSET=latin1
)

then line 359

        $strTokenArray[3] = $strTokenArray[2][1];

sets $strTokenArray[3]=(`artist_num`,
losing cd_num

codegen aborts with

Invalid Key Definition: `artist_num`,
Exception Type:   Exception

Rendered Page:   Click here to view contents able to be rendered

Source File:   /var/www/local/qcubed/includes/qcodo/_core/database/QMySqliDatabase.class.php     Line:   259

OOPMan's picture
Offline
Joined: 11/07/2008

Hi, this is a known issue with the codegen in QCubed at the moment. It doesn't handle multi-column FKs and PKs very well at all.

Offline
Joined: 03/31/2008

Multi-column PKs are fine. Multi-column FKs are currently completely unsupported. You could however hand-code the appropriate LoadBy* functions if needed.

Offline
Joined: 06/25/2009

OK, I did try searching first. I'll think about designing using artificial keys instead - probably not a big deal.

Brett