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....


LinkBack URL
About LinkBacks



Reply With Quote
Bookmarks