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) »
  • Support »
  • Using CiviCRM »
  • Using Core CiviCRM Functions (Moderator: Yashodha Chaku) »
  • [SOLVED] how to execute multiple database queries in one custom search
Pages: [1]

Author Topic: [SOLVED] how to execute multiple database queries in one custom search  (Read 770 times)

Sean Madsen

  • I post occasionally
  • **
  • Posts: 98
  • Karma: 5
  • CiviCRM implementer/developer
    • Bikes Not Bombs
  • CiviCRM version: 4.6
  • CMS version: Drupal 7
[SOLVED] how to execute multiple database queries in one custom search
March 24, 2010, 04:38:47 pm
I have some SQL code that I'd like to make in to a custom search. The SQL has some temporary tables and MySQL defined variables. These components of the code are necessary due to the complexity of the search. I can get a (simpler) custom search to work that just contains one SQL query. In trying to get the complicated search to work (that contains more than one query), I've tried putting multiple queries in the return value for the "all" function (which does indeed generate the SQL that I'm looking for), but I get an error. Is there another place that I can insert some SQL to run before the main query, but in such a way that it runs with the same MySQL session as the main query (so that I can initialize temporary tables and variables)?

For example:

I can get a query like this to work:
"select sort_name from civicrm_contact where id = 3"

but I can't get one like this to work:
"set @foo = 3; select sort_name from civicrm_contact where id = @foo"
« Last Edit: March 25, 2010, 07:41:08 am by Sean Madsen »

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: how to execute multiple database queries in one custom search
March 24, 2010, 09:47:47 pm

hey sean:

check:

CRM/Contact/Form/Search/Custom/Group.php

we use a fair number of queries and temp tables there. does this work for you

CRM_Core_DAO:executeQuery( "set @foo=3" );
CRM_Core_DAO:executeQuery( "select sort_name from civicrm_contact where id = @foo" );

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

Sean Madsen

  • I post occasionally
  • **
  • Posts: 98
  • Karma: 5
  • CiviCRM implementer/developer
    • Bikes Not Bombs
  • CiviCRM version: 4.6
  • CMS version: Drupal 7
Re: how to execute multiple database queries in one custom search
March 25, 2010, 07:39:59 am
Yes! Thanks, that works wonderfully. (The syntax requires two colons though).

Fore example, in the "all" function, I put the following code:
Code: [Select]
CRM_Core_DAO::executeQuery( "set @foo=3" );

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Core CiviCRM Functions (Moderator: Yashodha Chaku) »
  • [SOLVED] how to execute multiple database queries in one custom search

This forum was archived on 2017-11-26.