Page 1 of 1
[2.5b] DBSERVER:Zap
Posted: Thu Sep 17, 2020 8:01 am
by FFF
Guys,
anyone succeeded using Zap() on a table?
Simple dbServer,
Code: Select all
METHOD kill() AS LOGIC
LOCAL oD AS Schicht
oD:=Schicht{}
oD:Flock()
oD:Zap()
oD:Commit()
RETURN
Compiles, runs - and does nothing.
OK, changed my method call to:
Code: Select all
METHOD kill() AS LOGIC
USE "D:MiscTuKVN_VersionDATASchicht.dbf" EXCLUSIVE NEW
IF !NetErr()
// SET INDEX TO sales, branch, salesman
IF DbZap()
? "Zapped OK"
ELSE
? "Error detected during ZAP"
ENDIF
CLOSE "D:MiscTuKVN_VersionDATASchicht.dbf"
ELSE
? "Error detected when opening the file"
ENDIF
RETURN
using the sample from X# helpfile.
Compiling, i get:
error XS9002: Parser: unexpected input '->' 772,3 _Tom_Shell.prg TomShellWindow:kill
Line 772 is the "close" call.
I'm totally blank on using "commands", but i doubt, this should be as is.
PS, looking into Helfp for DBServer, it seems, in the description part quite some line breaks where lost...
[2.5b] DBSERVER:Zap
Posted: Thu Sep 17, 2020 8:30 am
by Chris
Hi Karl,
Maybe the dbf is opened in shared mode? Zap and Pack can only work in exclusive mode.
[2.5b] DBSERVER:Zap
Posted: Thu Sep 17, 2020 8:38 am
by robert
Karl,
What Chris said.
And if you want to help format the documentation, please let me know.
It's all in source code format (XML).:
https://github.com/X-Sharp/XSharpPublic ... lasses.xml
It's probably enough to add some breaks (<br />) at the right locations.
Robert
[2.5b] DBSERVER:Zap
Posted: Thu Sep 17, 2020 9:08 am
by FFF
Chris wrote:Maybe the dbf is opened in shared mode? Zap and Pack can only work in exclusive mode.
That i thought, too. But then, why doesn't FLock fail? I wrapped it into an If clause, debugged, Flock succeeds, stepping to the zap line i get an XSharp.RDD.RddError (no further information given). Added a SetExclusive(true) in front, which returned "False", so yes, whithout this it shouldn't work, but AFAIU the docs, Flock should correct that or return false, which it does not.
FTM i simply deleted the file and exported anew from Editor, but it feels strange.
[2.5b] DBSERVER:Zap
Posted: Thu Sep 17, 2020 9:40 am
by Chris
Hi Karl,
And FLock() will succeed, and it will work for updating single records, but this is not enough for Zap and Pack, those require the files to be opened in exclusive mode. Please try it also in VO, you will see that also in it exclusive is a requirement, an flock is not enough.
Btw, it is not necessary to use SetExclusive(), because this will affect opening of all files. You can instead open the file with the appropriate parameter when you instantiate the dbserver. For a simple DBServer class (not a subclass), you'd do something like
DBServer{<filename>,FALSE}
Also SetExclusive() returns the _previous_ state of the setting (so you can easily save it and restore it later) when you change it, this is why it returned FALSE in your case, because this is the default setting.
[2.5b] DBSERVER:Zap
Posted: Thu Sep 17, 2020 9:45 am
by FFF
Chris wrote:
Also SetExclusive() returns the _previous_ state of the setting (so you can easily save it and restore it later) when you change it, this is why it returned FALSE in your case, because this is the default setting.
That i grokked
- but nevertheless, even with the SetExclusive(true), the Zap fails. Why?
As for Flock is not enough, under Function SetExclusive the help says:
...Use this only for operations that absolutely require exclusive use of a database file, such as PACK, REINDEX, and ZAP. ...
You can control access programmatically using RLock() and FLock(). SetExclusive() is a compatibility function and not recommended...
A bit mislieading, is it not?
[2.5b] DBSERVER:Zap
Posted: Thu Sep 17, 2020 9:56 am
by Chris
Hi Karl,
Not sure, it seems to work fine here. Maybe there's something about this dbf, can you try with others? Or maybe when you instantiate the (dbserver descedant) Schicht class, this actually opens the file always in shared mode, ignoring the SetExclusive() setting? Please check the constructor of this class, it should be obvious what it is doing.
Yeah, I agree this documentation in SetExclusive() is bad. You need to blame the team that wrote the VO documentation for that