Compatibity with UniDac

Compatibity with UniDac

Postby FCS » Fri 04 Aug 2017 14:24

Hello,

I'm using UniDac for years.

I consider changing IDE to VisualStudio C#. I would like to know how to implement in dotConnect Universal such code:

Code: Select all
// SQL_Query is the TUniQuery

JestTrans:=SQL_Query.Connection.InTransaction;

if not JestTrans then SQL_Query.Connection.StartTransaction;
try
  SQL_Query.Lock;

  try
    SQL_Query.Edit;

    // changing record fields ...

    SQL_Query.Post;
    if not JestTrans then SQL_Query.Connection.Commit;
  except
    SQL_Query.Cancel;
    if not JestTrans then SQL_Query.Connection.Rollback;
    msgBox('Problem with edition');
  end;

except
  if not JestTrans then SQL_Query.Connection.Rollback;
  MsgBox('Record is edited by the other user');
end;



Regards
Michal
FCS
 
Posts: 134
Joined: Sat 23 Feb 2013 18:46

Re: Compatibity with UniDac

Postby Pinturiccio » Tue 08 Aug 2017 14:47

You want to migrate from a completely different language with a different set of functions. We will try to describe separate line and their counterparts in C#:
Code: Select all
JestTrans:=SQL_Query.Connection.InTransaction;

There is no counterpart for the TUniQuery class in dotConnect Universal. We cannot say how to implement any actions with the SQL_Query object using dotConnect Universal.

Connection.InTransaction; - UniConnection class has a property InDistributedTransaction, which indicates whether a connection is used in a distributed transaction or not. There is no way to check if a connection is in a usual UniTransaction.

Code: Select all
SQL_Query.Edit;

// changing record fields ...

SQL_Query.Post;

Since dotConnect Universal doesn't have a counterpart for the TUniQuery class, you will probably need to use a combination of DataTable and UniDataAdapter or DataSet and UniDataAdapter objects.

For more information, please refer to
https://www.devart.com/dotconnect/universal/docs/?Devart.Data.Universal~Devart.Data.Universal.UniDataAdapter.html
https://www.devart.com/dotconnect/universal/docs/?Devart.Data.Universal~Devart.Data.Universal.UniCommandBuilder.html

If you have any questions about how dotConnect Universal classes work, feel free to contact us.
Pinturiccio
Devart Team
 
Posts: 1979
Joined: Wed 02 Nov 2011 09:44

Re: Compatibity with UniDac

Postby FCS » Tue 08 Aug 2017 16:32

Hello,

Thank you for the reply.

In summary I want to:
1. Start transaction.
2. Check if the record with given ID (primary key) is not edited by other user
3. Lock this record to prevent editing by other user
4. Update this record
5. If all OK, End transaction.

In more complex situation (master-detail), I want to:
1. Start transaction.
2. Check if the master record with given ID (primary key) is not edited by other user
3. Lock this record to prevent editing by other user
4. Update this record
5. Update detail records
6. If all OK, End transaction.

Could you describe how to realize this using dotConnectUniversal ?
FCS
 
Posts: 134
Joined: Sat 23 Feb 2013 18:46

Re: Compatibity with UniDac

Postby Pinturiccio » Fri 11 Aug 2017 12:10

FCS wrote:1. Start transaction.
5. If all OK, End transaction.

You can find a detailed information about how to use transactions in dotConnect Universal in our documentation:
https://www.devart.com/dotconnect/universal/docs/?UsingTransactions.html

FCS wrote:2. Check if the record with given ID (primary key) is not edited by other user
3. Lock this record to prevent editing by other user

dotConnect Universal does not provide any features to solve this issue. You can create a DataTable object to store and process data in this object. For more information, please refer to https://msdn.microsoft.com/en-us/library/system.data.datatable(v=vs.110).aspx

You can lock the DataTable objects before changing any row. In this case only one user will be able to edit the object. You can lock either the whole DataTable or a separate row. For more information, please refer to https://stackoverflow.com/questions/2607661/if-im-updating-a-datarow-do-i-lock-the-entire-datatable-or-just-the-datarow
https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/lock-statement

FCS wrote:4. Update this record

For loading data in a DataTable object and then updating it you can use UniDataAdapter class. For more information, please refer to
https://www.devart.com/dotconnect/universal/docs/?Devart.Data.Universal~Devart.Data.Universal.UniDataAdapter.html
https://www.devart.com/dotconnect/universal/docs/?Devart.Data.Universal~Devart.Data.Universal.UniCommandBuilder.html

FCS wrote:In more complex situation (master-detail)

dotConnect Universal does not provide features for master-details tables. You should process this situation yourself and update a detail record after updating the master record.
Pinturiccio
Devart Team
 
Posts: 1979
Joined: Wed 02 Nov 2011 09:44

Re: Compatibity with UniDac

Postby FCS » Sun 13 Aug 2017 17:45

Hello,

Thank you for reply and information.

Regards
Michal
FCS
 
Posts: 134
Joined: Sat 23 Feb 2013 18:46


Return to dotConnect Universal