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) »
  • Adding custom groups with v2 API
Pages: [1]

Author Topic: Adding custom groups with v2 API  (Read 2044 times)

dougall

  • Guest
Adding custom groups with v2 API
March 25, 2008, 06:17:21 am
Hi,

I've just upgraded civicrm from 1.9 to 2.0, and I'm updating my code for adding custom groups/fields using:
Code: [Select]
function civicrm_custom_group_create(parms)
One change that I've noticed is that in addition to adding the custom group to civicrm_custom_group table, a new table is also created called "civicrm_value_1_******" where * appears to be taken from the "title" field in the parms. The only problem is that an SQL error is thrown if I have any spaces in this field.

For example if I use the following code:
Code: [Select]
  $params = array( 'domain_id'        => 1,
                   'title'            => 'TestGroup1_No_Spaces_In_Title',
                   'name'             => 'test_group_1',
                   'class_name'       => 'Individual',
                   'weight'           => 4,
                   'collapse_display' => 1,
                   'style'            => 'Tab',
                   'help_pre'         => 'This is Pre Help For Test Group 1',
                   'help_post'        => 'This is Post Help For Test Group 1',
                   'is_active'        => 1
                   );
  $customGroup =& civicrm_custom_group_create($params); 
  echo "Created test group:<br>".print_r($customGroup,true)."<br><br>; 
Then the group is successfully created:
Quote
Array ( [id] => 11 [domain_id] => 1 [name] => test_group_1 [title] => TestGroup1_No_Spaces_In_Title [extends] => Individual [extends_entity_column_name] => [extends_entity_column_value] => [style] => Tab [collapse_display] => 1 [help_pre] => This is Pre Help For Test Group 1 [help_post] => This is Post Help For Test Group 1 [weight] => 4 [is_active] => 1 [table_name] => civicrm_value_1_TestGroup1_No_Spaces_In_Title [is_multiple] => [is_error] => 0 )

However if I use a title which does have spaces in the name, like this:
Code: [Select]
  $params = array( 'domain_id'        => 1,
                   'title'            => 'TestGroup2 Spaces In Title',
                   'name'             => 'test_group_2',
                   'class_name'       => 'Individual',
                   'weight'           => 4,
                   'collapse_display' => 1,
                   'style'            => 'Tab',
                   'help_pre'         => 'This is Pre Help For Test Group 2',
                   'help_post'        => 'This is Post Help For Test Group 2',
                   'is_active'        => 1
                   );
  $customGroup =& civicrm_custom_group_create($params); 
  echo "Created test group:<br>".print_r($customGroup,true)."<br><br>; 
Then I get a DB error (I guess because of the spaces in the name of the table being created).
The returned "debug_info" is:
Quote
CREATE TABLE civicrm_value_1_TestGroup2 Spaces In Title (
        `id` int unsigned NOT NULL AUTO_INCREMENT COMMENT 'Default MySQL primary key',
        `domain_id` int unsigned NOT NULL COMMENT 'Default Domain that this data belongs to',
        `entity_id` int unsigned NOT NULL COMMENT 'Table that this extends',
        PRIMARY KEY ( id ),
        UNIQUE INDEX unique_domain_id_entity_id (  domain_id, entity_id ),
        CONSTRAINT FK_civicrm_value_1_TestGroup2 Spaces In Title_domain_id FOREIGN KEY ( `domain_id` ) REFERENCES civicrm_domain ( id ) ,
        CONSTRAINT FK_civicrm_value_1_TestGroup2 Spaces In Title_entity_id FOREIGN KEY ( `entity_id` ) REFERENCES civicrm_contact ( id ) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci; [nativecode=1064 ** You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Spaces In Title (
        `id` int unsigned NOT NULL AUTO_INCREMENT COMMENT 'Def' at line 1]

Maybe I'm missing the significance of something here, but this behaviour seems a little dubious to me, surely it should be acceptable to have spaces in the title?

Thanks,
  Dougall

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: Adding custom groups with v2 API
March 25, 2008, 10:14:37 am

this was a bug in the api. it is now fixed in the svn version and will be part of 2.0.2

http://issues.civicrm.org/jira/browse/CRM-2895

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

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Adding custom groups with v2 API

This forum was archived on 2017-11-26.