[12] | 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 | */
|
---|
| 11 | class 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 | ?> |
---|