Delphi and Kylix

Moderators: pritaeas
Number of threads: 7264
Number of posts: 19073

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
2 database questions Posted by SaMo on 21 Jul 2004 at 11:06 PM
Hi all!

At the moment I am developing ADO/Access database and I want it to support multi-user environment. The problem is simple: preventing 2 users from editing the same record simultaneously. I am using file-server architecture which means that a copy of database is created on each client machine. This copy does not automatically reflect the changes in the database. Therefore, it is often the case that user tries to edit data that has been already edited (or deleted) by another user. I use Requery method to update dataset, however it works kinda strange. If I call requery method just after another user edited database, it does not return the latest changes. I've tested it and there is an interval of about 5-10 seconds between the time when user on one machine finishes editing the record and application on another is capable of "seeing" those changes. That really causes some problems. Can anything be done about that? If not then is it possible to lock a certain record in a database when a user performs some action (for instance clicks a button)?

And the second question is: how can I distinguish between different types of database errors? They all just say "EDataBaseError", but I want to have special code for each type.
Report
Re: 2 database questions Posted by zibadian on 22 Jul 2004 at 1:24 AM
: Hi all!
:
: At the moment I am developing ADO/Access database and I want it to support multi-user environment. The problem is simple: preventing 2 users from editing the same record simultaneously. I am using file-server architecture which means that a copy of database is created on each client machine. This copy does not automatically reflect the changes in the database. Therefore, it is often the case that user tries to edit data that has been already edited (or deleted) by another user. I use Requery method to update dataset, however it works kinda strange. If I call requery method just after another user edited database, it does not return the latest changes. I've tested it and there is an interval of about 5-10 seconds between the time when user on one machine finishes editing the record and application on another is capable of "seeing" those changes. That really causes some problems. Can anything be done about that? If not then is it possible to lock a certain record in a database when a user performs some action (for instance clicks a button)?
:
: And the second question is: how can I distinguish between different types of database errors? They all just say "EDataBaseError", but I want to have special code for each type.
:
I don't know the answer to your first question, but I do to the second question. You have to look to the message to distinguish the various errors. Here is a code, which shows the message to the user as an example:
  try
    // DataBase Statements
  except
    on E: EDataBaseError do
      ShowMessage(E.Message);
  end;

By parsing the message, you can distinguish between the various errors.
Report
Re: 2 database questions Posted by SaMo on 22 Jul 2004 at 1:40 AM
: I don't know the answer to your first question, but I do to the second question. You have to look to the message to distinguish the various errors. Here is a code, which shows the message to the user as an example:
:
:   try
:     // DataBase Statements
:   except
:     on E: EDataBaseError do
:       ShowMessage(E.Message);
:   end;
: 

: By parsing the message, you can distinguish between the various errors.
:
I thought about it, but isn't it so that the message returned will depend on operating system? If the program is installed on localized version of Windows (say, Swedish or Russian), will the message still be on English? If not, my code for identifying errors based on messages, won't work.
Report
Re: 2 database questions Posted by zibadian on 22 Jul 2004 at 4:12 AM
: : I don't know the answer to your first question, but I do to the second question. You have to look to the message to distinguish the various errors. Here is a code, which shows the message to the user as an example:
: :
: :   try
: :     // DataBase Statements
: :   except
: :     on E: EDataBaseError do
: :       ShowMessage(E.Message);
: :   end;
: : 

: : By parsing the message, you can distinguish between the various errors.
: :
: I thought about it, but isn't it so that the message returned will depend on operating system? If the program is installed on localized version of Windows (say, Swedish or Russian), will the message still be on English? If not, my code for identifying errors based on messages, won't work.
:
That I don't know. I think it depends if the DBE is localized. I don't have much experience with using the DBE components. In some messages I've seen a hex value or an ErrorCode field, which identifies the error type and should be the same for all languages. Here is an example I came across during a google search:
try 
  SomeCodeThatRaisesAnEConvertError; 
except  
  on E: EIBError do  begin    
    if E.ErrorCode = iSomeCodeIWantToCatch then 
    begin
      // Deal with this specific exception here
    end else 
    begin
      raise; // re-raise the exception if its not the one I handle
    end;
  end;
end;

Source: http://community.borland.com/article/0,1410,32156,0.html

But this won't work with the general EDatabaseError.
You might find more info in the manual of the DB engine you are designing your program to use.



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.