Yes - I too was referring to this statement:
Query.Params.ParamByName('Pval').AsString := '%'+docName+'%';
However, I'm still using the format() - which is working - I will work on parambyname sometime later this week. Need to hack this application today.
Further, debugging the Query object - found out the actual Create and Database Connection had to be brought within the same function for it to work - running queries and the results were stuck on first queried record even on multiple loops..
Previously I had the code like this...
function getDocumentFromDB(docID: Integer): String;
begin
if AConnection.Connected then
begin
Query.SQL.Clear;
Query.SQL.Text:='SELECT DOC_ID, NAME, TYPE, DESC FROM DOCUMENTS ' +
Format('WHERE DOC_ID LIKE '%%%s%%'; [docID]);
Query.Prepare;
Query.Open;
// I had also included Query.ExecSQL; I have commented this out...
Query.First;
while not Query.EOF do
begin
Fetch some records.....
The above query always returns 1 record - since the matching doc_id has one-to-one record.
end;
// while we exit this function and return back from DBConnection - since we will fetch second document - based on the external function which parses html files.. and then reenter this function. Doing so the query will always return the previous record.
The way I fixed this is by moving Query Create and Database within this function and that seems to have fixed the results stuck at the first record.
end;
end;
Procedure DBConnection()
begin
Query := TSQLQuery.Create(nil);
Query.DataBase := AConnection;
getDocumentFromDB(documentID);
end;
I hope I was clear.
Again thanks for your continued support - really appreciate LaZarus and Freepascal - and great community so supportive