Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Paramaterised SP returns same results, no matter what parm is used

Status
Not open for further replies.

SQLWilts

Programmer
Feb 12, 2001
651
GB
Hi,
I have MySQL 5 running on a windows box.

I have a weird caching scenario going on here, which I am convinced is the client - but any help pointers would be appreciated.

I have a SP which does a simple select according to parms
Code:
CREATE PROCEDURE adcentre.`search_classifiedListings`(
_customerNumber INT,
_directoryId int,
_headingId int,
out _recordCount int)
BEGIN

  select sql_no_cache distinct
    SQL_CALC_FOUND_ROWS
    MAX(l.end_date) as listing_end_date,
    l.tlsearch_listing_code as listing_code,
    l.listing_type_enum,
    l.match_group,
    ld.listing_name as business_name,
    ld.postcode,
    ld.phonenumber as phone_number,
    l.classified_listing_id,
    h.name as heading_name,
    d.name as directory_area
  from ada_classified_listing l
  inner join ada_directory d on d.directory_id = l.directory_id
  inner join ada_heading h on h.heading_id = l.heading_id
  left outer join listing_detail ld on ld.listing_code = l.tlsearch_listing_code
  where
  (l.customer_number is null or l.customer_number = _customerNumber) and
  (_directoryId is null or _directoryId = l.directory_id) and
  (_headingId is null or _headingId = l.heading_id)

  group by directory_area, heading_name, match_group

  order by heading_name, directory_area

  limit 200;

  set _recordCount = found_rows();
END;

If I call the SP like so in MySQL QA I get 8 rows on the first call, and 4 on the second - repeatable.

Code:
call adcentre.search_classifiedListings(174605,null,null, @recordCount);

call adcentre.search_classifiedListings(174605,null,208, @recordCount);

If I call them using Toad or my .net app, the first call returns 8 rows, the second 4, if I then use the first call again I only get 4 rows! This will then only return 4 rows until I break and reconnect.

I have turned off query caching on the server, but I am convinced that this is happening on the client somewhere as MySQL QA works fine.

Any thoughts/ideas/contributions appreciated
 
It appears to be the way nulls are being handled.
I am calling the proc as
Code:
call myprocname parm1, null, null, null
returns 8 rows
Code:
call myprocname parm1, null, null, 208
returns 4 rows
Code:
call myprocname parm1, null, null, null
returns the same 4 rows as above, but if I use
Code:
call myprocname parm1, null, null, 683
then I get a different result

I am saying

Code:
where
  (l.customer_number is null or l.customer_number = _customerNumber) and
Is this correct?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top