[V4RB] The Open/Close trick Lives!

Keith DeLong delong at redcort.com
Fri Feb 14 09:31:28 CST 2003


After months of pondering and 3 focused days of testing and investigation, I
have a solution for basic shared data file access under OS X

The Situation
Pseudo multi-user access to Valentina files was pretty easily achieved by
opening and closing the data file between uses. Under OS 9 and Windows,
doing a db.open(f) will throw an error if the data file is already open.
Using a timer to attempt opens until successful proved quite stable and
robust.

The problem
OS X will does not grant exclusive file access
(http://developer.apple.com/technotes/tn/tn2037.html). This means that any
Valentina data residing on OS X will open happily without an error even if
someone else has already opened and is using it. The result is the dreaded
-61 error as well as data corruption and a host of other complications.

The solution!
Valentina will open, access and write to baseobjects as well as select
cursors even when someone else is using the data file. The key was to find a
reliable way to test a db on OS X for write access before giving the open db
object back to the program for use.

I've discovered that that Valentina reliably throws the -61 error
(permissions violation) when trying to select multiple tables. I suspect
this has something to do with accessing the index file.

Thus, with a little overhead for a quick select from a small table, we can
now test for both a successful Open AND the ability to have write access --
meaning no one else is using the data file.

One last note: the -61 error reveals itself as db.errnumber.  Db.errstring
is blank. This makes the the errstring an unreliable test for an error.

Example:

Function OpenDB(dbFolderItem) as vDatabase
 if MyDatabase.open(dbFolderItem) then
   //test for full write access - dummy select 2 tables test for -61 error
   c = MyDatabase.sqlselect("SELECT TaskName,DefTask FROM Tasks,Settings" )
   if Mydatabase.errNumber = 0 then
      return MyDatabase //success ...
   else
      c = nil
   end
 end
END

If the open fails, show a 'file busy' dialog with a timer that repeats the
loop until a successful open or a Cancel from the user.

Ruslan,
Perhaps on the backend you could use whatever is causing this -61 error to
test a db.open. In this way a more elegant test and Open error could be
thrown natively by Valentina under OSX.

I hope this helps someone else,

Keith DeLong










More information about the Valentina mailing list