Fork me on GitHub

Hack for DBUtil.class.php  Bottom

  • The following Hack for DBUtil.class.php permit create constraints en pntable.php.

    1. In the file DBUtil.class.php in the function createTable() after

    Code

    $dbconn   = DBConnectionStack::getConnection();
            $dict     = NewDataDictionary($dbconn);
            if (!isset($tabopt) || empty($tabopt)) {
                $tabopt = pnDBGetTableOptions();
            }
            $table    = $pntables[$tablename];


    add the following lines:

    Code

    // BEGING Support constraints
            // Hack Mod by UnderMedia S.A.
            $tabledef = $tablename . '_column_def';
            $tablecol = $tablename . '_column';
            $tableopt = $tablename . '_constraints';

            if(array_key_exists($tableopt,$pntables) && is_array($pntables[$tableopt])){
                foreach ($pntables[$tableopt] as $fk_column => $fk_reference){
                    $reference_table = $pntables[$fk_reference['table']];
                    $reference_column = $pntables[$fk_reference['table'] . '_column'][$fk_reference['column']];
                    $original_column = $pntables[$tablecol][$fk_column];
                    $tabopt['constraints'] .= ", CONSTRAINT FOREIGN KEY ($original_column) REFERENCES $reference_table ($reference_column) $fk_reference[accion]";     
                }
            }
            // END Support constraints


    2. In pntables.php you should create a array like the follow:

    Code

    $pntable['cancion_constraints'] = array ('top'  => array('table'    => "top",
                                                                 'column'   => "id",
                                                                 'accion'   => "ON UPDATE CASCADE ON DELETE CASCADE"));


    I don't know if the function createTable() is the correct or the hack can be put in the function getTableDefinition($tablename)...

    What do you think about it?

    Thanks!

    icon_smile



    edited by: netoec84, Mar 11, 2007 - 03:28 AM
  • I think your last idea is probably the better approach. Adding the code to getTableDefinition would then add the constraints for both createTable and changeTable - and since changeTable is effectively createTable should the table not exist then having the constraints in both methods would seem sensible.

    Could you submit a patch against the either SVN or the latest daily to the patch tracker and i'll include it in SVN.

    Thanks.

    -Mark

    --
    Visit My homepage and Zikula themes.

This list is based on users active over the last 60 minutes.