Page 1 of 2

Random access file

Posted: Mon Jan 06, 2025 12:53 pm
by pieffe67
good morning everyone: can you indicate examples of random or direct access files in SuperBasic? routine that they write them and then read them? Thank you.

Re: Random access file

Posted: Mon Jan 06, 2025 2:23 pm
by dilwyn
Just to clarify a little: do you mean article which explain random access files in general, or specifically how to handle random access files from SuperBASIC on a QL, for example?

Reason I ask, "vanilla" SuperBASIC has no real commands to move the file pointer around within the file until you add Toolkit 2 to get commands like BGET, BPUT, FPOS, GET, PUT... (although, that said, read Simon Goodwin's ROM bugs articles and see that there are undocumented and obscure ways of doing this because of lax parameter checking in some SuperBASIC commands, but they might only work on one or two ROM versions of course)

I'll have a look if I have any relevant articles on my site and if not try to see what it would take to write one.

The only one which sprang instantly to mind is this one: https://dilwyn.theqlforum.com/docs/articles/rafiles.zip (it's a zipped Quill _doc file). It's one I wrote for QL Today magazine many years ago and I don't really remember what it contains or whether it's beginner level or more advanced. If you can't use the zipped QL _doc, let me know, I'll do a PDF of it instead.

If it doesn't quite provide what you wanted, I'd also suggest reading Toolkit 2 manual and floppy disc system manuals once you know which commands to look for - some manuals like the CST QDisc interface manuals do document the random access commands, but don't go into great detail about HOW to use them.

Maybe if you have a read of that article I linked to first, see where it leaves you, then I could see what else I can come up with. It's not a particularly difficult subject, but like a lot of things when they're new to you it takes a bit of getting used to.

EDIT: I've just had a look at the rafiles_doc in the zip and it contains some markup text instructions for when the publisher was laying out the article - those comments are marked with tripple-dollar $$$markers, so please ignore anything said in those comments!

Re: Random access file

Posted: Mon Jan 06, 2025 3:18 pm
by dilwyn
I ended up biting the bullet on this one and after spotting a few typos and spelling mistakes in the article (e.g. "fileds" instead of "fields"), I corrected those in the Quill doc and also made a PDF for anyone who'd prefer one to a QL doc file. Not looked back in QL Today to check, I wonder if those typos got published in QL Today in the end, or did they get picked up on at the proof reading stage?

Updated version at https://dilwyn.theqlforum.com/docs/articles/index.html

Hope someone finds it useful.
Random Access Files article
Random Access Files article
rafiles.jpg (6.55 KiB) Viewed 826 times

Re: Random access file

Posted: Mon Jan 06, 2025 3:54 pm
by RalfR
dilwyn wrote: Mon Jan 06, 2025 3:18 pmHope someone finds it useful.
Yes, as usual :) .

Re: Random access file

Posted: Mon Jan 06, 2025 4:29 pm
by dilwyn
Thank you Ralf.
I'm sure I'll kick myself when you explain, but what is the significance of the 4E75 7000 in your signature? Looks like it has the letters "Nup", but...

Re: Random access file

Posted: Mon Jan 06, 2025 4:42 pm
by RalfR
dilwyn wrote: Mon Jan 06, 2025 4:29 pmbut what is the significance of the 4E75 7000 in your signature? Looks like it has the letters "Nup", but...
MOVEQ#0,D0
RTS

Best way to exit :D

(was swapped... :o )

Re: Random access file

Posted: Mon Jan 06, 2025 4:54 pm
by dilwyn
<Dilwyn kicks himself>
Should have realised!

Re: File di accesso casuale

Posted: Mon Jan 06, 2025 9:14 pm
by pieffe67
Thanks, great, I'll read the pdf. I wanted to get btree indexing in SuperBasic + Minerva toolkit...Make a simple phone book file, search friends and relatives even approximately.

Re: Random access file

Posted: Tue Jan 07, 2025 7:08 am
by Derek_Stewart
Hi,

I think you want the DBAS database extensions for the QL, which add database functionality to QDOS/SMSQ/E at assembler and Superbasic level.

This extension, is one of the best and underused facilities for the QL.

A database manager like Archive can be written in BASIC and compiled with Qliberator, C, Assembler, giving the programme faster data access and mutli-tasking abilities.

Please find DBAS in the QL Homepage: https://dilwyn.theqlforum.com/database/index.html

Re: Random access file

Posted: Tue Jan 07, 2025 8:16 am
by martyn_hill
Hi Dilwyn!
dilwyn wrote: Mon Jan 06, 2025 3:18 pm I ended up biting the bullet on this one and after spotting a few typos and spelling mistakes in the article ...
Updated version at https://dilwyn.theqlforum.com/docs/articles/index.html

A very clear article - thank you!

May I offer a couple of suggestions for your next version?

1. On page 5, a tiny, cosmetic typo - you end with:

Code: Select all

"...and we can store the whole lot in an array called entry$:
DIM array$(9,120)"
- I guess you meant "DIM entry$ ..."

2. On (middle of) page 10, you mention:

Code: Select all

"If one program has a channel opened to the file with OPEN, no other program can do so, but other programs may be able to OPEN_IN a channel to that file to input something if really necessary..."
- Actually, for as long as the file is still open in exclusive mode (either with OPEN_NEW, OPEN_OVER or just OPEN), any subsequent attempt to open for reading (shared mode - OPEN_IN), will result in an "in use" error. Same would apply if you attempt to open exclusively a file still open in shared mode - this time the exclusive open call would fail with the error. It's a QDOS limitation in that the entire file is locked in exclusive mode, rather than just at the record or field level. I can't recall whether the excellent DBAS extensions offer a more granular exclusive-lock facility over plain QDOS files...

3. (Just a thought...) It might be wise to call-out the need to CLOSE any file opened (in any of the exclusive modes) after any data is changed - in order to persist those changes and before any attempt to re-open in shared mode is made.

Thanks again, Dilwyn for your generous knowledge sharing!

M.