Refreshing params on ORAQuery

Discussion of open issues, suggestions and bugs regarding ODAC (Oracle Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
jswanberg
Posts: 2
Joined: Sat 26 Sep 2015 15:34

Refreshing params on ORAQuery

Post by jswanberg » Sat 26 Sep 2015 15:43

I have an ORAQuery that I'd like to reuse and submit different params each but keep the same SELECT field list. When I clear the SQL and build a new query it works until I try to put values to the new params as it doesn't recognize. Doing a ORAQuery.Refresh doesn't work. How do I reinitialize the params list? Here's what I'm currently doing:

DM.StudentsQry.Close;
DM.StudentsQry.SQL.Clear;
DM.StudentsQry.SQL.Add('select s.ID, s.LASTFIRST, s.First_Name, s.Last_Name, s.Student_Number,' +
's.DOB, s.GRADE_LEVEL, s.MAILING_STREET, s.MAILING_CITY, s.MAILING_STATE, s.MAILING_ZIP, s.HOME_PHONE' +
'from students s' +
'join cc c on s.schoolid = c.schoolid and s.id = c.studentid and c.termid >= 2500' +
'join teachers pt on c.teacherid = pt.id and c.schoolid = pt.schoolid' +
'where s.enroll_status = 0 and s.schoolid = :SCHOOL' +
'and c.section_number = :SECTION' +
'and c.teacherid = :TEACHERID' +
'AND C.COURSE_NUMBER = :COURSENUMBER' +
'order by s.lastfirst');
DM.StudentsQry.Params.AddParam('SECTION');
DM.StudentsQry.ParamByName('SCHOOL').Value := SchoolNum;
DM.StudentsQry.ParamByName('SECTION').Value := DM.GetPSSections.FieldbyName('SECTION_NUMBER').AsString;
DM.StudentsQry.ParamByName('TEACHERID').Value := DM.GetPSTeachers.FieldbyName('ID').AsString;
DM.StudentsQry.ParamByName('COURSENUMBER').Value := DM.GetPSSections.FieldbyName('COURSE_NUMBER').AsString;
DM.StudentsQry.Open;

MaximG
Devart Team
Posts: 1822
Joined: Mon 06 Jul 2015 11:34

Re: Refreshing params on ORAQuery

Post by MaximG » Mon 28 Sep 2015 09:09

When updating SQL query text in the OraQuery component, the list of parameters in the query is generated automatically. So you should delete the following line from the provided code sample: DM.StudentsQry.Params.AddParam('SECTION');

jswanberg
Posts: 2
Joined: Sat 26 Sep 2015 15:34

Re: Refreshing params on ORAQuery

Post by jswanberg » Mon 28 Sep 2015 15:38

Removing that line had no effect. Still get an error of "Parameter 'SCHOOL' not found" when I hit the first line after updating the SQL.

MaximG
Devart Team
Posts: 1822
Joined: Mon 06 Jul 2015 11:34

Re: Refreshing params on ORAQuery

Post by MaximG » Tue 29 Sep 2015 07:55

Your query text misses spaces in the end of strings. Because of that the name of the :SCHOOL parameter in your case is like the following: :SCHOOLand. Add missing spaces in the end of strings of the generated query

Post Reply