jenkins-bot has submitted this change and it was merged. Change subject: CRM-17748 Expose options['result_buffering'] to CRM_Core_DAO ......................................................................
CRM-17748 Expose options['result_buffering'] to CRM_Core_DAO Backport of patch in 4.7 Bug: T120892 Change-Id: I8a9129c665c7efd61e14a8b1ad1de191ffef1996 --- M CRM/Contact/BAO/Query.php M CRM/Contact/Selector.php M CRM/Core/DAO.php 3 files changed, 115 insertions(+), 7 deletions(-) Approvals: Awight: Looks good to me, approved jenkins-bot: Verified diff --git a/CRM/Contact/BAO/Query.php b/CRM/Contact/BAO/Query.php index c9d4de7..6b9d912 100644 --- a/CRM/Contact/BAO/Query.php +++ b/CRM/Contact/BAO/Query.php @@ -44,6 +44,7 @@ * @var int */ const + NO_RETURN_PROPERTIES = 'CRM_Contact_BAO_Query::NO_RETURN_PROPERTIES', MODE_CONTACTS = 1, MODE_CONTRIBUTE = 2, MODE_MEMBER = 8, @@ -421,7 +422,10 @@ $this->_params = array(); } - if (empty($returnProperties)) { + if ($returnProperties === self::NO_RETURN_PROPERTIES) { + $this->_returnProperties = array(); + } + elseif (empty($returnProperties)) { $this->_returnProperties = self::defaultReturnProperties($mode); } else { diff --git a/CRM/Contact/Selector.php b/CRM/Contact/Selector.php index d8920ae..2ec49ce 100644 --- a/CRM/Contact/Selector.php +++ b/CRM/Contact/Selector.php @@ -1213,15 +1213,16 @@ if (!$displayRelationshipType) { $query = new CRM_Contact_BAO_Query($params, - $this->_returnProperties, - NULL, FALSE, FALSE, 1, + CRM_Contact_BAO_Query::NO_RETURN_PROPERTIES, + array('contact_id'), FALSE, FALSE, 1, FALSE, TRUE, TRUE, NULL, $queryOperator ); } else { - $query = new CRM_Contact_BAO_Query($params, $this->_returnProperties, - NULL, FALSE, FALSE, 1, + $query = new CRM_Contact_BAO_Query($params, + CRM_Contact_BAO_Query::NO_RETURN_PROPERTIES, + array('contact_id'), FALSE, FALSE, 1, FALSE, TRUE, TRUE, $displayRelationshipType, $queryOperator ); diff --git a/CRM/Core/DAO.php b/CRM/Core/DAO.php index d142405..b0eb4d3 100644 --- a/CRM/Core/DAO.php +++ b/CRM/Core/DAO.php @@ -78,6 +78,12 @@ static $_checkedSqlFunctionsExist = FALSE; /** + * https://issues.civicrm.org/jira/browse/CRM-17748 + * internal variable for DAO to hold per-query settings + */ + protected $_options = array(); + + /** * Class constructor. * * @return \CRM_Core_DAO @@ -321,12 +327,20 @@ */ public function query($query, $i18nRewrite = TRUE) { // rewrite queries that should use $dbLocale-based views for multi-language installs - global $dbLocale; + global $dbLocale, $_DB_DATAOBJECT; + + $conn = &$_DB_DATAOBJECT['CONNECTIONS'][$this->_database_dsn_md5]; + $orig_options = $conn->options; + $this->_setDBOptions($this->_options); + if ($i18nRewrite and $dbLocale) { $query = CRM_Core_I18n_Schema::rewriteQuery($query); } - return parent::query($query); + $ret = parent::query($query); + + $this->_setDBOptions($orig_options); + return $ret; } /** @@ -1156,6 +1170,64 @@ $object->entity_table = 'civicrm_contact'; $object->entity_id = $contactId; $object->delete(); + } + + /** + * execute an unbuffered query. This is a wrapper around new functionality + * exposed with CRM-17748. + * + * @param string $query query to be executed + * + * @return Object CRM_Core_DAO object that points to an unbuffered result set + * @static + * @access public + */ + static public function executeUnbufferedQuery( + $query, + $params = array(), + $abort = TRUE, + $daoName = NULL, + $freeDAO = FALSE, + $i18nRewrite = TRUE, + $trapException = FALSE + ) { + $queryStr = self::composeQuery($query, $params, $abort); + //CRM_Core_Error::debug( 'q', $queryStr ); + if (!$daoName) { + $dao = new CRM_Core_DAO(); + } + else { + $dao = new $daoName(); + } + + if ($trapException) { + CRM_Core_Error::ignoreException(); + } + + // set the DAO object to use an unbuffered query + $dao->setOptions(array('result_buffering' => 0)); + + $result = $dao->query($queryStr, $i18nRewrite); + + if ($trapException) { + CRM_Core_Error::setCallback(); + } + + if (is_a($result, 'DB_Error')) { + return $result; + } + + // since it is unbuffered, ($dao->N==0) is true. This blocks the standard fetch() mechanism. + $dao->N = TRUE; + + if ($freeDAO || + preg_match('/^(insert|update|delete|create|drop|replace)/i', $queryStr) + ) { + // we typically do this for insert/update/delete stataments OR if explicitly asked to + // free the dao + $dao->free(); + } + return $dao; } /** @@ -2410,6 +2482,37 @@ } /** + * https://issues.civicrm.org/jira/browse/CRM-17748 + * Sets the internal options to be used on a query + * + * @param array $options + * + */ + function setOptions($options) { + if (is_array($options)) { + $this->_options = $options; + } + } + + /** + * https://issues.civicrm.org/jira/browse/CRM-17748 + * wrapper to pass internal DAO options down to DB_mysql/DB_Common level + * + * @param array $options + * + */ + protected function _setDBOptions($options) { + global $_DB_DATAOBJECT; + + if (is_array($options) && count($options)) { + $conn = &$_DB_DATAOBJECT['CONNECTIONS'][$this->_database_dsn_md5]; + foreach ($options as $option_name => $option_value) { + $conn->setOption($option_name, $option_value); + } + } + } + + /** * @param array $params */ public function setApiFilter(&$params) { -- To view, visit https://gerrit.wikimedia.org/r/274060 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I8a9129c665c7efd61e14a8b1ad1de191ffef1996 Gerrit-PatchSet: 2 Gerrit-Project: wikimedia/fundraising/crm/civicrm Gerrit-Branch: master Gerrit-Owner: Eileen <emcnaugh...@wikimedia.org> Gerrit-Reviewer: Awight <awi...@wikimedia.org> Gerrit-Reviewer: Eileen <emcnaugh...@wikimedia.org> Gerrit-Reviewer: Ejegg <eeggles...@wikimedia.org> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits