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) »
  • getting a column name with spaces
Pages: [1]

Author Topic: getting a column name with spaces  (Read 562 times)

SarahG (FountainTribe)

  • Ask me questions
  • ****
  • Posts: 782
  • Karma: 29
  • CiviCRM version: 4.4.7
  • CMS version: Drupal 6, Drupal 7
  • MySQL version: 5.5
  • PHP version: 5.3
getting a column name with spaces
November 04, 2014, 09:12:01 am
I am using CiviCRM to execute the following SQL:  "SHOW CREATE TRIGGER `civicrm_contact_before_insert`"

But one of the field names returned is "SQL Original Statement". My syntax to get the field is not working because of the spaces: 

Code: [Select]
$dao->SQL Original Statement
What syntax should I use to get the field "SQL Original Statement"

Thanks,
Did I help you? Please donate to the Civi-Make-It-Happen campaign  CiviCRM for mobile devices! 

FrTommy

  • I post frequently
  • ***
  • Posts: 273
  • Karma: 2
  • CiviCRM version: 4.5.x
  • CMS version: Drupal 7.x
  • MySQL version: 5.5.32
  • PHP version: 5.3
Re: getting a column name with spaces
November 04, 2014, 09:55:50 am
If I remember correctly, you place the text in single quotes, 'Show SQL Original'

SarahG (FountainTribe)

  • Ask me questions
  • ****
  • Posts: 782
  • Karma: 29
  • CiviCRM version: 4.4.7
  • CMS version: Drupal 6, Drupal 7
  • MySQL version: 5.5
  • PHP version: 5.3
Re: getting a column name with spaces
November 04, 2014, 10:47:18 am
I tried single quotes
 
Code: [Select]
$dao->'SQL Original Statement';
and get the error message:

Parse error: syntax error, unexpected ''SQL Original Statement'' (T_CONSTANT_ENCAPSED_STRING), expecting identifier (T_STRING) or variable (T_VARIABLE) or '{' or '$' in /home/dev17/public_html/test/myscript.php
Did I help you? Please donate to the Civi-Make-It-Happen campaign  CiviCRM for mobile devices! 

Michael McAndrew

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1274
  • Karma: 55
    • Third Sector Design
  • CiviCRM version: various
  • CMS version: Nearly always Drupal
  • MySQL version: 5.5
  • PHP version: 5.3
Re: getting a column name with spaces
November 05, 2014, 02:58:27 am
https://github.com/civicrm/civicrm-core/blob/master/CRM/Core/DAO.php is based on http://pear.php.net/package/DB_DataObject so you might want to have a look at the DB_DataObject documentation.
Service providers: Grow your business, build your reputation and support CiviCRM. Become a partner today

SarahG (FountainTribe)

  • Ask me questions
  • ****
  • Posts: 782
  • Karma: 29
  • CiviCRM version: 4.4.7
  • CMS version: Drupal 6, Drupal 7
  • MySQL version: 5.5
  • PHP version: 5.3
Re: getting a column name with spaces
November 05, 2014, 12:27:53 pm
Those docs were helpful - it seems the only option is to turn the result set of fields into an array.  So I called the following method:

 
Code: [Select]
$dao = & CRM_Core_DAO::executeQuery(" SHOW CREATE TRIGGER `civicrm_website_after_delete" ,    CRM_Core_DAO::$_nullArray ) ;
 $tmp =  $dao->toArray();
 print_r( $tmp );

The code runs without error, but the resulting $tmp array is empty.  Does CiviCRM need to implement this method?
Did I help you? Please donate to the Civi-Make-It-Happen campaign  CiviCRM for mobile devices! 

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: getting a column name with spaces
November 05, 2014, 01:52:49 pm
$dao->{'SQL Original Statement'}

should do the trick
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

SarahG (FountainTribe)

  • Ask me questions
  • ****
  • Posts: 782
  • Karma: 29
  • CiviCRM version: 4.4.7
  • CMS version: Drupal 6, Drupal 7
  • MySQL version: 5.5
  • PHP version: 5.3
Re: getting a column name with spaces
November 08, 2014, 06:20:07 am
The syntax  {'SQL Original Statement'} did not blow up.   Also I got the syntax for toArray(); is working too. By working, I mean not blowing up or throwing an error message.    However, the weird issue I am having is there is no data in the field "SQL Original Statement", even though I am able to get the data for the other fields, such as character_set_client.
Did I help you? Please donate to the Civi-Make-It-Happen campaign  CiviCRM for mobile devices! 

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • getting a column name with spaces

This forum was archived on 2017-11-26.