src/snac/server/database/SQL.php
/**
     * Select text records. Several tables have identical structure so don't copy/paste, just call
     * this. DBUtils has code to turn the return values into objects in a Constellation object.
     *
     * Solve the multi-version problem by joining to a subquery.
     *
     * @param string[] $vhInfo associative list with keys: version, ic_id.
     *
     * @param string $table The table this text is related to.
     *
     * @return string[][] Return list of an associative list with keys: id, version, ic_id,
     * text. There may be multiple rows returned.
     *
     */
Select text records. Several tables have identical structure so don't copy/paste, just call
this. DBUtils has code to turn the return values into objects in a Constellation object.

Solve the multi-version problem by joining to a subquery.

@param string[] $vhInfo associative list with keys: version, ic_id.

@param string $table The table this text is related to.

@return string[][] Return list of an associative list with keys: id, version, ic_id,
text. There may be multiple rows returned.
Select text records . Several tables have identical structure so don ' t copy / paste just call this . DBUtils has code to turn the return values into objects in a Constellation object . Solve the multi - version problem by joining to a subquery . @param string [] $vhInfo associative list with keys : version ic_id . @param string $table The table this text is related to . @return string [] [] Return list of an associative list with keys : id version ic_id text . There may be multiple rows returned .
protected function selectTextCore($vhInfo, $table)
    {
        $approved_table = array('convention_declaration' => 1,
                                'structure_genealogy' => 1,
                                'general_context' => 1,
                                'mandate' => 1);
        if (! isset($approved_table[$table]))
        {
            die("Tried to select on non-approved table: $table\n");
        }
        $qq = "select_$table";
        $this->sdb->prepare($qq,
                            sprintf(
                                'select
                                aa.id, aa.version, aa.ic_id, aa.text
                                from %s aa,
                                (select id, max(version) as version from %s where version<=$1 and ic_id=$2 group by id) as bb
                                where not aa.is_deleted and
                                aa.id=bb.id
                                and aa.version=bb.version', $table, $table));
        $result = $this->sdb->execute($qq,
                                      array($vhInfo['version'],
                                            $vhInfo['ic_id']));
        $all = array();
        while($row = $this->sdb->fetchrow($result))
        {
            array_push($all, $row);
        }
        $this->sdb->deallocate($qq);
        return $all;
    }
protected function selectTextCore ( $ vhInfo , $ table ) { $ approved_table = array ( 'convention_declaration' => 1 , 'structure_genealogy' => 1 , 'general_context' => 1 , 'mandate' => 1 ) ; if ( ! isset ( $ approved_table [ $ table ] ) ) { die ( " Tried to select on non-approved table:  $ table \n " ) ; } $ qq = " select_ $ table " ; $ this -> sdb -> prepare ( $ qq , sprintf ( 'select
                                aa.id, aa.version, aa.ic_id, aa.text
                                from %s aa,
                                (select id, max(version) as version from %s where version<=$1 and ic_id=$2 group by id) as bb
                                where not aa.is_deleted and
                                aa.id=bb.id
                                and aa.version=bb.version' , $ table , $ table ) ) ; $ result = $ this -> sdb -> execute ( $ qq , array ( $ vhInfo [ 'version' ] , $ vhInfo [ 'ic_id' ] ) ) ; $ all = array ( ) ; while ( $ row = $ this -> sdb -> fetchrow ( $ result ) ) { array_push ( $ all , $ row ) ; } $ this -> sdb -> deallocate ( $ qq ) ; return $ all ; }
Select text records.
Select text records .
/*
             * Trying something not approved is fatal.
             */ /*
         * String interpolation would require escaping $1 and $2 so just use sprintf() which always works.
         */