[2.5b] DBSERVER:Zap

This forum is meant for questions and discussions about the X# language and tools
Post Reply
FFF
Posts: 1521
Joined: Fri Sep 25, 2015 4:52 pm
Location: Germany

[2.5b] DBSERVER:Zap

Post 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...;)
Regards
Karl
(on Win8.1/64, Xide32 2.19, X#2.19.0.2.)
User avatar
Chris
Posts: 4562
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

[2.5b] DBSERVER:Zap

Post by Chris »

Hi Karl,

Maybe the dbf is opened in shared mode? Zap and Pack can only work in exclusive mode.
Chris Pyrgas

XSharp Development Team test
chris(at)xsharp.eu
User avatar
robert
Posts: 4225
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

[2.5b] DBSERVER:Zap

Post 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
XSharp Development Team
The Netherlands
robert@xsharp.eu
FFF
Posts: 1521
Joined: Fri Sep 25, 2015 4:52 pm
Location: Germany

[2.5b] DBSERVER:Zap

Post 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.
Regards
Karl
(on Win8.1/64, Xide32 2.19, X#2.19.0.2.)
User avatar
Chris
Posts: 4562
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

[2.5b] DBSERVER:Zap

Post 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.
Chris Pyrgas

XSharp Development Team test
chris(at)xsharp.eu
FFF
Posts: 1521
Joined: Fri Sep 25, 2015 4:52 pm
Location: Germany

[2.5b] DBSERVER:Zap

Post 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?
Regards
Karl
(on Win8.1/64, Xide32 2.19, X#2.19.0.2.)
User avatar
Chris
Posts: 4562
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

[2.5b] DBSERVER:Zap

Post 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 :)
Chris Pyrgas

XSharp Development Team test
chris(at)xsharp.eu
Post Reply