json查询

json查询

procedure TFunc1549.select(req, res: TSerialize);
var
  db: tdb;
  pool: tdbpool;
  jo: variant;
begin
  try
    try
      pool := GetDBPool('1');
      db := pool.Lock;
      db.qry.Close;
      db.qry.SQL.Clear;
      db.qry.SQL.Text := 'select * from tunit';
      db.qry.Open;
      TDocVariant.New(jo);
      jo.status := 200;
      jo.message := 'success';
      jo.tunits := _json(db.qry.ToJSONArrayString);
      res.asStr['res'] := VariantSaveJSON(jo);
    except
      on E: Exception do
      begin
        jo.status := 500;
        jo.message := 'fail';
        jo.exception := E.Message;
        res.asStr['res'] := VariantSaveJSON(jo);
      end;
    end;
  finally
    pool.Unlock(db);
  end;
end;                 

 

posted @ 2023-02-14 18:11  delphi中间件  阅读(105)  评论(0编辑  收藏  举报