function DelPair($relationName, $srcConcept, $srcAtom, $tgtConcept, $tgtAtom)
{
    if (func_num_args() != 5) {
        throw new Exception("Wrong number of arguments supplied for function DelPair(): " . func_num_args() . " arguments", 500);
    }
    Notifications::addLog("DelPair({$relationName},{$srcConcept},{$srcAtom},{$tgtConcept},{$tgtAtom})", 'ExecEngine');
    try {
        $database = Database::singleton();
        // Check if relation signature exists: $relationName[$srcConcept*$tgtConcept]
        $relation = Relation::isCombination($relationName, $srcConcept, $tgtConcept);
        $srcAtoms = explode('_AND', $srcAtom);
        $tgtAtoms = explode('_AND', $tgtAtom);
        if (count($srcAtoms) > 1) {
            throw new Exception('DelPair function call has more than one src atom', 501);
        }
        // 501: Not implemented
        if (count($tgtAtoms) > 1) {
            throw new Exception('DelPair function call has more than one tgt atom', 501);
        }
        // 501: Not implemented
        foreach ($srcAtoms as $a) {
            foreach ($tgtAtoms as $b) {
                $database->editDelete($relation, false, $a, $srcConcept, $b, $tgtConcept, 'ExecEngine');
            }
        }
        return 'Tuple (' . $srcAtom . ' - ' . $tgtAtom . ') deleted from ' . $relationName . '[' . $srcConcept . '*' . $tgtConcept . ']';
    } catch (Exception $e) {
        Notifications::addError('DelPair: ' . $e->getMessage());
    }
}
 public function editDelete($rel, $isFlipped, $stableAtom, $stableConcept, $modifiedAtom, $modifiedConcept, $source = 'User')
 {
     Notifications::addLog("editDelete({$rel}, " . var_export($isFlipped, true) . ", {$stableAtom}, {$stableConcept}, {$modifiedAtom}, {$modifiedConcept})", 'DATABASE');
     try {
         // This function is under control of transaction check!
         if (!isset($this->transaction)) {
             $this->startTransaction();
         }
         $stableAtom = $this->typeConversion($stableAtom, $stableConcept);
         $modifiedAtom = $this->typeConversion($modifiedAtom, $modifiedConcept);
         // Check if $rel, $srcConcept, $tgtConcept is a combination
         $srcConcept = $isFlipped ? $modifiedConcept : $stableConcept;
         $tgtConcept = $isFlipped ? $stableConcept : $modifiedConcept;
         $fullRelationSignature = Relation::isCombination($rel, $srcConcept, $tgtConcept);
         // Get table properties
         $table = Relation::getTable($fullRelationSignature);
         $srcCol = Relation::getSrcCol($fullRelationSignature);
         $tgtCol = Relation::getTgtCol($fullRelationSignature);
         // Determine which Col must be editited and which must be used in the WHERE statement
         $stableCol = $isFlipped ? $tgtCol : $srcCol;
         $modifiedCol = $isFlipped ? $srcCol : $tgtCol;
         // Escape atoms for use in query
         $modifiedAtomEsc = $this->escape($modifiedAtom);
         $stableAtomEsc = $this->escape($stableAtom);
         // Get database table information
         $tableStableColumnInfo = Relation::getTableColumnInfo($table, $stableCol);
         $tableModifiedColumnInfo = Relation::getTableColumnInfo($table, $modifiedCol);
         // If the modifiedCol can be set to null, we do an update
         if ($tableModifiedColumnInfo['null']) {
             $this->Exe("UPDATE `{$table}` SET `{$modifiedCol}` = NULL WHERE `{$stableCol}` = '{$stableAtomEsc}' AND `{$modifiedCol}` = '{$modifiedAtomEsc}'");
             // Elseif the stableCol can be set to null, we do an update
         } elseif ($tableStableColumnInfo['null']) {
             $this->Exe("UPDATE `{$table}` SET `{$stableCol}` = NULL WHERE `{$stableCol}` = '{$stableAtomEsc}' AND `{$modifiedCol}` = '{$modifiedAtomEsc}'");
             // Otherwise, binary table, so perform a delete
         } else {
             $this->Exe("DELETE FROM `{$table}` WHERE `{$stableCol}` = '{$stableAtomEsc}' AND `{$modifiedCol}` = '{$modifiedAtomEsc}'");
         }
         $this->addAffectedRelations($fullRelationSignature);
         // add relation to affected relations. Needed for conjunct evaluation.
         Hooks::callHooks('postDatabaseDelete', get_defined_vars());
     } catch (Exception $e) {
         // Catch exception and continue script
         Notifications::addError($e->getMessage());
     }
 }
Beispiel #3
0
function OverwritePopulation($rArray, $relationName, $concept)
{
    try {
        $database = Database::singleton();
        $fullRelationSignature = Relation::isCombination($relationName, $concept, $concept);
        $table = Relation::getTable($fullRelationSignature);
        $srcCol = Relation::getSrcCol($fullRelationSignature);
        $tgtCol = Relation::getTgtCol($fullRelationSignature);
        $query = "TRUNCATE TABLE {$table}";
        $database->Exe($query);
        foreach ($rArray as $src => $tgtArray) {
            foreach ($tgtArray as $tgt => $bool) {
                if ($bool) {
                    $query = "INSERT INTO {$table} (`{$srcCol}`, `{$tgtCol}`) VALUES ('{$src}','{$tgt}')";
                    $database->Exe($query);
                }
            }
        }
    } catch (Exception $e) {
        throw new Exception('OverwritePopulation: ' . $e->getMessage(), 500);
    }
}