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 »
  • Post-installation Setup and Configuration (Moderator: Dave Greenberg) »
  • SQL error
Pages: [1]

Author Topic: SQL error  (Read 1308 times)

8ballsaysiwin@gmail.com

  • Guest
SQL error
August 19, 2009, 06:58:20 pm
I am relative new to PHP, could someone please tell me what the error in this syntax is?

Code: [Select]
    $types = crmax_query("SELECT value, label FROM {civicrm_option_value} WHERE option_group_id=(SELECT id FROM {civicrm_option_group} WHERE name='activity_type') AND filter=0 and is_active=1");

This is the error I am getting.
Code: [Select]
Error Details:

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

    [code] => -2
    [message] => DB Error: syntax error
    [mode] => 16
    [debug_info] => SELECT value, label FROM {civicrm_option_value} WHERE option_group_id=(SELECT id FROM {civicrm_option_group} WHERE name='activity_type') AND is_active=1 [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 '} WHERE option_group_id=(SELECT id FROM {civicrm_option_group} WHERE name='activ' at line 1]
    [type] => DB_Error
    [user_info] => SELECT value, label FROM {civicrm_option_value} WHERE option_group_id=(SELECT id FROM {civicrm_option_group} WHERE name='activity_type') AND is_active=1 [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 '} WHERE option_group_id=(SELECT id FROM {civicrm_option_group} WHERE name='activ' at line 1]
    [to_string] => [db_error: message="DB Error: syntax error" code=-2 mode=callback callback=CRM_Core_Error::handle prefix="" info="SELECT value, label FROM {civicrm_option_value} WHERE option_group_id=(SELECT id FROM {civicrm_option_group} WHERE name='activity_type') AND is_active=1 [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 '} WHERE option_group_id=(SELECT id FROM {civicrm_option_group} WHERE name='activ' at line 1]"]
)
[/code]

Kiran Jagtap

  • Ask me questions
  • ****
  • Posts: 533
  • Karma: 51
Re: SQL error
August 19, 2009, 10:03:13 pm
your corrected query might be like :
Code: [Select]
SELECT value, label
FROM civicrm_option_value
WHERE option_group_id=(SELECT id FROM civicrm_option_group WHERE name='activity_type') AND filter = 0 and is_active = 1

Also if you don't want nested queries, than query might be :
Quote
SELECT val.value, val.label
FROM civicrm_option_value val
LEFT JOIN civicrm_option_group grp on ( grp.id = val.option_group_id)
WHERE grp.name ='activity_type'
AND  val.filter = 0
AND val.is_active = 1

kiran
You Are Designed To Choose... Defined By Choice.

Sunil

  • I post frequently
  • ***
  • Posts: 131
  • Karma: 23
  • The community around a product more important than the product itself?
    • CiviCRM
Re: SQL error
August 19, 2009, 10:08:26 pm
Hi,

This error because of Curly bracket not replacing

If you run the same SQL by removing the '{' , '}' then work fine.

Sunil


The community around a product more important than the product itself?

8ballsaysiwin@gmail.com

  • Guest
Re: SQL error
August 20, 2009, 05:04:20 pm
Thanks. I tried all three of those options and all three break my page. So I assume I am doing something else incorrectly. Any idea what could be causing that?

Running devel here is what the page returns with the correct syntax in that query:
Code: [Select]
Executed 9 queries in 7.62 milliseconds.

Array
(
    [0] => Array
        (
            [0] => module_list
/* Administrator : module_list */ SELECT name, filename, throttle FROM system WHERE type = 'module' AND status = 1 AND bootstrap = 1 ORDER BY weight ASC, filename ASC
            [1] => 0.000849962234497
        )

    [1] => Array
        (
            [0] => drupal_get_filename
/* Administrator : drupal_get_filename */ SELECT filename FROM system WHERE name = 'user' AND type = 'module'
            [1] => 0.00178098678589
        )

    [2] => Array
        (
            [0] => drupal_lookup_path
/* Administrator : drupal_lookup_path */ SELECT COUNT(pid) FROM url_alias
            [1] => 0.000203847885132
        )

    [3] => Array
        (
            [0] => module_list
/* Administrator : module_list */ SELECT name, filename, throttle FROM system WHERE type = 'module' AND status = 1 ORDER BY weight ASC, filename ASC
            [1] => 0.00116395950317
        )

    [4] => Array
        (
            [0] => _connect
/* Administrator */ /*!40101 SET NAMES utf8 */
            [1] => 0.000291109085083
        )

    [5] => Array
        (
            [0] => _initVariables
/* Administrator */ SELECT  config_backend, locales  FROM civicrm_domain

            [1] => 0.000380039215088
        )

    [6] => Array
        (
            [0] => menu_get_item
/* Administrator : menu_get_item */ SELECT * FROM menu_router WHERE path IN ('civicrm/admin/civiassign','civicrm/admin/%','civicrm/%/civiassign','civicrm/admin','civicrm/%','civicrm') ORDER BY fit DESC LIMIT 0, 1
            [1] => 0.000702857971191
        )

    [7] => Array
        (
            [0] => sess_write
/* Administrator : sess_write */ UPDATE sessions SET uid = 1, cache = 0, hostname = '::1', session = 'CiviCRM|a:19:{s:4:\"ufID\";s:1:\"1\";s:6:\"userID\";i:102;s:8:\"ufUniqID\";s:0:\"\";s:11:\"userContext\";a:6:{i:0;s:40:\...' // this string continues but was much too long to post here
            [1] => 0.00201988220215
        )

    [8] => Array
        (
            [0] => sess_write
/* Administrator : sess_write */ UPDATE users SET access = 1250812925 WHERE uid = 1
            [1] => 0.000223159790039
        )

)

Memory usage:
Memory used at: devel_init()=0.96 MB, devel_shutdown()=11.3 MB.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Post-installation Setup and Configuration (Moderator: Dave Greenberg) »
  • SQL error

This forum was archived on 2017-11-26.