ARC2_StoreDeleteQueryHandler::deleteTriples PHP Method

deleteTriples() public method

*
public deleteTriples ( )
    function deleteTriples()
    {
        $r = 0;
        $dbv = $this->store->getDBVersion();
        $tbl_prefix = $this->store->getTablePrefix();
        $con = $this->store->getDBCon();
        /* graph restriction */
        $tgs = $this->infos['query']['target_graphs'];
        $gq = '';
        foreach ($tgs as $g) {
            if ($g_id = $this->getTermID($g, 'g')) {
                $gq .= $gq ? ', ' . $g_id : $g_id;
            }
        }
        $gq = $gq ? ' AND G.g IN (' . $gq . ')' : '';
        /* triples */
        foreach ($this->infos['query']['construct_triples'] as $t) {
            $q = '';
            $skip = 0;
            foreach (array('s', 'p', 'o') as $term) {
                if (isset($t[$term . '_type']) && preg_match('/(var)/', $t[$term . '_type'])) {
                    //$skip = 1;
                } else {
                    $term_id = $this->getTermID($t[$term], $term);
                    $q .= ($q ? ' AND ' : '') . 'T.' . $term . '=' . $term_id;
                    /* explicit lang/dt restricts the matching */
                    if ($term == 'o') {
                        $o_lang = $this->v1('o_lang', '', $t);
                        $o_lang_dt = $this->v1('o_datatype', $o_lang, $t);
                        if ($o_lang_dt) {
                            $q .= ($q ? ' AND ' : '') . 'T.o_lang_dt=' . $this->getTermID($o_lang_dt, 'lang_dt');
                        }
                    }
                }
            }
            if ($skip) {
                continue;
            }
            if ($gq) {
                $sql = $dbv < '04-01' ? 'DELETE ' . $tbl_prefix . 'g2t' : 'DELETE G';
                $sql .= '
          FROM ' . $tbl_prefix . 'g2t G 
          JOIN ' . $this->getTripleTable() . ' T ON (T.t = G.t' . $gq . ')
          WHERE ' . $q . '
        ';
                $this->refs_deleted = 1;
            } else {
                /* triples only */
                $sql = $dbv < '04-01' ? 'DELETE ' . $this->getTripleTable() : 'DELETE T';
                $sql .= ' FROM ' . $this->getTripleTable() . ' T WHERE ' . $q;
            }
            //$rs = mysql_query($sql, $con);
            $rs = $this->queryDB($sql, $con);
            $er = mysqli_error($con);
            if (!empty($er)) {
                $this->addError($er . ' in ' . $sql);
            }
            $r += mysqli_affected_rows($con);
        }
        return $r;
    }