Board index » delphi » Getting exclusive acces to a Paradox table

Getting exclusive acces to a Paradox table

I asked this question a couple of days ago, but didn't get an answer. So
I'm trying again in the hope that it was overlooked the first time.

I am doing an application in D1, where the user can create new fields (and
tables). I do it by creating a new table (tblNew) with the same table
structure as the original (tblOriginal) plus the new field, then I transfer
the data via a TBatchMove, delete tblOriginal and rename tblNew. To
accomplish this I set

        tblOriginal.Exclusive := true;

So I get an exception if someone else is using the table, when I call Open
for tblOriginal. This works fine, as long as it is another program that
uses the table, I get my exception, but if my own program is using the
table, I don't get an exception until I try to delete the table, which is
very much too late.

Because of the number of tables that the user can create, I would prefer
not to have to create a list of booleans, one for every table, to keep
track of which table have been opened by my own program. So is there
another way to check if I get my Exclusive access at the time I call
tblOriginal.Open?

--
CUL8R dude!                       \|/
                                  @ @
Jens  +-----------------------oOO-(_)-OOo-----------------------+
      | Internet   jb...@image.dk     CompuServe    100437,2475 |
      | FidoNet         2:235/142     VirNet          9:451/238 |
      | OS2Net          81:445/49     Fax     +45 - 3537 - 7006 |
      +---------------------------------------------------------+

 

Re:Getting exclusive acces to a Paradox table


Quote
jb...@image.dk (Jens Bang) wrote:
>I asked this question a couple of days ago, but didn't get an answer. So
>I'm trying again in the hope that it was overlooked the first time.
>I am doing an application in D1, where the user can create new fields (and
>tables). I do it by creating a new table (tblNew) with the same table
>structure as the original (tblOriginal) plus the new field, then I transfer
>the data via a TBatchMove, delete tblOriginal and rename tblNew. To
>accomplish this I set
>        tblOriginal.Exclusive := true;
>So I get an exception if someone else is using the table, when I call Open
>for tblOriginal. This works fine, as long as it is another program that
>uses the table, I get my exception, but if my own program is using the
>table, I don't get an exception until I try to delete the table, which is
>very much too late.
>Because of the number of tables that the user can create, I would prefer
>not to have to create a list of booleans, one for every table, to keep
>track of which table have been opened by my own program. So is there
>another way to check if I get my Exclusive access at the time I call
>tblOriginal.Open?
>--
>CUL8R dude!                       \|/
>                                  @ @
>Jens  +-----------------------oOO-(_)-OOo-----------------------+
>      | Internet   jb...@image.dk     CompuServe    100437,2475 |
>      | FidoNet         2:235/142     VirNet          9:451/238 |
>      | OS2Net          81:445/49     Fax     +45 - 3537 - 7006 |
>      +---------------------------------------------------------+

why don't you try file marking, it may be the long way round, but it
is exclusive.

        {i want exclusive mode now}

        if filexists('using.lck') then
          {someone is using the db}
          MessageDlg('could not perform exclusive', mtInformation,[mbOK],0);
        else
          filecreate('file.lck'); {lock the db}
          ......
          {now you can do your stuff}

          .....
          deletefile('file.lck');
        end;

it can be messy, and you have to make sure that the 'using.lck' files
are deleted, but it may keep you going for now.......

so when your user comes in and tries to use the db

if filexists('file.lck') then
  MessageDlg('sorry, table is in exclusive mode',mtinformation,
                       [mbOK],0);
else
  filecreate('using.lck');
  .......
  {do some stuff}
  ......
  deletefile('using.lck');
end;

regards

sean
------------------------------------------------------------------------------      
:      .o        .         .           *            _____    .    :    .  .
                                 .          __..---'-----`---..._    . .
"You BROKE it!!!       .       ..     ================================
   I'm telling the Captain!"     %       .   `--..._______...---'     *   .
      .           \      _____                .         \           .    .
 ____________________ _/' ~ \_`;    .     .      "SHUT UP WESLEY!"    .
(___________________||_)   /          *.                .            .    @
     /    /  _..---'    ~~,           .        .           .:     *        .
 *  `-----`=============_/      .     .  Mr Sean Hale  A.M.I.L.E. N.E.B.S.M.
       ..     `----()__/    .                s...@darkstar.ftech.co.uk .    
   .   .        .   *      .        .:         hs...@greenwich.ac.uk      . .
   .   .    .    .    *    *   ,      . .   http://www.gre.ac.uk/~hs574 . ...
------------------------------------------------------------------------------

Re:Getting exclusive acces to a Paradox table


Would the DbiGetTableOpenCount function of the BDE help ?
This should give you the number of local cursors currently
open on the table which, in combination with the exception
created if another user has the table open, may do the
trick.

--
Robert Eccles

Other Threads