sqlquery.class.inc.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585
  1. <?php
  2. // Copyright (C) 2010 Combodo SARL
  3. //
  4. // This program is free software; you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation; version 3 of the License.
  7. //
  8. // This program is distributed in the hope that it will be useful,
  9. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. // GNU General Public License for more details.
  12. //
  13. // You should have received a copy of the GNU General Public License
  14. // along with this program; if not, write to the Free Software
  15. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. /**
  17. * SQLQuery
  18. * build an mySQL compatible SQL query
  19. *
  20. * @author Erwan Taloc <erwan.taloc@combodo.com>
  21. * @author Romain Quetiez <romain.quetiez@combodo.com>
  22. * @author Denis Flaven <denis.flaven@combodo.com>
  23. * @license http://www.opensource.org/licenses/gpl-3.0.html LGPL
  24. */
  25. /**
  26. * SQLQuery
  27. * build an mySQL compatible SQL query
  28. *
  29. * @package iTopORM
  30. */
  31. require_once('cmdbsource.class.inc.php');
  32. class SQLQuery
  33. {
  34. private $m_SourceOQL = '';
  35. private $m_sTable = '';
  36. private $m_sTableAlias = '';
  37. private $m_aFields = array();
  38. private $m_aGroupBy = array();
  39. private $m_oConditionExpr = null;
  40. private $m_bToDelete = true; // The current table must be listed for deletion ?
  41. private $m_aValues = array(); // Values to set in case of an update query
  42. private $m_oSelectedIdField = null;
  43. private $m_aJoinSelects = array();
  44. public function __construct($sTable, $sTableAlias, $aFields, $bToDelete = true, $aValues = array(), $oSelectedIdField = null)
  45. {
  46. // This check is not needed but for developping purposes
  47. //if (!CMDBSource::IsTable($sTable))
  48. //{
  49. // throw new CoreException("Unknown table '$sTable'");
  50. //}
  51. // $aFields must be an array of "alias"=>"expr"
  52. // $oConditionExpr must be a condition tree
  53. // $aValues is an array of "alias"=>value
  54. $this->m_sTable = $sTable;
  55. $this->m_sTableAlias = $sTableAlias;
  56. $this->m_aFields = $aFields;
  57. $this->m_aGroupBy = null;
  58. $this->m_oConditionExpr = null;
  59. $this->m_bToDelete = $bToDelete;
  60. $this->m_aValues = $aValues;
  61. $this->m_oSelectedIdField = $oSelectedIdField;
  62. }
  63. public function GetTableAlias()
  64. {
  65. return $this->m_sTableAlias;
  66. }
  67. public function SetSourceOQL($sOQL)
  68. {
  69. $this->m_SourceOQL = $sOQL;
  70. }
  71. public function GetSourceOQL()
  72. {
  73. return $this->m_SourceOQL;
  74. }
  75. public function DisplayHtml()
  76. {
  77. if (count($this->m_aFields) == 0) $sFields = "";
  78. else
  79. {
  80. $aFieldDesc = array();
  81. foreach ($this->m_aFields as $sAlias => $oExpression)
  82. {
  83. $aFieldDesc[] = $oExpression->Render()." as <em>$sAlias</em>";
  84. }
  85. $sFields = " =&gt; ".implode(', ', $aFieldDesc);
  86. }
  87. echo "<b>$this->m_sTable</b>$sFields<br/>\n";
  88. // #@# todo - display html of an expression tree
  89. //$this->m_oConditionExpr->DisplayHtml()
  90. if (count($this->m_aJoinSelects) > 0)
  91. {
  92. echo "Joined to...<br/>\n";
  93. echo "<ul class=\"treeview\">\n";
  94. foreach ($this->m_aJoinSelects as $aJoinInfo)
  95. {
  96. $sJoinType = $aJoinInfo["jointype"];
  97. $oSQLQuery = $aJoinInfo["select"];
  98. if (isset($aJoinInfo["on_expression"]))
  99. {
  100. $sOnCondition = $aJoinInfo["on_expression"]->Render();
  101. echo "<li>Join '$sJoinType', ON ($sOnCondition)".$oSQLQuery->DisplayHtml()."</li>\n";
  102. }
  103. else
  104. {
  105. $sLeftField = $aJoinInfo["leftfield"];
  106. $sRightField = $aJoinInfo["rightfield"];
  107. $sRightTableAlias = $aJoinInfo["righttablealias"];
  108. echo "<li>Join '$sJoinType', $sLeftField, $sRightTableAlias.$sRightField".$oSQLQuery->DisplayHtml()."</li>\n";
  109. }
  110. }
  111. echo "</ul>";
  112. }
  113. $aFrom = array();
  114. $aFields = array();
  115. $aGroupBy = array();
  116. $oCondition = null;
  117. $aDelTables = array();
  118. $aSetValues = array();
  119. $aSelectedIdFields = array();
  120. $this->privRender($aFrom, $aFields, $aGroupBy, $oCondition, $aDelTables, $aSetValues, $aSelectedIdFields);
  121. echo "From ...<br/>\n";
  122. echo "<pre style=\"font-size: smaller;\">\n";
  123. print_r($aFrom);
  124. echo "</pre>";
  125. }
  126. public function SetSelect($aExpressions)
  127. {
  128. $this->m_aFields = $aExpressions;
  129. }
  130. public function SetGroupBy($aExpressions)
  131. {
  132. $this->m_aGroupBy = $aExpressions;
  133. }
  134. public function SetCondition($oConditionExpr)
  135. {
  136. $this->m_oConditionExpr = $oConditionExpr;
  137. }
  138. public function AddCondition($oConditionExpr)
  139. {
  140. if (is_null($this->m_oConditionExpr))
  141. {
  142. $this->m_oConditionExpr = $oConditionExpr;
  143. }
  144. else
  145. {
  146. $this->m_oConditionExpr->LogAnd($oConditionExpr);
  147. }
  148. }
  149. private function AddJoin($sJoinType, $oSQLQuery, $sLeftField, $sRightField, $sRightTableAlias = '')
  150. {
  151. assert((get_class($oSQLQuery) == __CLASS__) || is_subclass_of($oSQLQuery, __CLASS__));
  152. // No need to check this here but for development purposes
  153. //if (!CMDBSource::IsField($this->m_sTable, $sLeftField))
  154. //{
  155. // throw new CoreException("Unknown field '$sLeftField' in table '".$this->m_sTable);
  156. //}
  157. if (empty($sRightTableAlias))
  158. {
  159. $sRightTableAlias = $oSQLQuery->m_sTableAlias;
  160. }
  161. // #@# Could not be verified here because the namespace is unknown - do we need to check it there?
  162. //
  163. // if (!CMDBSource::IsField($sRightTable, $sRightField))
  164. // {
  165. // throw new CoreException("Unknown field '$sRightField' in table '".$sRightTable."'");
  166. // }
  167. $this->m_aJoinSelects[] = array(
  168. "jointype" => $sJoinType,
  169. "select" => $oSQLQuery,
  170. "leftfield" => $sLeftField,
  171. "rightfield" => $sRightField,
  172. "righttablealias" => $sRightTableAlias
  173. );
  174. }
  175. public function AddInnerJoin($oSQLQuery, $sLeftField, $sRightField, $sRightTable = '')
  176. {
  177. $this->AddJoin("inner", $oSQLQuery, $sLeftField, $sRightField, $sRightTable);
  178. }
  179. public function AddInnerJoinTree($oSQLQuery, $sLeftFieldLeft, $sLeftFieldRight, $sRightFieldLeft, $sRightFieldRight, $sRightTableAlias = '', $iOperatorCode = TREE_OPERATOR_BELOW)
  180. {
  181. assert((get_class($oSQLQuery) == __CLASS__) || is_subclass_of($oSQLQuery, __CLASS__));
  182. if (empty($sRightTableAlias))
  183. {
  184. $sRightTableAlias = $oSQLQuery->m_sTableAlias;
  185. }
  186. $this->m_aJoinSelects[] = array(
  187. "jointype" => 'inner_tree',
  188. "select" => $oSQLQuery,
  189. "leftfield" => $sLeftFieldLeft,
  190. "rightfield" => $sLeftFieldRight,
  191. "rightfield_left" => $sRightFieldLeft,
  192. "rightfield_right" => $sRightFieldRight,
  193. "righttablealias" => $sRightTableAlias,
  194. "tree_operator" => $iOperatorCode);
  195. }
  196. public function AddLeftJoin($oSQLQuery, $sLeftField, $sRightField)
  197. {
  198. return $this->AddJoin("left", $oSQLQuery, $sLeftField, $sRightField);
  199. }
  200. public function AddInnerJoinEx(SQLQuery $oSQLQuery, Expression $oOnExpression)
  201. {
  202. $this->m_aJoinSelects[] = array(
  203. "jointype" => 'inner',
  204. "select" => $oSQLQuery,
  205. "on_expression" => $oOnExpression
  206. );
  207. }
  208. public function AddLeftJoinEx(SQLQuery $oSQLQuery, Expression $oOnExpression)
  209. {
  210. $this->m_aJoinSelects[] = array(
  211. "jointype" => 'left',
  212. "select" => $oSQLQuery,
  213. "on_expression" => $oOnExpression
  214. );
  215. }
  216. // Interface, build the SQL query
  217. public function RenderDelete($aArgs = array())
  218. {
  219. // The goal will be to complete the list as we build the Joins
  220. $aFrom = array();
  221. $aFields = array();
  222. $aGroupBy = arry();
  223. $oCondition = null;
  224. $aDelTables = array();
  225. $aSetValues = array();
  226. $aSelectedIdFields = array();
  227. $this->privRender($aFrom, $aFields, $aGroupBy, $oCondition, $aDelTables, $aSetValues, $aSelectedIdFields);
  228. // Target: DELETE myAlias1, myAlias2 FROM t1 as myAlias1, t2 as myAlias2, t3 as topreserve WHERE ...
  229. $sDelete = self::ClauseDelete($aDelTables);
  230. $sFrom = self::ClauseFrom($aFrom);
  231. // #@# safety net to redo ?
  232. /*
  233. if ($this->m_oConditionExpr->IsAny())
  234. -- if (count($aConditions) == 0) --
  235. {
  236. throw new CoreException("Building a request wich will delete every object of a given table -looks suspicious- please use truncate instead...");
  237. }
  238. */
  239. if (is_null($oCondition))
  240. {
  241. // Delete all !!!
  242. }
  243. else
  244. {
  245. $sWhere = self::ClauseWhere($oCondition, $aArgs);
  246. return "DELETE $sDelete FROM $sFrom WHERE $sWhere";
  247. }
  248. }
  249. // Interface, build the SQL query
  250. public function RenderUpdate($aArgs = array())
  251. {
  252. // The goal will be to complete the list as we build the Joins
  253. $aFrom = array();
  254. $aFields = array();
  255. $aGroupBy = array();
  256. $oCondition = null;
  257. $aDelTables = array();
  258. $aSetValues = array();
  259. $aSelectedIdFields = array();
  260. $this->privRender($aFrom, $aFields, $aGroupBy, $oCondition, $aDelTables, $aSetValues, $aSelectedIdFields);
  261. $sFrom = self::ClauseFrom($aFrom);
  262. $sValues = self::ClauseValues($aSetValues);
  263. $sWhere = self::ClauseWhere($oCondition, $aArgs);
  264. return "UPDATE $sFrom SET $sValues WHERE $sWhere";
  265. }
  266. // Interface, build the SQL query
  267. public function RenderSelect($aOrderBy = array(), $aArgs = array(), $iLimitCount = 0, $iLimitStart = 0, $bGetCount = false)
  268. {
  269. // The goal will be to complete the lists as we build the Joins
  270. $aFrom = array();
  271. $aFields = array();
  272. $aGroupBy = array();
  273. $oCondition = null;
  274. $aDelTables = array();
  275. $aSetValues = array();
  276. $aSelectedIdFields = array();
  277. $this->privRender($aFrom, $aFields, $aGroupBy, $oCondition, $aDelTables, $aSetValues, $aSelectedIdFields);
  278. $sFrom = self::ClauseFrom($aFrom);
  279. $sWhere = self::ClauseWhere($oCondition, $aArgs);
  280. if ($bGetCount)
  281. {
  282. if (count($aSelectedIdFields) > 0)
  283. {
  284. $sIDFields = implode(', ', $aSelectedIdFields);
  285. $sSQL = "SELECT COUNT(DISTINCT $sIDFields) AS COUNT FROM $sFrom WHERE $sWhere";
  286. }
  287. else
  288. {
  289. $sSQL = "SELECT COUNT(*) AS COUNT FROM $sFrom WHERE $sWhere";
  290. }
  291. }
  292. else
  293. {
  294. $sSelect = self::ClauseSelect($aFields);
  295. $sOrderBy = self::ClauseOrderBy($aOrderBy);
  296. if (!empty($sOrderBy))
  297. {
  298. $sOrderBy = "ORDER BY $sOrderBy";
  299. }
  300. if ($iLimitCount > 0)
  301. {
  302. $sLimit = 'LIMIT '.$iLimitStart.', '.$iLimitCount;
  303. }
  304. else
  305. {
  306. $sLimit = '';
  307. }
  308. $sSQL = "SELECT DISTINCT $sSelect FROM $sFrom WHERE $sWhere $sOrderBy $sLimit";
  309. }
  310. return $sSQL;
  311. }
  312. // Interface, build the SQL query
  313. public function RenderGroupBy($aArgs = array())
  314. {
  315. // The goal will be to complete the lists as we build the Joins
  316. $aFrom = array();
  317. $aFields = array();
  318. $aGroupBy = array();
  319. $oCondition = null;
  320. $aDelTables = array();
  321. $aSetValues = array();
  322. $aSelectedIdFields = array();
  323. $this->privRender($aFrom, $aFields, $aGroupBy, $oCondition, $aDelTables, $aSetValues, $aSelectedIdFields);
  324. $sSelect = self::ClauseSelect($aFields);
  325. $sFrom = self::ClauseFrom($aFrom);
  326. $sWhere = self::ClauseWhere($oCondition, $aArgs);
  327. $sGroupBy = self::ClauseGroupBy($aGroupBy);
  328. $sSQL = "SELECT $sSelect, COUNT(*) AS _itop_count_ FROM $sFrom WHERE $sWhere GROUP BY $sGroupBy";
  329. return $sSQL;
  330. }
  331. private static function ClauseSelect($aFields)
  332. {
  333. $aSelect = array();
  334. foreach ($aFields as $sFieldAlias => $sSQLExpr)
  335. {
  336. $aSelect[] = "$sSQLExpr AS $sFieldAlias";
  337. }
  338. $sSelect = implode(', ', $aSelect);
  339. return $sSelect;
  340. }
  341. private static function ClauseGroupBy($aGroupBy)
  342. {
  343. $sRes = implode(', ', $aGroupBy);
  344. return $sRes;
  345. }
  346. private static function ClauseDelete($aDelTableAliases)
  347. {
  348. $aDelTables = array();
  349. foreach ($aDelTableAliases as $sTableAlias)
  350. {
  351. $aDelTables[] = "$sTableAlias";
  352. }
  353. $sDelTables = implode(', ', $aDelTables);
  354. return $sDelTables;
  355. }
  356. private static function ClauseFrom($aFrom)
  357. {
  358. $sFrom = "";
  359. foreach ($aFrom as $sTableAlias => $aJoinInfo)
  360. {
  361. switch ($aJoinInfo["jointype"])
  362. {
  363. case "first":
  364. $sFrom .= "`".$aJoinInfo["tablename"]."` AS `$sTableAlias`";
  365. $sFrom .= " ".self::ClauseFrom($aJoinInfo["subfrom"]);
  366. break;
  367. case "inner":
  368. case "inner_tree":
  369. $sFrom .= " INNER JOIN (`".$aJoinInfo["tablename"]."` AS `$sTableAlias`";
  370. $sFrom .= " ".self::ClauseFrom($aJoinInfo["subfrom"]);
  371. $sFrom .= ") ON ".$aJoinInfo["joincondition"];
  372. break;
  373. case "left":
  374. $sFrom .= " LEFT JOIN (`".$aJoinInfo["tablename"]."` AS `$sTableAlias`";
  375. $sFrom .= " ".self::ClauseFrom($aJoinInfo["subfrom"]);
  376. $sFrom .= ") ON ".$aJoinInfo["joincondition"];
  377. break;
  378. default:
  379. throw new CoreException("Unknown jointype: '".$aJoinInfo["jointype"]."'");
  380. }
  381. }
  382. return $sFrom;
  383. }
  384. private static function ClauseValues($aValues)
  385. {
  386. $aSetValues = array();
  387. foreach ($aValues as $sFieldSpec => $value)
  388. {
  389. $aSetValues[] = "$sFieldSpec = ".CMDBSource::Quote($value);
  390. }
  391. $sSetValues = implode(', ', $aSetValues);
  392. return $sSetValues;
  393. }
  394. private static function ClauseWhere($oConditionExpr, $aArgs = array())
  395. {
  396. if (is_null($oConditionExpr))
  397. {
  398. return '1';
  399. }
  400. else
  401. {
  402. return $oConditionExpr->Render($aArgs);
  403. }
  404. }
  405. private static function ClauseOrderBy($aOrderBy)
  406. {
  407. $aOrderBySpec = array();
  408. foreach($aOrderBy as $sFieldAlias => $bAscending)
  409. {
  410. // Note: sFieldAlias must have backticks around column aliases
  411. $aOrderBySpec[] = $sFieldAlias.($bAscending ? " ASC" : " DESC");
  412. }
  413. $sOrderBy = implode(", ", $aOrderBySpec);
  414. return $sOrderBy;
  415. }
  416. // Purpose: prepare the query data, once for all
  417. private function privRender(&$aFrom, &$aFields, &$aGroupBy, &$oCondition, &$aDelTables, &$aSetValues, &$aSelectedIdFields)
  418. {
  419. $sTableAlias = $this->privRenderSingleTable($aFrom, $aFields, $aGroupBy, $aDelTables, $aSetValues, $aSelectedIdFields, '', array('jointype' => 'first'));
  420. $oCondition = $this->m_oConditionExpr;
  421. return $sTableAlias;
  422. }
  423. private function privRenderSingleTable(&$aFrom, &$aFields, &$aGroupBy, &$aDelTables, &$aSetValues, &$aSelectedIdFields, $sCallerAlias = '', $aJoinData)
  424. {
  425. $aActualTableFields = CMDBSource::GetTableFieldsList($this->m_sTable);
  426. $aTranslationTable[$this->m_sTable]['*'] = $this->m_sTableAlias;
  427. // Handle the various kinds of join (or first table in the list)
  428. //
  429. if (empty($aJoinData['righttablealias']))
  430. {
  431. $sRightTableAlias = $this->m_sTableAlias;
  432. }
  433. else
  434. {
  435. $sRightTableAlias = $aJoinData['righttablealias'];
  436. }
  437. switch ($aJoinData['jointype'])
  438. {
  439. case "first":
  440. $aFrom[$this->m_sTableAlias] = array("jointype"=>"first", "tablename"=>$this->m_sTable, "joincondition"=>"");
  441. break;
  442. case "inner":
  443. case "left":
  444. if (isset($aJoinData["on_expression"]))
  445. {
  446. $sJoinCond = $aJoinData["on_expression"]->Render();
  447. }
  448. else
  449. {
  450. $sJoinCond = "`$sCallerAlias`.`{$aJoinData['leftfield']}` = `$sRightTableAlias`.`{$aJoinData['rightfield']}`";
  451. }
  452. $aFrom[$this->m_sTableAlias] = array("jointype"=>$aJoinData['jointype'], "tablename"=>$this->m_sTable, "joincondition"=>"$sJoinCond");
  453. break;
  454. case "inner_tree":
  455. $sNodeLeft = "`$sCallerAlias`.`{$aJoinData['leftfield']}`";
  456. $sNodeRight = "`$sCallerAlias`.`{$aJoinData['rightfield']}`";
  457. $sRootLeft = "`$sRightTableAlias`.`{$aJoinData['rightfield_left']}`";
  458. $sRootRight = "`$sRightTableAlias`.`{$aJoinData['rightfield_right']}`";
  459. switch($aJoinData['tree_operator'])
  460. {
  461. case TREE_OPERATOR_BELOW:
  462. $sJoinCond = "$sNodeLeft >= $sRootLeft AND $sNodeLeft <= $sRootRight";
  463. break;
  464. case TREE_OPERATOR_BELOW_STRICT:
  465. $sJoinCond = "$sNodeLeft > $sRootLeft AND $sNodeLeft < $sRootRight";
  466. break;
  467. case TREE_OPERATOR_NOT_BELOW: // Complementary of 'BELOW'
  468. $sJoinCond = "$sNodeLeft < $sRootLeft OR $sNodeLeft > $sRootRight";
  469. break;
  470. case TREE_OPERATOR_NOT_BELOW_STRICT: // Complementary of BELOW_STRICT
  471. $sJoinCond = "$sNodeLeft <= $sRootLeft OR $sNodeLeft >= $sRootRight";
  472. break;
  473. case TREE_OPERATOR_ABOVE:
  474. $sJoinCond = "$sNodeLeft <= $sRootLeft AND $sNodeRight >= $sRootRight";
  475. break;
  476. case TREE_OPERATOR_ABOVE_STRICT:
  477. $sJoinCond = "$sNodeLeft < $sRootLeft AND $sNodeRight > $sRootRight";
  478. break;
  479. case TREE_OPERATOR_NOT_ABOVE: // Complementary of 'ABOVE'
  480. $sJoinCond = "$sNodeLeft > $sRootLeft OR $sNodeRight < $sRootRight";
  481. break;
  482. case TREE_OPERATOR_NOT_ABOVE_STRICT: // Complementary of ABOVE_STRICT
  483. $sJoinCond = "$sNodeLeft >= $sRootLeft OR $sNodeRight <= $sRootRight";
  484. break;
  485. }
  486. $aFrom[$this->m_sTableAlias] = array("jointype"=>$aJoinData['jointype'], "tablename"=>$this->m_sTable, "joincondition"=>"$sJoinCond");
  487. break;
  488. }
  489. // Given the alias, modify the fields and conditions
  490. // before adding them into the current lists
  491. //
  492. foreach($this->m_aFields as $sAlias => $oExpression)
  493. {
  494. $aFields["`$sAlias`"] = $oExpression->Render();
  495. }
  496. if ($this->m_aGroupBy)
  497. {
  498. foreach($this->m_aGroupBy as $sAlias => $oExpression)
  499. {
  500. $aGroupBy["`$sAlias`"] = $oExpression->Render();
  501. }
  502. }
  503. if ($this->m_bToDelete)
  504. {
  505. $aDelTables[] = "`{$this->m_sTableAlias}`";
  506. }
  507. //echo "<p>in privRenderSingleTable this->m_aValues<pre>".print_r($this->m_aValues, true)."</pre></p>\n";
  508. foreach($this->m_aValues as $sFieldName=>$value)
  509. {
  510. $aSetValues["`{$this->m_sTableAlias}`.`$sFieldName`"] = $value; // quoted further!
  511. }
  512. if (!is_null($this->m_oSelectedIdField))
  513. {
  514. $aSelectedIdFields[] = $this->m_oSelectedIdField->Render();
  515. }
  516. // loop on joins, to complete the list of tables/fields/conditions
  517. //
  518. $aTempFrom = array(); // temporary subset of 'from' specs, to be grouped in the final query
  519. foreach ($this->m_aJoinSelects as $aJoinData)
  520. {
  521. $oRightSelect = $aJoinData["select"];
  522. $sJoinTableAlias = $oRightSelect->privRenderSingleTable($aTempFrom, $aFields, $aGroupBy, $aDelTables, $aSetValues, $aSelectedIdFields, $this->m_sTableAlias, $aJoinData);
  523. }
  524. $aFrom[$this->m_sTableAlias]['subfrom'] = $aTempFrom;
  525. return $this->m_sTableAlias;
  526. }
  527. }
  528. ?>