sqlquery.class.inc.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591
  1. <?php
  2. // Copyright (C) 2010-2012 Combodo SARL
  3. //
  4. // This file is part of iTop.
  5. //
  6. // iTop is free software; you can redistribute it and/or modify
  7. // it under the terms of the GNU Affero General Public License as published by
  8. // the Free Software Foundation, either version 3 of the License, or
  9. // (at your option) any later version.
  10. //
  11. // iTop is distributed in the hope that it will be useful,
  12. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. // GNU Affero General Public License for more details.
  15. //
  16. // You should have received a copy of the GNU Affero General Public License
  17. // along with iTop. If not, see <http://www.gnu.org/licenses/>
  18. /**
  19. * SQLQuery
  20. * build an mySQL compatible SQL query
  21. *
  22. * @copyright Copyright (C) 2010-2012 Combodo SARL
  23. * @license http://opensource.org/licenses/AGPL-3.0
  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 = array();
  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. $aCountFields = array();
  285. foreach ($aSelectedIdFields as $sFieldExpr)
  286. {
  287. $aCountFields[] = "COALESCE($sFieldExpr, 0)"; // Null values are excluded from the count
  288. }
  289. $sCountFields = implode(', ', $aCountFields);
  290. $sSQL = "SELECT COUNT(DISTINCT $sCountFields) AS COUNT FROM $sFrom WHERE $sWhere";
  291. }
  292. else
  293. {
  294. $sSQL = "SELECT COUNT(*) AS COUNT FROM $sFrom WHERE $sWhere";
  295. }
  296. }
  297. else
  298. {
  299. $sSelect = self::ClauseSelect($aFields);
  300. $sOrderBy = self::ClauseOrderBy($aOrderBy);
  301. if (!empty($sOrderBy))
  302. {
  303. $sOrderBy = "ORDER BY $sOrderBy";
  304. }
  305. if ($iLimitCount > 0)
  306. {
  307. $sLimit = 'LIMIT '.$iLimitStart.', '.$iLimitCount;
  308. }
  309. else
  310. {
  311. $sLimit = '';
  312. }
  313. $sSQL = "SELECT DISTINCT $sSelect FROM $sFrom WHERE $sWhere $sOrderBy $sLimit";
  314. }
  315. return $sSQL;
  316. }
  317. // Interface, build the SQL query
  318. public function RenderGroupBy($aArgs = array())
  319. {
  320. // The goal will be to complete the lists as we build the Joins
  321. $aFrom = array();
  322. $aFields = array();
  323. $aGroupBy = array();
  324. $oCondition = null;
  325. $aDelTables = array();
  326. $aSetValues = array();
  327. $aSelectedIdFields = array();
  328. $this->privRender($aFrom, $aFields, $aGroupBy, $oCondition, $aDelTables, $aSetValues, $aSelectedIdFields);
  329. $sSelect = self::ClauseSelect($aFields);
  330. $sFrom = self::ClauseFrom($aFrom);
  331. $sWhere = self::ClauseWhere($oCondition, $aArgs);
  332. $sGroupBy = self::ClauseGroupBy($aGroupBy);
  333. $sSQL = "SELECT $sSelect, COUNT(*) AS _itop_count_ FROM $sFrom WHERE $sWhere GROUP BY $sGroupBy";
  334. return $sSQL;
  335. }
  336. private static function ClauseSelect($aFields)
  337. {
  338. $aSelect = array();
  339. foreach ($aFields as $sFieldAlias => $sSQLExpr)
  340. {
  341. $aSelect[] = "$sSQLExpr AS $sFieldAlias";
  342. }
  343. $sSelect = implode(', ', $aSelect);
  344. return $sSelect;
  345. }
  346. private static function ClauseGroupBy($aGroupBy)
  347. {
  348. $sRes = implode(', ', $aGroupBy);
  349. return $sRes;
  350. }
  351. private static function ClauseDelete($aDelTableAliases)
  352. {
  353. $aDelTables = array();
  354. foreach ($aDelTableAliases as $sTableAlias)
  355. {
  356. $aDelTables[] = "$sTableAlias";
  357. }
  358. $sDelTables = implode(', ', $aDelTables);
  359. return $sDelTables;
  360. }
  361. private static function ClauseFrom($aFrom)
  362. {
  363. $sFrom = "";
  364. foreach ($aFrom as $sTableAlias => $aJoinInfo)
  365. {
  366. switch ($aJoinInfo["jointype"])
  367. {
  368. case "first":
  369. $sFrom .= "`".$aJoinInfo["tablename"]."` AS `$sTableAlias`";
  370. $sFrom .= " ".self::ClauseFrom($aJoinInfo["subfrom"]);
  371. break;
  372. case "inner":
  373. case "inner_tree":
  374. $sFrom .= " INNER JOIN (`".$aJoinInfo["tablename"]."` AS `$sTableAlias`";
  375. $sFrom .= " ".self::ClauseFrom($aJoinInfo["subfrom"]);
  376. $sFrom .= ") ON ".$aJoinInfo["joincondition"];
  377. break;
  378. case "left":
  379. $sFrom .= " LEFT JOIN (`".$aJoinInfo["tablename"]."` AS `$sTableAlias`";
  380. $sFrom .= " ".self::ClauseFrom($aJoinInfo["subfrom"]);
  381. $sFrom .= ") ON ".$aJoinInfo["joincondition"];
  382. break;
  383. default:
  384. throw new CoreException("Unknown jointype: '".$aJoinInfo["jointype"]."'");
  385. }
  386. }
  387. return $sFrom;
  388. }
  389. private static function ClauseValues($aValues)
  390. {
  391. $aSetValues = array();
  392. foreach ($aValues as $sFieldSpec => $value)
  393. {
  394. $aSetValues[] = "$sFieldSpec = ".CMDBSource::Quote($value);
  395. }
  396. $sSetValues = implode(', ', $aSetValues);
  397. return $sSetValues;
  398. }
  399. private static function ClauseWhere($oConditionExpr, $aArgs = array())
  400. {
  401. if (is_null($oConditionExpr))
  402. {
  403. return '1';
  404. }
  405. else
  406. {
  407. return $oConditionExpr->Render($aArgs);
  408. }
  409. }
  410. private static function ClauseOrderBy($aOrderBy)
  411. {
  412. $aOrderBySpec = array();
  413. foreach($aOrderBy as $sFieldAlias => $bAscending)
  414. {
  415. // Note: sFieldAlias must have backticks around column aliases
  416. $aOrderBySpec[] = $sFieldAlias.($bAscending ? " ASC" : " DESC");
  417. }
  418. $sOrderBy = implode(", ", $aOrderBySpec);
  419. return $sOrderBy;
  420. }
  421. // Purpose: prepare the query data, once for all
  422. private function privRender(&$aFrom, &$aFields, &$aGroupBy, &$oCondition, &$aDelTables, &$aSetValues, &$aSelectedIdFields)
  423. {
  424. $sTableAlias = $this->privRenderSingleTable($aFrom, $aFields, $aGroupBy, $aDelTables, $aSetValues, $aSelectedIdFields, '', array('jointype' => 'first'));
  425. $oCondition = $this->m_oConditionExpr;
  426. return $sTableAlias;
  427. }
  428. private function privRenderSingleTable(&$aFrom, &$aFields, &$aGroupBy, &$aDelTables, &$aSetValues, &$aSelectedIdFields, $sCallerAlias = '', $aJoinData)
  429. {
  430. $aActualTableFields = CMDBSource::GetTableFieldsList($this->m_sTable);
  431. $aTranslationTable[$this->m_sTable]['*'] = $this->m_sTableAlias;
  432. // Handle the various kinds of join (or first table in the list)
  433. //
  434. if (empty($aJoinData['righttablealias']))
  435. {
  436. $sRightTableAlias = $this->m_sTableAlias;
  437. }
  438. else
  439. {
  440. $sRightTableAlias = $aJoinData['righttablealias'];
  441. }
  442. switch ($aJoinData['jointype'])
  443. {
  444. case "first":
  445. $aFrom[$this->m_sTableAlias] = array("jointype"=>"first", "tablename"=>$this->m_sTable, "joincondition"=>"");
  446. break;
  447. case "inner":
  448. case "left":
  449. if (isset($aJoinData["on_expression"]))
  450. {
  451. $sJoinCond = $aJoinData["on_expression"]->Render();
  452. }
  453. else
  454. {
  455. $sJoinCond = "`$sCallerAlias`.`{$aJoinData['leftfield']}` = `$sRightTableAlias`.`{$aJoinData['rightfield']}`";
  456. }
  457. $aFrom[$this->m_sTableAlias] = array("jointype"=>$aJoinData['jointype'], "tablename"=>$this->m_sTable, "joincondition"=>"$sJoinCond");
  458. break;
  459. case "inner_tree":
  460. $sNodeLeft = "`$sCallerAlias`.`{$aJoinData['leftfield']}`";
  461. $sNodeRight = "`$sCallerAlias`.`{$aJoinData['rightfield']}`";
  462. $sRootLeft = "`$sRightTableAlias`.`{$aJoinData['rightfield_left']}`";
  463. $sRootRight = "`$sRightTableAlias`.`{$aJoinData['rightfield_right']}`";
  464. switch($aJoinData['tree_operator'])
  465. {
  466. case TREE_OPERATOR_BELOW:
  467. $sJoinCond = "$sNodeLeft >= $sRootLeft AND $sNodeLeft <= $sRootRight";
  468. break;
  469. case TREE_OPERATOR_BELOW_STRICT:
  470. $sJoinCond = "$sNodeLeft > $sRootLeft AND $sNodeLeft < $sRootRight";
  471. break;
  472. case TREE_OPERATOR_NOT_BELOW: // Complementary of 'BELOW'
  473. $sJoinCond = "$sNodeLeft < $sRootLeft OR $sNodeLeft > $sRootRight";
  474. break;
  475. case TREE_OPERATOR_NOT_BELOW_STRICT: // Complementary of BELOW_STRICT
  476. $sJoinCond = "$sNodeLeft <= $sRootLeft OR $sNodeLeft >= $sRootRight";
  477. break;
  478. case TREE_OPERATOR_ABOVE:
  479. $sJoinCond = "$sNodeLeft <= $sRootLeft AND $sNodeRight >= $sRootRight";
  480. break;
  481. case TREE_OPERATOR_ABOVE_STRICT:
  482. $sJoinCond = "$sNodeLeft < $sRootLeft AND $sNodeRight > $sRootRight";
  483. break;
  484. case TREE_OPERATOR_NOT_ABOVE: // Complementary of 'ABOVE'
  485. $sJoinCond = "$sNodeLeft > $sRootLeft OR $sNodeRight < $sRootRight";
  486. break;
  487. case TREE_OPERATOR_NOT_ABOVE_STRICT: // Complementary of ABOVE_STRICT
  488. $sJoinCond = "$sNodeLeft >= $sRootLeft OR $sNodeRight <= $sRootRight";
  489. break;
  490. }
  491. $aFrom[$this->m_sTableAlias] = array("jointype"=>$aJoinData['jointype'], "tablename"=>$this->m_sTable, "joincondition"=>"$sJoinCond");
  492. break;
  493. }
  494. // Given the alias, modify the fields and conditions
  495. // before adding them into the current lists
  496. //
  497. foreach($this->m_aFields as $sAlias => $oExpression)
  498. {
  499. $aFields["`$sAlias`"] = $oExpression->Render();
  500. }
  501. if ($this->m_aGroupBy)
  502. {
  503. foreach($this->m_aGroupBy as $sAlias => $oExpression)
  504. {
  505. $aGroupBy["`$sAlias`"] = $oExpression->Render();
  506. }
  507. }
  508. if ($this->m_bToDelete)
  509. {
  510. $aDelTables[] = "`{$this->m_sTableAlias}`";
  511. }
  512. //echo "<p>in privRenderSingleTable this->m_aValues<pre>".print_r($this->m_aValues, true)."</pre></p>\n";
  513. foreach($this->m_aValues as $sFieldName=>$value)
  514. {
  515. $aSetValues["`{$this->m_sTableAlias}`.`$sFieldName`"] = $value; // quoted further!
  516. }
  517. if (!is_null($this->m_oSelectedIdField))
  518. {
  519. $aSelectedIdFields[] = $this->m_oSelectedIdField->Render();
  520. }
  521. // loop on joins, to complete the list of tables/fields/conditions
  522. //
  523. $aTempFrom = array(); // temporary subset of 'from' specs, to be grouped in the final query
  524. foreach ($this->m_aJoinSelects as $aJoinData)
  525. {
  526. $oRightSelect = $aJoinData["select"];
  527. $sJoinTableAlias = $oRightSelect->privRenderSingleTable($aTempFrom, $aFields, $aGroupBy, $aDelTables, $aSetValues, $aSelectedIdFields, $this->m_sTableAlias, $aJoinData);
  528. }
  529. $aFrom[$this->m_sTableAlias]['subfrom'] = $aTempFrom;
  530. return $this->m_sTableAlias;
  531. }
  532. }
  533. ?>