source: Dev/branches/rest-dojo-ui/server/rdfapi/sparql/SparqlEngineDb/SqlMerger.php @ 256

Last change on this file since 256 was 256, checked in by hendrikvanantwerpen, 13 years ago

Reworked project structure based on REST interaction and Dojo library. As
soon as this is stable, the old jQueryUI branch can be removed (it's
kept for reference).

File size: 1.4 KB
Line 
1<?php
2
3/**
4*   Creates an sql string from an sql array
5*
6*   @author Christian Weiske <cweiske@cweiske.de>
7*   @license http://www.gnu.org/licenses/lgpl.html LGPL
8*
9*   @package sparql
10*/
11class SparqlEngineDb_SqlMerger
12{
13    public static function getSelect(Query $query, $arSqls, $strAdditional = '')
14    {
15        if (count($arSqls) == 1) {
16            return implode('', $arSqls[0]) . $strAdditional;
17        }
18
19        //union
20        $strUnion = 'UNION' .
21            ($query->getResultForm() == 'select distinct' ? '' : ' ALL');
22        $ar = array();
23        foreach ($arSqls as $arSql) {
24            $ar[] = implode('', $arSql) . $strAdditional;
25        }
26        return '(' . implode(') ' . $strUnion . ' (', $ar) . ')';
27    }//public static function getSelect(Query $query, $arSqls, $strAdditional = '')
28
29
30
31    public static function getCount(Query $query, $arSqls, $strAdditional = '')
32    {
33        if (count($arSqls) == 1) {
34            return 'SELECT COUNT(*) as count ' . $arSqls[0]['from'] . $arSqls[0]['where'] . $strAdditional;
35        }
36
37        $ar = array();
38        foreach ($arSqls as $arSql) {
39            $ar[] = implode('', $arSql) . $strAdditional;
40        }
41        return 'SELECT (' . implode(') + (', $ar) . ') as count';
42    }//public static function getCount(Query $query, $arSqls, $strAdditional = '')
43
44}//class SparqlEngineDb_SqlMerger
45
46?>
Note: See TracBrowser for help on using the repository browser.