Notification on MySQL

Please discuss general Delphi programming topics here.

Notification on MySQL

Postby Kambiz » December 2nd, 2007, 1:00 am

I have to write a stupid application that uses a remote MySQL as database. Each instance of this application needs to be notified about changes made by other instances on the database in real time.

Whether I need a middle ware application to manage notifications, or is there an easier solution?

Thank you.
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2421
Joined: March 7th, 2003, 7:10 pm

Postby sepehr » December 7th, 2007, 5:12 pm

if you use transactions you don't need to notify other clients about changes,
search for transactions in mysql ;)

Ps:don't call my favorite database stupid man ;)
User avatar
sepehr
Active Member
Active Member
 
Posts: 23
Joined: October 4th, 2006, 6:38 am
Location: Karaj

Postby Kambiz » December 7th, 2007, 7:52 pm

I don't use transaction because I don't need it. Using transactions makes the database operations slower.

As solution, I used a pair of MultiCast TCP server and client in my application to notify other instances when something critical has been changed.

By the way, I called my application stupid, not MySQL.
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2421
Joined: March 7th, 2003, 7:10 pm

Postby john123 » December 8th, 2007, 4:58 am

second solution is,
(Windows Messaging)
,
& third solution is (Creating Shared Memory),{CreateFileMapping &...}
john123
Active Member
Active Member
 
Posts: 15
Joined: November 7th, 2007, 10:43 am

Postby Kambiz » December 8th, 2007, 8:35 am

Do mapped files and Windows messages work across network? :-k
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2421
Joined: March 7th, 2003, 7:10 pm

Postby john123 » December 8th, 2007, 10:07 am

No,
these don't work across network. [-X
these are for system wide communicate on a single computer between Applications.
for across network,
I think your solution is good.
what is your problem with your solution?
john123
Active Member
Active Member
 
Posts: 15
Joined: November 7th, 2007, 10:43 am

Postby Kambiz » December 8th, 2007, 8:03 pm

Actually nothing! :)

Just wanted to prevent doing something which could be already available as built-in.
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2421
Joined: March 7th, 2003, 7:10 pm

Postby sepehr » December 9th, 2007, 3:01 pm

Kambiz wrote:I don't use transaction because I don't need it. Using transactions makes the database operations slower.

As solution, I used a pair of MultiCast TCP server and client in my application to notify other instances when something critical has been changed.
.

hmm,would it be much faster to worth using? if so would you share more light on it ;)
User avatar
sepehr
Active Member
Active Member
 
Posts: 23
Joined: October 4th, 2006, 6:38 am
Location: Karaj

Postby Kambiz » December 10th, 2007, 5:20 am

When each instance of my program does a database operation, it broadcasts a message across the network with the following information:
  • Table Name (actually ID)
  • Operation which can be either Insert, Update, or Delete
  • Record ID
When an instance receives this kind of message (even the message owner) it broadcasts it as a Windows message to all the open forms. Eventually, each form processes the Windows message to update its current state.

As I already said, I use MultiCast protocol (Indy implementation) to broadcast the message. But notice that MultiCast does not work on a machine without network connection (a socket error occurs).

Here is the actual code in my application:

Code: Select all
// broadcast the message to the application's forms
procedure TDM.LocalBroadcast(const Message: TMessage);
var
  I: Integer;
begin
  for I := 0 to Screen.FormCount - 1 do
    with Screen.Forms[I] do
      if HandleAllocated then
        PostMessage(Handle, Message.Msg, Message.WParam, Message.LParam);
end;

// broadcasts the message accross the network
procedure TDM.NetworkBroadcast(const Message: TMessage);
begin
  if MultiCastServer.Active then { are we connected to a network? }
    MultiCastServer.SendBuffer(Message, SizeOf(Message))
  else
    LocalBroadcast(Message);
end;

// dispatch meesages received from network to the application's forms
procedure TDM.MultiCastClientIPMCastRead(Sender: TObject; AData: TStream;
  ABinding: TIdSocketHandle);
var
  Message: TMessage;
begin
  AData.Position := 0;
  while AData.Read(Message, SizeOf(Message)) = SizeOf(Message) do
    LocalBroadcast(Message);
end;
Attachments
MultiCast.zip
A simple MultiCast demo
(226.46 KiB) Downloaded 121 times
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2421
Joined: March 7th, 2003, 7:10 pm


Return to Delphi Programming

Who is online

Users browsing this forum: Bing [Bot] and 1 guest

cron