Anonymous User
  Saturday, 09 May 2020
  8 Replies
  2.4K Visits
  Subscribe
sgcWSPClient_Dataset subscribe_all only seems to be subscribing to delete.
sgcWSPClient_Dataset AKUtoSubscribe only subscribes to delete.

Use case: I'm wanting to have multiple people editing a single database table and when open person makes a change I want the others to see it reflected in the other u sers DBGrid. The server runs with FDCOnnection, FDTable and sgcWebSocketServer and sgcWSPServer_Dataset. The Clients are using sgcWebSocketCLient and sgcWSPClient_Dataset with FDConnection, FDTable TDatasource and DBGrid.

Delphi Rio 3
Laters sgcWebSockets
SQLLite

I'm also having strange behavior with SQLLite autoid getting errors in sgcWSPClient_Dataset.
4 years ago
·
#354
Hi,

Let me some time to do a sample and test this behaviour, maybe there is something wrong in dataset notify events. I will tell you the result of my tests.

Kind regards,
Sergio
4 years ago
·
#355
Hi,

I've built a simple server / client project for SQLLite database, this project has 2 folders: Server and Client. Is a simple form with a dbgrid which shows one table. Server and client have their own sqllite databases, so in order to test several clients, you must create every client in a different folder (because I search on the same folder where is the application, the database).

Inside bin folder, I put compiled server and 2 clients to do tests. Just start server first, and then start 2 clients (don't start the same client from same folder twice because you will get an exception trying to update).
If I change something in any client, example: if I modify the field Seniority, this change is sent to server and then server broadcast to all clients. I've modified this field, delete and create a new record.

sqllite.png

Please, download this project from this url and tell me if works for you.

http://www.esegece.com/download/samples/sgcSQLLite.zip

I am using SQLLite database provided with samples from embarcadero, most probably your database is more complex so maybe we can find why is not working.

Kind regards,
Sergio
Attachments (1)
4 years ago
·
#356
Thank you Sergio. The demo does in fact update all screens properly, however, I noticed you are referencing 2 separate databases. Server and Client DB's. In my test I was having all clients reference the servers instance of the DB via Firedac connections. We only want 1 DB right? So this may be a case of my lack of understanding of what the components can achieve.. Why the 2 separate DB's? In your demo, the databases do stay in sync. But, in a live scenario, I would want only one DB with clients being updated after the post event on the server I would think. Is this a case of my misunderstanding what the components are capable of doing?

Thanks again for your attention.

-Scott
4 years ago
·
#357
Hi Scott,

Dataset protocol usually is used to replicate a server database in several clients, example: a typical usage is a quote server, where server has stock quotes and distributes price updates over all connected clients.
If I understand, you want that client to be notified every time there is a change in a table, isn't it? Although this dataset protocol was not designed for it, maybe I can implement something, let me analyze the code and I will let you know the result of my analysis.
Thanks for the feedback.

Kind regards,
Sergio
4 years ago
·
#358
Thanks again for the attention. Please allow me to explain. I want to stress I am no expert at push notifications or client update notifications. I'm not even sure what the proper term is that I am asking for. But In the world of Client interfaces there is a huge hole in notification updates capabilities. I threw a very ugly timer based update option together to get by. However, I'm fixing to change my app.to uniGUI.

uniGUI is a server-side Delphi web based framework (you may know all of this) which lacks notification events that exist in products like Django, which is inherent to their data model. With Django you simply subscribe data fields to be updated upon notification (this is a bit of an oversimplification). So with uniGUI I was going to migrate my solution to a web based app. Accessing a webSocketServer from a webSocketclient works well under uniGUI. The dataset components would be a perfect fit and since uniGUI segregates Clients from Servers and would probably work. That's where I was headed with my future endeavor. If that's the case, it would be a very big deal for people that write web apps because notifications are non-existent without writing workarounds that are not inherent to the dataset models.

But now that you have filled me in on the original intent of the dataset components, I have a better understanding of what they are designed for and why I was running in to problems. They work perfectly for database-to-database updates with screen updates.

I would say that you working on this would fill a need but honestly I'm not sure of the payback. Unless you are just up for a challenge :-)

-Scott
4 years ago
·
#359
Hi,

I've added a new value to UpdateMode property of dataset protocol, "upRefreshAll", if selected, instead of update dataset, it refreshes every time there is a change.
You can download latest beta from your account which includes this update. I've added a demo folder and inside Demos/SQLLite/SingleDatabase, you can find an example of usage (client and server share the same database).

Kind regards,
Sergio
4 years ago
·
#360
Everything seems to be working! It subscribes all 3 (add, update and delete). All clients update properly. I'm not sure but I don't believe there is a way to prevent the cursor moving to the effected row. If User 1 is entering data and user 2 updates a row, the cursor moves to the effected row throwing off the location of User 1. Question: How can I tell if a client has received a add/update/delete broadcast and which of the messages it recieved? I added memo lines to the event notifications of the client_dataset but I can't see the inbound notifications. Is there a way?

I'm asking because my next step is UniGUI. I believe the client grids won't auto-update. I believe the boradcasted message will be received but the nature of Web interfaces means I may have to refresh to get the update. I will have to do it manually based on the received event.

-Scott
4 years ago
·
#361
Hi,

You can use the OnBeforeDatasetUpdate to know which record is updating:


procedure OnBeforeDatasetUpdate(Connection: TsgcWSConnection; const JSON: IsgcObjectJSON; var Handled: Boolean);
begin
ShowMessage(JSON.JSONObject.Text);
end;


Just decode JSON message to get record data.


{
"method": "sgc@dataset",
"channel": "sgc@dataset@update",
"updatemode": "upRefreshAll",
"dataset_name": "FDTable1",
"dataset_recno": 2,
"dataset_encode_base64": false,
"dataset": {
"ID": 2,
"Name": "Robert White",
"Department": "Sales",
"Seniority": 2
}
}


Kind regards,
Sergio
  • Page :
  • 1
There are no replies made for this post yet.
Submit Your Response
Upload files or images for this discussion by clicking on the upload button below.
Supported: gif,jpg,png,jpeg,zip,rar,pdf
· Insert · Remove
  Upload Files (Maximum 10MB)