CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • CRM_Core_DAO::executeQuery() in Smarty function returns HTML
Pages: [1]

Author Topic: CRM_Core_DAO::executeQuery() in Smarty function returns HTML  (Read 1060 times)

s0014

  • I post occasionally
  • **
  • Posts: 56
  • Karma: 2
  • CiviCRM version: 4.4.5
  • CMS version: Drupal 7.28
  • MySQL version: 5.5.37
  • PHP version: 5.5.9
CRM_Core_DAO::executeQuery() in Smarty function returns HTML
July 14, 2014, 09:14:05 am
Hey,

I am using CRM_Core_DAO::executeQuery() in a smarty plugin. Now, whenever there is a database error, the function prints the following code.

Code: [Select]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">

<head>
  <title></title>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <base href="http://xav.crm:8001/sites/all/modules/civicrm/" />
  <style type="text/css" media="screen">@import url(http://xav.crm:8001/sites/all/modules/civicrm/css/civicrm.css);</style>
  <style type="text/css" media="screen">@import url(http://xav.crm:8001/sites/all/modules/civicrm/css/extras.css);</style>
</head>
<body>
<div id="crm-container" class="crm-container" lang="en" xml:lang="en">
<div class="messages status no-popup">  <div class="icon red-icon alert-icon"></div>
 <span class="status-fatal">Sorry but we are not able to provide this at the moment.</span>
    <div class="crm-section crm-error-message"></div>
            <hr style="solid 1px" />
        <div class="crm-section crm-error-message">DB Error: no such field</div>
            <p><a href="http://xav.crm:8001/" title="Main Menu">Return to home page.</a></p>
</div>
</div>
<script language="JavaScript">
function toggle( element ) {
    var className = element.className;
    if ( className  == 'crm-accordion-wrapper collapsed crm-fatal-error-details-block') {
        element.className = 'crm-accordion-wrapper  crm-fatal-error-details-block';
    } else {
        element.className = 'crm-accordion-wrapper collapsed crm-fatal-error-details-block';
    }
}
</script>

</body>
</html>

This causes the whole page to crash. Is there a workaround for this, I have tried $abort=False, and $trapException=False, but it is still not helping.

All I get is the page doesn't get loaded, and

var eventdetails = {crmFunction bla="1" blah="2"} converted to

var eventdetails = !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">..
....

I tried catching the exception as well, but it throws no exception. I have also tried if the result is_a('DB_Error') but this also doesn't seem to help.
Sid
DataViz Project, GSoC 2014

totten

  • Administrator
  • Ask me questions
  • *****
  • Posts: 695
  • Karma: 64
Re: CRM_Core_DAO::executeQuery() in Smarty function returns HTML
July 14, 2014, 01:56:58 pm
CRM_Core_DAO (or, more specifically, its parent class -- PEAR's DB_DataObject) is wired to handle errors by printing out an HTML page and exiting. You should be able to temporarily override this and instead use exceptions -- which are easier to catch.

Code: [Select]
<?php
function smarty_something(...) {
  
$errorScope = CRM_Core_TemporaryErrorScope::useException();
  try {
    
CRM_Core_DAO::executeQuery(...);
  } catch (
Exception $e) {
    
// do something nice with $e
  
}

s0014

  • I post occasionally
  • **
  • Posts: 56
  • Karma: 2
  • CiviCRM version: 4.4.5
  • CMS version: Drupal 7.28
  • MySQL version: 5.5.37
  • PHP version: 5.5.9
Re: CRM_Core_DAO::executeQuery() in Smarty function returns HTML
July 17, 2014, 11:35:52 am
Thanks a ton Tim, really solved my problem.
Sid
DataViz Project, GSoC 2014

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • CRM_Core_DAO::executeQuery() in Smarty function returns HTML

This forum was archived on 2017-11-26.