Source for file PostgreSQLInsertQueryResult.class.php

Documentation is available at PostgreSQLInsertQueryResult.class.php

  1. <?php
  2. /**
  3. * @package harmoni.dbc.postgre
  4. *
  5. * @copyright Copyright &copy; 2005, Middlebury College
  6. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  7. *
  8. * @version $Id: PostgreSQLInsertQueryResult.class.php,v 1.1 2007/09/14 13:57:08 adamfranco Exp $
  9. */
  10. require_once(HARMONI."DBHandler/InsertQueryResult.interface.php");
  11.  
  12. /**
  13. * The InsertQueryResult interface provides the functionality common to all INSERT query results.
  14. * For example, you can get the primary key for the last insertion, get number of inserted rows, etc.
  15. *
  16. * @package harmoni.dbc.postgre
  17. *
  18. * @copyright Copyright &copy; 2005, Middlebury College
  19. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  20. *
  21. * @version $Id: PostgreSQLInsertQueryResult.class.php,v 1.1 2007/09/14 13:57:08 adamfranco Exp $
  22. */
  23. class PostgreSQLInsertQueryResult
  24. implements InsertQueryResultInterface
  25. {
  26.  
  27.  
  28. /**
  29. * The resource id for this query.
  30. * @var integer __resourceId
  31. * @access private
  32. */
  33. var $_resourceId;
  34.  
  35. /**
  36. * Gets the last auto increment value that was generated by the INSERT query.
  37. * Gets the last auto increment value that was generated by the INSERT query.
  38. * @access private
  39. * @var integer $_lastAutoIncrementValue The last auto increment value that was generated by the INSERT query.
  40. */
  41. var $_lastAutoIncrementValue;
  42.  
  43. /**
  44. * Stores the number of rows processed by the query.
  45. * Stores the number of rows processed by the query.
  46. * @var integer $_numberOfRows The number of rows processed by the query.
  47. * @access private
  48. */
  49. var $_numberOfRows;
  50.  
  51.  
  52. /**
  53. * Creates a new PostgreSQLINSERTQueryResult object.
  54. * @access public
  55. * @param integer $resourceId The resource id for this query.
  56. * @param integer $lastId The last id that was inserted
  57. * @return object A new PostgreSQLINSERTQueryResult object.
  58. */
  59. function PostgreSQLInsertQueryResult($resourceId, $lastId) {
  60. // ** parameter validation
  61. $resourceRule = ResourceValidatorRule::getRule();
  62. $integerRule = OptionalRule::getRule(IntegerValidatorRule::getRule());
  63. ArgumentValidator::validate($resourceId, $resourceRule, true);
  64. ArgumentValidator::validate($lastId, $integerRule, true);
  65. // ** end of parameter validation
  66.  
  67. $this->_resourceId = $resourceId;
  68. $this->_numberOfRows = pg_affected_rows($this->_resourceId);
  69. $this->_lastAutoIncrementValue = $lastId;
  70. }
  71.  
  72. /**
  73. * Gets the last auto increment value that was generated by the INSERT query.
  74. * This is not a 100% reliable method. If somebody inserted something after
  75. * the insert query but before the InsertQueryResult object was created, then
  76. * this method could return an invalid value.
  77. * @access public
  78. * @return integer The last auto increment value that was generated by the INSERT query.
  79. */
  80. function getLastAutoIncrementValue() {
  81. if (is_null($this->_lastAutoIncrementValue)) {
  82. $str = "Cannot get last autoincrement value, because the autoincrement ";
  83. $str .= "column has not been set with setAutoIncrementColumn().";
  84. throw new DatabaseException($str);
  85. }
  86. return $this->_lastAutoIncrementValue;
  87. }
  88.  
  89. /**
  90. * Returns the number of rows that the query processed.
  91. * Returns the number of rows that the query processed. For a SELECT query,
  92. * this would be the total number of rows selected. For a DELETE, UPDATE, or
  93. * INSERT query, this would be the number of rows that were affected.
  94. * @return integer Number of rows that were processed by the query.
  95. * @access public
  96. */
  97. function getNumberOfRows() {
  98. return $this->_numberOfRows;
  99. }
  100.  
  101.  
  102. }
  103.  
  104. ?>

Documentation generated on Wed, 19 Sep 2007 10:25:33 -0400 by phpDocumentor 1.3.0RC3