databasedelphiremobjectsanydacdataabstract

How can I update a blob field on the server


I have a client/server application built using DataAbstract and RemObjects where the client is transferring a Binary variable for the server to put in the DB. The server function looks like this

function SetItemContent(const anItemId: UnicodeString; const anItemContent: Binary): Boolean;

But I don't know hot to access the table from the server to save that binary variable in a blob. I can't find any reference in the DA documentation either.


Solution

  • You can use a TDALocalDataAdapter on the service implementation module, and hook up TDAMemDataTable. You can then use Dynamic Where (or parameterised DataTable) to find and update your record using normal TDataset techniques. (i.e. insert, edit, post)

    You should surround any update with a transaction. Use the Connection.BeginTransaction, RollbackTransaction and CommitTransaction.

    Edit ====

    You can also use a IDASQLCommand: use Connection.NewCommand method. You can either give this the SQL directly as a parameter, or (better IMHO++) provide the name of a parameterised update/insert SQL command you have created in the Schema.

    I guess that you still have to know whether to insert/update so you could use an IDADataset from Connection.NewDataset method to establish this using MyDataset.IsEmpty. Create a Dataset in the Schema first or pass SQL.

    The point about using transactions still holds for this method.

    ++ better because this allows you to better support multiple DB back-ends by using multiple statements for each datatable or command object.