PageRenderTime 26ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/sgl/assets/_core/php/examples/qcubed_query/qq.php

http://logisticsouth.googlecode.com/
PHP | 95 lines | 86 code | 9 blank | 0 comment | 4 complexity | b906e899b986e32d53dc1e079d184e6f MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0
  1. <?php require_once('../qcubed.inc.php'); ?>
  2. <?php require('../includes/header.inc.php'); ?>
  3. <div class="instructions">
  4. <h1 class="instruction_title">Introduction to QCubed Query</h1>
  5. The querying logic behind all the Load methods in your ORM classes is powered by <b>QCubed Query</b>,
  6. or <b>QQ</b> for short. Put simply, <b>QQ</b> is a completely object oriented API to perform any SELECT-based
  7. query on your database to return any result or hierarchy of your ORM objects.<br/><br/>
  8. While the ORM classes utilize basic, straightforward SELECT statements in its Load methods,
  9. <b>QQ</b> is capable of infinitely more complex queries. In fact, any SELECT a developer
  10. would need to do against a database should be possible with <b>QQ</b>*.<br/><br/>
  11. <div style="font-size: 9px; line-height: 11px;">* Beta 3 Prerelease note: this is the
  12. eventual goal with QCubed Query. Currently, subselects and partial selects are still not yet available
  13. in QQ. But please know that they are slated to be offically supported in Qcodo.)</div><br/>
  14. At its core, any <b>QQ</b> query will return a collection of objects of the same type (e.g. a collection of
  15. Person objects). But the power of <b>QQ</b> is that we can branch beyond this core collection by bringing in
  16. any related objects, performing any SQL-based clause (including WHERE, ORDER BY, JOIN, aggregations, etc.) on both
  17. the core set of Person rows <i>and</i> any of these related objects rows.<br/><br/>
  18. Every code generated class in your ORM will have the three following static <b>QCubed Query</b> methods:
  19. <ul>
  20. <li><b>QuerySingle</b>: to perform a QCubed Query to return just a single object (typically for queries where you expect only one row)</li>
  21. <li><b>QueryArray</b>: to perform a QCubed Query to return just an array of objects</li>
  22. <li><b>QueryCount</b>: to perform a QCubed Query to return an integer of the count of rows (e.g. "COUNT (*)")</li>
  23. </ul>
  24. All three QCubed Query methods expect two parameters, a <b>QQ Condition</b> and an optional set of <b>QQ Clauses</b>.
  25. <b>QQ Conditions</b> are typically conditions that you would expect to find in a SQL WHERE clause, including <b>Equal</b>,
  26. <b>GreaterThan</b>, <b>IsNotNull</b>, etc. <b>QQ Clauses</b> are additional clauses that you could add to alter
  27. your SQL statement, including methods to perform SQL equivalents of JOIN, DISTINCT, GROUP BY, ORDER BY and LIMIT.
  28. <br/><br/>
  29. And finally, both <b>QQ Condition</b> and <b>QQ Clause</b> objects will expect <b>QQ Node</b> parameters. <b>QQ Nodes</b> can
  30. either be tables, individual columns within the tables, or even association tables. <b>QQ Node</b> classes for your
  31. entire ORM is code generated for you.
  32. <br/><br/>
  33. The next few examples will examine all three major constructs (<b>QQ Node</b>, <b>QQ Condition</b> and <b>QQ Clause</b>) in greater
  34. detail.<br/><br/>
  35. And as a final note, notice that <b>QCubed Query</b> doesn't have any construct to describe what would normally be your SELECT clause.
  36. This is because we take advantage of the code generation process to allow <b>QCubed Query</b> to automagically "know" which
  37. fields that should be SELECT-ed based on the query, conditions and clauses you are performing. This will allow a lot
  38. greater flexbility in your data model. Because the framework is now taking care of column names, etc., instead of the
  39. developer needing to manually hard code it, you can make changes to columns in your tables without needing to rewrite
  40. your <b>QCubed Query</b> calls.
  41. </div>
  42. <h3>QuerySingle Example</h3>
  43. <?php
  44. $objPerson = Person::QuerySingle(
  45. QQ::Equal(QQN::Person()->Id, 1)
  46. );
  47. // Notice that QuerySingle returned just a single Person object
  48. _p($objPerson->FirstName . ' ' . $objPerson->LastName);
  49. _p('<br/>', false);
  50. ?>
  51. <h3>QueryArray Example</h3>
  52. <?php
  53. $objPersonArray = Person::QueryArray(
  54. QQ::In(QQN::Person()->Id, array(5, 6, 8))
  55. );
  56. // Notice that QueryArray returns an array of Person objects... this will
  57. // be true even if the result set only yields 1 row.=
  58. foreach ($objPersonArray as $objPerson) {
  59. _p($objPerson->FirstName . ' ' . $objPerson->LastName);
  60. _p('<br/>', false);
  61. }
  62. ?>
  63. <h3>QueryCount Example</h3>
  64. <?php
  65. $intCount = Person::QueryCount(
  66. QQ::In(QQN::Person()->Id, array(5, 6, 8))
  67. );
  68. // Notice that QueryCount returns an integer
  69. _p($intCount . ' rows.');
  70. ?>
  71. <?php require('../includes/footer.inc.php'); ?>