#1 2012-03-26 22:14:29

array81
Member
From: Italy
Registered: 2010-07-23
Posts: 411

FillOne bug?

Today I have used the FillOne method but I have a problem, see the code:

      CustomerRecord := TSQLInvoicesCustomers.Create(Database,'IDInvoice="%"',[IntToStr(InvoiceID)]);
      try
        while CustomerRecord.FillOne do
          begin
             ...
             ...
          end;
      finally
        CustomerRecord.Free;
      end;

Now the problem, if there are more of 1 record on CustomerRecord the code works, but if there are ONLY 1 record the code not work, I think because FillOne return False.

I think FillOne should work with 1 ore more records, right? In fact I cannot know how many records CustomerRecord can retrieve. Can you check this? Thanks.

Offline

#2 2012-03-27 09:32:21

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,660
Website

Re: FillOne bug?

1. There is no need of using IntToStr() in the open array: just put [InvoiceID].

2. You are not using the good method.
You should call CreateAndFillPrepare() constructor instead of Create() here, as stated by the documentation.

Offline

#3 2012-03-27 18:47:21

array81
Member
From: Italy
Registered: 2010-07-23
Posts: 411

Re: FillOne bug?

OK but can CreateAndFillPrepare works also with a single record without use the loop? Or I need use Create if I have a record and CreateAndFillPrepare if I have more that one record?

Offline

#4 2012-03-27 18:51:29

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,660
Website

Re: FillOne bug?

As stated by the documentation:

- Use Create + an ID or a Where clause to retrieve one record;
- Use CreateAndFillPrepare to retrieve one or more records - but you need the loop, or at list one FillOne call for a single record.

Offline

#5 2012-03-29 13:50:44

array81
Member
From: Italy
Registered: 2010-07-23
Posts: 411

Re: FillOne bug?

Is there a way to add ORDER command to CreateAndFillPrepare method? I need use CreateAndFillPrepare (to avoid a simple SQL) but I need ORDER the results, is it possible?

I have read the documentation but I cannot find a "ORDER" parameter for CreateAndFillPrepare.

Another think, when I use Create or CreateAndFillPrepare, to know if there are some result I can check "if CustomerRecord <> nil", is it right?

Thanks

Offline

#6 2012-03-29 15:52:29

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,660
Website

Re: FillOne bug?

1. Put the ORDER clause in the end of your WHERE parameter.

2. When you use Create or CreateAndFillPrepare, the record is always set.
What you can check is to check for ID<>0.

Offline

#7 2012-03-30 17:29:54

array81
Member
From: Italy
Registered: 2010-07-23
Posts: 411

Re: FillOne bug?

To get the count of the records, for example sql: "SELECT COUNT(*) FROM Projects" I need use ExecuteList or is there a "Framework" system?
Sorry for these questions but I'm check to remove all ExecuteList, when I can, from my application.

Offline

#8 2012-03-30 19:23:42

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,660
Website

Re: FillOne bug?

Use function TSQLRest.TableRowCount(Table: TSQLRecordClass): integer method.

If you have just searched for "SELECT Count(" in the documentation or the source, you would have found this one.
wink

Offline

Board footer

Powered by FluxBB