Dear Sir;
Could you help me to append records form an internal DB to an external file?
Regards;
AHMED
-
- VIP Member
- Posts: 105
- Joined: 28 Apr 2006 12:03
-
- Active Member
- Posts: 37
- Joined: 15 Sep 2009 14:06
-
- VIP Member
- Posts: 1466
- Joined: 28 Feb 2000 0:01
-
- VIP Member
- Posts: 105
- Joined: 28 Apr 2006 12:03
hi maybe something like this, depends on which version of prolog you use,
Code: Select all
append_to_file():-
Fn2 = "dbtextfile.txt"
file5x::closefile(fileSelector::gg()),
trap(file5x::openappend(fileSelector::gg(),Fn2),_,fail),
file5x::writedevice(fileSelector::gg()),
record(A,B),
file5x::write(A2,"\n"),
fail.
append_to_file():-
file5x::closefile(fileSelector::gg()),
file5x::writedevice(fileSelector::stdout()),
-
- Active Member
- Posts: 37
- Joined: 15 Sep 2009 14:06
-
- VIP Member
- Posts: 1466
- Joined: 28 Feb 2000 0:01
You should not (= absolutely not at all) use file5x, it is only intended to be used when migrating old Vip5.2 code.
The code corresponds to this "up-to-date" code:
The code still contains the same bugs
(variable A2 is unbound).
If you want to try something like this you will have to write all facts, and also their functors (and a terminating dot):
The code corresponds to this "up-to-date" code:
Code: Select all
append_to_file() :-
Fn2 = "dbtextfile.txt",
OS = outputStream_file::append(Fn2),
foreach record(A, B) do
OSwrite(A2, "\n")
end foreach,
OS:close().

If you want to try something like this you will have to write all facts, and also their functors (and a terminating dot):
Code: Select all
append_to_file() :-
Fn2 = "dbtextfile.txt",
OS = outputStream_file::append(Fn2),
foreach record(A, B) do
OS:write("%.\n", record(A, B))
end foreach,
foreach anotherFact(A, B, C, D) do
OS:write("%.\n", anotherFact(A, B, C, D))
end foreach,
% continue for all facts
OS:close().
Regards Thomas Linder Puls
PDC
PDC