简体   繁体   中英

How to get select results using zeoslib

I am working on a project with mysql, and for this I am doing a class using zeoslib, I can make the connection, I can execute querys like insert, update, etc. But my problem is with select, I run it quietly, but how would I do to get the return? I would like something like PHP in that I inform the column name and it returns me the value of the row that is in that column.

It's important what you want to select, here is an example that uses TZQuery to get an integer value;

function TAccess.getProgramNo(aProgramName:WideString):Integer;
 var
  q:TZQuery;
begin
  Result := -1;
  q := TZQuery.Create(Self);
  try
      q.Connection := conn;
      q.SQL.Text := ' SELECT progno FROM programs WHERE name = :name ORDER BY progno ASC ';
      q.ParamByName('name').Value := aProgramName;
      q.Open;
      if q.RecordCount > 0 then
        Result := q.FieldByName('progno').AsInteger;
  finally
    q.Free();
  end;
end;

If you want to return a list of objects (i did not compile this);

function TAccess.getPrograms(aProgramName:WideString):TList;
 var
  q:TZQuery;
begin
  Result := TList.Create;
  q := TZQuery.Create(Self);
  try
      q.Connection := conn;
      q.SQL.Text := ' SELECT progno FROM programs WHERE name = :name ORDER BY progno ASC ';
      q.ParamByName('name').Value := aProgramName;
      q.Open;
      While not q.EOF do
        begin
          result.Add(TZoo.Create(....));
          q.Next;
        end;
  finally
    q.Free();
  end;
end;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM