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 CiviReport (Moderator: Dave Greenberg) »
  • V2 schema - get primary email only for a contact
Pages: [1]

Author Topic: V2 schema - get primary email only for a contact  (Read 4836 times)

speleo

  • Ask me questions
  • ****
  • Posts: 396
  • Karma: 28
  • CiviCRM version: 4.3.1
  • CMS version: J! 2.5,9
  • MySQL version: 5.1
  • PHP version: 5.3.24
V2 schema - get primary email only for a contact
February 25, 2008, 04:38:47 am
Under the old schema the sql below would return a table with a single entry for each contacts primary email

Code: [Select]
SELECT 
i.first_name AS 'First Name',
i.last_name AS 'Last Name',
e.email AS 'email'   

FROM    ((civicrm_individual AS i 
LEFT JOIN civicrm_location AS loc ON i.contact_id = loc.entity_id)
LEFT JOIN civicrm_email AS e ON loc.id=e.location_id AND e.is_primary = 1 )

With the schema changed I assumed that I could this

Code: [Select]
SELECT
c.first_name AS 'First Name',
c.last_name AS 'Last Name',
e.email AS 'email'
   
FROM   
((civicrm_contact AS c
LEFT JOIN civicrm_email AS e ON c.id=e.contact_id AND e.is_primary = 1 )

This is based on this info http://wiki.civicrm.org/confluence/display/CRM/Location+Data

However in my db all the entries in civicrm_email have is_primary = 1.  Surely there should only be a single civicrm_email.is_primary = 1 for each civicrm_email.contact_id??

Is my sql logic wrong or is my email table incorrect?

Kurund Jalmi

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4169
  • Karma: 128
    • CiviCRM
  • CiviCRM version: 4.x, future
  • CMS version: Drupal 7, Joomla 3.x
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: V2 schema - get primary email only for a contact
February 25, 2008, 05:00:42 am
Quote
Surely there should only be a single civicrm_email.is_primary = 1 for each civicrm_email.contact_id??

Yes. Every Contact record will have only one "Primary" email address. So your SQL logic should work.
Wanna investigate more how you got this db state.

kurund
Found this reply helpful? Support CiviCRM

speleo

  • Ask me questions
  • ****
  • Posts: 396
  • Karma: 28
  • CiviCRM version: 4.3.1
  • CMS version: J! 2.5,9
  • MySQL version: 5.1
  • PHP version: 5.3.24
Re: V2 schema - get primary email only for a contact
February 25, 2008, 05:11:16 am
Looking at my 1.9 tables it looks like the is_primary data is correct. Each civicrm19.email.location_id has only a single is_primary email.

Is it possible that the upgrade process to v2.0 schema has changed this??

Kurund Jalmi

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4169
  • Karma: 128
    • CiviCRM
  • CiviCRM version: 4.x, future
  • CMS version: Drupal 7, Joomla 3.x
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: V2 schema - get primary email only for a contact
February 25, 2008, 05:25:49 am
You are right. This looks like a bug in upgrade process. Can you file an issue for this in jira.

thanx

kurund
Found this reply helpful? Support CiviCRM

speleo

  • Ask me questions
  • ****
  • Posts: 396
  • Karma: 28
  • CiviCRM version: 4.3.1
  • CMS version: J! 2.5,9
  • MySQL version: 5.1
  • PHP version: 5.3.24
Re: V2 schema - get primary email only for a contact
February 25, 2008, 05:56:54 am
http://issues.civicrm.org/jira/browse/CRM-2728

speleo

  • Ask me questions
  • ****
  • Posts: 396
  • Karma: 28
  • CiviCRM version: 4.3.1
  • CMS version: J! 2.5,9
  • MySQL version: 5.1
  • PHP version: 5.3.24
Re: V2 schema - get primary email only for a contact
February 25, 2008, 10:47:37 am
kurund,

now that it is fixed, I assume that in order to bring my db back inline I just need to run location.mysql against a copy of my 1.9 db and then push the updated tables over.

However...there are other changes happening to the upgrade scripts which touch other tables. I know that you don't normally provide interim fixes but some advice would be appreciated.

Kurund Jalmi

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4169
  • Karma: 128
    • CiviCRM
  • CiviCRM version: 4.x, future
  • CMS version: Drupal 7, Joomla 3.x
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: V2 schema - get primary email only for a contact
February 25, 2008, 09:17:23 pm
I think best approach will be restore you 1.9 db and then go through entire upgrade process.

kurund
Found this reply helpful? Support CiviCRM

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using CiviReport (Moderator: Dave Greenberg) »
  • V2 schema - get primary email only for a contact

This forum was archived on 2017-11-26.