Results 1 to 6 of 6

Thread: Issue with get_entry_list soap call with SQL Server 2005

  1. #1
    mickeyhaynes is offline Junior Member
    Join Date
    May 2007
    Posts
    3

    Default Issue with get_entry_list soap call with SQL Server 2005

    I am using Sugar Open Source Version 4.5.1b (Build 1246) with PHP on SQL Server 2005. The client application is written in C# using Visual Studio 2005.

    The issue arises when executing a subquery through the get_entry_list web service. The underlying SQL that is generated by the web service is not what is expected and creates a SQL exception.

    When calling the get_entry_list service with the following parameters:

    module_name = "Opportunities"
    query = "opportunities.id in (select opportunity_id id from opportunities_contacts where contact_id = '<<contactId>>)'"
    order_by = ""
    offset = 0
    select_fields = {"id", "name"}
    max_results = 100
    deleted = 0


    A SQL Exception is generated. Using SQL Trace to inspect the SQL created by the web service shows the following:

    SELECT count(*) c FROM opportunities LEFT JOIN users
    ON opportunities.assigned_user_id=users.id LEFT JOIN accounts_opportunities
    ON opportunities.id=accounts_opportunities.opportunit y_id
    LEFT JOIN accounts
    ON accounts_opportunities.account_id=accounts.id
    where (opportunities.id in (SELECT count(*) c FROM opportunities_contacts where contact_id = '<<contactid>>'))
    AND (accounts_opportunities.deleted is null OR accounts_opportunities.deleted=0)
    AND (accounts.deleted is null OR accounts.deleted=0)
    AND opportunities.deleted=0

    The key issue is in the line:
    where (opportunities.id in (SELECT count(*) c FROM opportunities_contacts where contact_id = '<<contactid>>'))

    The correct SQL should be:
    where (opportunities.id in (SELECT opportunity_id id FROM opportunities_contacts where contact_id = '<<contactid>>'))

    The web service is apparantly changing my subquery to try to get a Count, but this creates a SQL exception.

    Please advise. Regards....

  2. #2
    julian's Avatar
    julian is offline Sugar Team Member
    Join Date
    Sep 2004
    Posts
    1,639

    Default Re: Issue with get_entry_list soap call with SQL Server 2005

    Hello mickeyhaynes,

    It looks like the culprit is this line in ./data/SugarBean.php:

    PHP Code:
            $pattern '/SELECT(.*?)(\s){1}FROM(\s){1}/is';  // ignores the case
            
    $replacement 'SELECT count(*) c FROM ';
            
    $modified_select_query preg_replace($pattern$replacement$query); 
    I see why this method exists (to create COUNT() statements from generic queries), but it should not be applied to the query you pass in the SOAP call. For now, you have three options:

    1) change your SOAP application so it does not rely on a subquery in the WHERE clause (these will probably not be supported in the revamped SOAP API for Sugar 5.0)
    2) change the Sugar code (in SugarBean.php) to add an exception if the query is coming from SOAP
    3) modify your subquery to try and sidestep the preg_replace() call

    This is something I'd like to fix in the product as well, but it'll require re-working a few parts of the API. It'd be a good idea to file a bug for this on http://bugs.sugarcrm.com/ -- you can reference this forum thread when posting the bug.

    Thanks!
    Julian Ostrow
    Systems and Applications Engineer
    SugarCRM Inc.

  3. #3
    mickeyhaynes is offline Junior Member
    Join Date
    May 2007
    Posts
    3

    Default Re: Issue with get_entry_list soap call with SQL Server 2005

    Thank you, Julian, for your prompt response. I have posted a bug #12878 for this issue.

    Unfortunately, in my case I cannot change the PHP code on the server, so I will need to come up with a client-side solution. Do you have an alternative suggestion to get opportunities for a contact without using the get_entry_list subquery method?

    Thanks again...

  4. #4
    julian's Avatar
    julian is offline Sugar Team Member
    Join Date
    Sep 2004
    Posts
    1,639

    Default Re: Issue with get_entry_list soap call with SQL Server 2005

    Hey mickeyhaynes,

    Definitely. Take a look at the get_relationships() SOAP method. Prior to 4.5.1c, many relationships were not available through this method, but that's since been fixed. You'll want to make a call similar to this:

    PHP Code:
    $output $client->get_relationships($session_id"Contacts""<your Contact GUID>""Opportunities"""0); 
    Julian Ostrow
    Systems and Applications Engineer
    SugarCRM Inc.

  5. #5
    mickeyhaynes is offline Junior Member
    Join Date
    May 2007
    Posts
    3

    Default Re: Issue with get_entry_list soap call with SQL Server 2005

    That worked perfectly, thanks Julian! I suppose there are quite a few knowledge base articles and code samples out there that need to be updated. Better documentation on the soap.php would also be great!

    Thanks again.

  6. #6
    rayner.jrp is offline Junior Member
    Join Date
    Mar 2010
    Posts
    2

    Default Re: Issue with get_entry_list soap call with SQL Server 2005

    How can i get an unlimited number of elements with get_entry_list method througth soap api of sugar?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 1
    Last Post: 2008-02-22, 04:25 PM
  2. SQL Express 2005 Step 7 cannot connect to server
    By CRMNOW in forum Installation and Upgrade Help
    Replies: 0
    Last Post: 2007-02-02, 07:49 PM
  3. Replies: 4
    Last Post: 2006-09-29, 04:15 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •