ZEOS subsequent queries: RecordCount > 1, but I only got 1 row lazarus / 16-Databases ---------------------------------------------------------------------- Leledumbo · 2010-12-31 06:54 This code below (after "ambil daftar restoran" comment), have RecordCount > 1 but the while loop terminates after one iteration: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   FDaftarBahan := TDaftarBahan.Create;  FDaftarRestoran := TDaftarRestoran.Create(true);  if Self.NameExists(ANama) then begin  DBQuery.SQL.Text := 'SELECT id FROM masakan WHERE nama = :nama LIMIT 1';    DBQuery.Params.ParamByName('nama').AsString := ANama;    DBQuery.Open;    FID := DBQuery.FieldByName('id').AsInteger;    // ambil daftar bahan    DBQuery.SQL.Text := 'SELECT b.nama AS nama,mb.frekuensi AS frekuensi FROM bahan b ' +      'INNER JOIN masakan_bahan mb ON b.id = mb.id_bahan ' +      'AND mb.id_masakan = :id ORDER BY mb.frekuensi DESC';    DBQuery.Params.ParamByName('id').AsInteger := FID;    DBQuery.Open;  while not DBQuery.EOF do begin      FDaftarBahan[DBQuery.FieldByName('nama').AsString]        := DBQuery.FieldByName('frekuensi').AsInteger;      DBQuery.Next;    end;    // ambil daftar restoran    DBQuery.SQL.Text := 'SELECT r.nama AS nama,r.lintang AS lintang,r.bujur AS bujur ' +      'FROM restoran r INNER JOIN restoran_masakan rm ON r.id = rm.id_restoran ' +      'AND rm.id_masakan = :id ORDER BY r.nama DESC';    DBQuery.Params.ParamByName('id').AsInteger := FID;    DBQuery.Open;  AppendLog(IntToStr(DBQuery.RecordCount));    while not DBQuery.EOF do begin      FDaftarRestoran.Add(TRestoran.Create(        DBQuery.FieldByName('nama').AsString,        DBQuery.FieldByName('lintang').AsFloat,        DBQuery.FieldByName('bujur').AsFloat      ));      DBQuery.Next;    end;  end else begin    DBQuery.SQL.Text := 'INSERT INTO masakan (nama) VALUES (:nama)';    DBQuery.Params.ParamByName('nama').AsString := ANama;    DBQuery.ExecSQL;    FID := Self.LastInsertID;  end;  FNama := ANama; Can anyone help me? Is it unallowed to use one TZQuery instance shared along the program? FYI, the query has been tested manually outside the program and indeed it returns more than one record. ---------------------------------------------------------------------- Leledumbo · 2010-12-31 07:42 Sorry, my bad. I forgot that my model's constructor also does query WITH THE SAME TZQuery object. I see that I must redesign my app. I didn't implement the ORM correctly. ---------------------------------------------------------------------- SteveF · 2011-01-04 16:10 PMFJI, and for a bit of "thread shift", but would you please confirm that you're using a TZquery with your code? Also, is the component part of a DataModule, or is it placed directly on your form? TIA, Steve ---------------------------------------------------------------------- Leledumbo · 2011-01-04 17:18 Quotebut would you please confirm that you're using a TZquery with your code?Yes, I am. QuoteAlso, is the component part of a DataModule, or is it placed directly on your form?It's hand coded, somehow I've got errors when the component is dropped on the web module (maybe I didn't use it correctly). ---------------------------------------------------------------------- SteveF · 2011-01-04 18:11 Sorry, I guess i wasn't specific enough: For a non-web project, would the code you used work if the TZquery was part of a DataModule, or does this code require the TZquery to be included in the form/module that actually has the code that's working with the TZquery? If the TZquery is NOT part of a DataModule, what changes to the code would be needed to work with a TZquery that is in a DataModule? Thanks, Steve ---------------------------------------------------------------------- Leledumbo · 2011-01-05 01:21 Quotewould the code you used work if the TZquery was part of a DataModule, or does this code require the TZquery to be included in the form/module that actually has the code that's working with the TZquery?It should work in both cases, TZQuery has no dependency on any form / module. QuoteIf the TZquery is NOT part of a DataModule, what changes to the code would be needed to work with a TZquery that is in a DataModule?Nothing, except you have to create, initialize and free the instance yourself.