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) »
  • sorting search results by state fails with a DB error - column 'state_province'
Pages: [1]

Author Topic: sorting search results by state fails with a DB error - column 'state_province'  (Read 833 times)

mhonman

  • I’m new here
  • *
  • Posts: 20
  • Karma: 2
sorting search results by state fails with a DB error - column 'state_province'
February 01, 2012, 02:28:05 pm
In CiviCRM 3.4.8, if one clicks on the 'State' column header in the search results, production of a sorted version of the results fails with a DB error because the generated SQL query has an ORDER BY clause referencing a column named state_province - however the name of the State or Province is actually found in the 'name' column of the civicrm_state_province table.

I believe the problem originates in CRM/Contact/Selector.php but have been unable to confirm this as I haven't been able to get useful debugging output from that file. However it's been a very long day and it could well be that I'm logging into quite the wrong server.

The problem is reproducible on the 3.4.8 demo site... I'm very surprised no-one has encountered it before.

To reproduce, from the menu select Search->Advanced Search
there is no need to enter criteria, just click 'Search'
when the list of results is displayed, click on the 'State' column header
BOOM - fizz.

The error message, in all its glory, is:

Database Error Code: Unknown column 'state_province' in 'order clause', 1054
Additional Details:

Array
(
    [callback] => Array
        (
           
  • => CRM_Core_Error
  • [1] => handle
            )

       
Code: [Select]
=> -19
    [message] => DB Error: no such field
    [mode] => 16
    [debug_info] =>
INSERT INTO civicrm_prevnext_cache ( entity_table, entity_id1, entity_id2, cacheKey, data )
SELECT 'civicrm_contact', contact_a.id, contact_a.id, 'civicrm search 44d8f2ace5e4a4ad8ed2567ff896f444_8479', contact_a.display_name
  FROM civicrm_contact contact_a LEFT JOIN civicrm_address ON ( contact_a.id = civicrm_address.contact_id AND civicrm_address.is_primary = 1 ) LEFT JOIN civicrm_state_province ON civicrm_address.state_province_id = civicrm_state_province.id  WHERE (contact_a.is_deleted = 0)   GROUP BY contact_a.id  ORDER BY state_province asc  [nativecode=1054 ** Unknown column 'state_province' in 'order clause']
    [type] => DB_Error
    [user_info] =>
INSERT INTO civicrm_prevnext_cache ( entity_table, entity_id1, entity_id2, cacheKey, data )
SELECT 'civicrm_contact', contact_a.id, contact_a.id, 'civicrm search 44d8f2ace5e4a4ad8ed2567ff896f444_8479', contact_a.display_name
  FROM civicrm_contact contact_a LEFT JOIN civicrm_address ON ( contact_a.id = civicrm_address.contact_id AND civicrm_address.is_primary = 1 ) LEFT JOIN civicrm_state_province ON civicrm_address.state_province_id = civicrm_state_province.id  WHERE (contact_a.is_deleted = 0)   GROUP BY contact_a.id  ORDER BY state_province asc  [nativecode=1054 ** Unknown column 'state_province' in 'order clause']
    [to_string] => [db_error: message="DB Error: no such field" code=-19 mode=callback callback=CRM_Core_Error::handle prefix="" info="
INSERT INTO civicrm_prevnext_cache ( entity_table, entity_id1, entity_id2, cacheKey, data )
SELECT 'civicrm_contact', contact_a.id, contact_a.id, 'civicrm search 44d8f2ace5e4a4ad8ed2567ff896f444_8479', contact_a.display_name
  FROM civicrm_contact contact_a LEFT JOIN civicrm_address ON ( contact_a.id = civicrm_address.contact_id AND civicrm_address.is_primary = 1 ) LEFT JOIN civicrm_state_province ON civicrm_address.state_province_id = civicrm_state_province.id  WHERE (contact_a.is_deleted = 0)   GROUP BY contact_a.id  ORDER BY state_province asc  [nativecode=1054 ** Unknown column 'state_province' in 'order clause']"]
)

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: sorting search results by state fails with a DB error - column 'state_province'
February 01, 2012, 02:50:18 pm

This has been fixed in v4.1

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

mhonman

  • I’m new here
  • *
  • Posts: 20
  • Karma: 2
Re: sorting search results by state fails with a DB error - column 'state_province'
February 02, 2012, 12:02:28 pm
Thanks lobo, that's good to know - however we are still on Drupal 6 for the next few months at least.

If you can point me to the fix in the 4.x code, I'd be willing to try and apply it in the 3.4 codebase if that would make sense.

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: sorting search results by state fails with a DB error - column 'state_province'
February 02, 2012, 04:01:28 pm

4.1 is supporting D6 thanx to eileen and tim

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

click on fisheye tab to see the patches

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

mhonman

  • I’m new here
  • *
  • Posts: 20
  • Karma: 2
Re: sorting search results by state fails with a DB error - column 'state_province'
February 03, 2012, 02:33:35 am
That;s excellent news... standing ovation for Eileen & Tim!

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Core CiviCRM Functions (Moderator: Yashodha Chaku) »
  • sorting search results by state fails with a DB error - column 'state_province'

This forum was archived on 2017-11-26.