mormot2 json操作

delphi中间件發表於2024-08-20

mormot2 json操作

procedure Tcrud.select;
var
  db: Tdb;
  pool: Tdbpool;
  jo: Tdocvariantdata;
  i: integer;
begin
  jo.init;
  try
    try
      pool := GetDBPool(DBID);
      db := pool.Lock;
      for i := 0 to high(sqls) do
      begin
        DB.select(sqls[i]);
        jo.AddItem(_json(DB.qry.tojsonarraystring));
      end;
      ctxt.SetOutJson(jo.ToJson);
    except
      on E: Exception do
      begin
        ctxt.SetOutJson(error(E.Message));
        WriteLog('db.tables.crud.select()' + E.Message);
      end;
    end;
  finally
    pool.Unlock(db);
  end;
end;                  

  

procedure Tcrud.select;
var
  db: Tdb;
  pool: Tdbpool;
  jo: variant;
  i: integer;
begin
  Tdocvariant.NewFast(jo);
  try
    try
      pool := GetDBPool(DBID);
      db := pool.Lock;
      for i := 0 to high(sqls) do
      begin
        DB.select(sqls[i]);
        jo.r := _json(DB.qry.tojsonarraystring);//dataset-->json
      end;
      ctxt.SetOutJson(variantsavejson(jo));
    except
      on E: Exception do
      begin
        ctxt.SetOutJson(error(E.Message));
        WriteLog('db.tables.crud.select()' + E.Message);
      end;
    end;
  finally
    pool.Unlock(db);
  end;
end;                            

  

相關文章