universeu2u2netdk

UniObjects - Write vs WriteField Difference?


Can someone please explain the difference in the following:

string RecordID = "123456";
string AttribNum = "120";
UniFile myUniFile = myUniSession.CreateUniFile("myFileName");

UniDynArray uda = myUniFile.Read(RecordID);
uda.Replace(AttribNum, "New Value");
myUniFile.Write();

and this:

string RecordID = "123456";
string AttribNum = "120";
UniFile myUniFile = myUniSession.CreateUniFile("myFileName");

UniDynArray uda = new UniDynArray(myUniSession, "New Value");
myUniFile.WriteField(RecordID, AttribNum, uda);

Both will set attribute 120 of record "123456" to the string "New Value". Is it just a matter of writing just one attribute of a record vs writing the entire record? Is one better than the other when needing to update a single attribute?

Thanks!


Solution

  • In the first example you are fetching an entire record from the server to the client. Once on the client's side of the wire you replace attribute 20 with your value then write the entire record down to the server.

    Read(Server)
       -> Send(Server-Client)
          -> Change Record(Client)
             -> Send(Client-Server)
                -> Write(Server)
    

    In the second example you are instructing the server to read the entire record, update attribute 20 and then write the entire record. All this happens on the server's side of the wire.

    Read(Server)
       -> Change Record(Server)
          -> Write(Server)
    

    If you are updating a single attribute and don't need the record on the client the later definitely will perform better. The former can be better if 1) you need to record client-side and/or 2) You need to update multiple attributes and want to avoid multiple DB writes.