LB Booster
General >> General Board >> RANDOM ACCESS LIBRARY?
http://lbb.conforums.com/index.cgi?board=general&action=display&num=1445338105

RANDOM ACCESS LIBRARY?
Post by joker on Oct 20th, 2015, 10:48am

Being new to LBB and LB, but not new to BASIC I am reluctant to reinvent random access file routines. "In the old days" I had a library of "generic" routines for opening, closing, indexing, get record, put record, delete record, recovering space, etc. Are routines like that available that I can use?

I had thought to try SQLite, but seems like so much overkill for my simple program, because there won't be thousands of records.
Re: RANDOM ACCESS LIBRARY?
Post by tsh73 on Oct 20th, 2015, 11:54am

open / close / get / put are JB/LB/LBB operators.
There is a program sometimes mentioned on JB forum, so I've seen it work
Simple Database Framework
http://justbasic.wikispaces.com/Simple_Database_Framework
and on page near it
http://justbasic.wikispaces.com/Just+Basic+Shared+Code
some set of routines (I did not tried it)
Random access I/O functions library
http://justbasic.wikispaces.com/Random+access+files+with+arrays
Have a look.
Re: RANDOM ACCESS LIBRARY?
Post by Richard Russell on Oct 20th, 2015, 11:59am

on Oct 20th, 2015, 10:48am, pnlawrence wrote:
Being new to LBB and LB, but not new to BASIC I am reluctant to reinvent random access file routines. "In the old days" I had a library of "generic" routines for opening, closing, indexing, get record, put record, delete record, recovering space, etc. Are routines like that available that I can use?

LB/LBB natively supports Random Access Files with open, close, get record and put record statements. What you don't get 'built in' is full database functionality such as the ability to delete a record and recover the space.

It may be that a library for that already exists, but I don't personally know of one (of course only LBB supports 'true' libraries; with LB the routines would need to be appended to your own program).

If you do decide to use an off-the-shelf database package SQLite is not necessarily the best choice. LB/LBB can easily interface with ODBC (it's a standard component of Windows) which has the advantage of not tying you to one particular database manager.

Richard.

Re: RANDOM ACCESS LIBRARY?
Post by joker on Oct 20th, 2015, 12:13pm

I should have used the words "stored procedure" in my post.

A "stored procedure" being a little higher level function/sub/gosub encapsulation of database functions.

What I like to do in my programs is "insulate" myself from myself! smiley

Quote:
LB/LBB can easily interface with ODBC


I hadn't thought of ODBC. I'll do some searching there.
Re: RANDOM ACCESS LIBRARY?
Post by joker on Oct 20th, 2015, 12:33pm

Searching ...

Damn! Everything about BASIC is frustratingly OLD like me! Seems like every solution I run across is from 10 years ago.

I think RAF will be plenty robust enough for my program. tsh73, I have looked at all the resource links you provided and am studying how to make my own procedures.

Perhaps its time for a project to define a library of "stored procedures" for RAF.
Re: RANDOM ACCESS LIBRARY?
Post by Mystic on Oct 23rd, 2015, 12:33am

I would love to see some functions made that perform some simple SQL-like functions using the native RAF system...

Thought about trying to write some of my own but time is lacking.
Re: RANDOM ACCESS LIBRARY?
Post by joker on Oct 23rd, 2015, 11:09am

I'm starting to believe that it can be done, but only with a lot of "low level" routines serving as some sort of "interpreter" between the "SQL-like" statements and LB/LBB.

There doesn't seem to be much benefit for spending all the time involved.
Re: RANDOM ACCESS LIBRARY?
Post by Alincon on Oct 24th, 2015, 5:34pm

I don't use Random Access Files because you can't access them randomly - unless you know the record number - which means a separate index file - which means more work keeping the index and main file in synch.

I think the simplest thing to do is use one-record files and access them (randomly !) with the file dialog statement.

r.m.
Re: RANDOM ACCESS LIBRARY?
Post by Richard Russell on Oct 24th, 2015, 7:25pm

on Oct 24th, 2015, 5:34pm, Alincon wrote:
which means more work keeping the index and main file in synch.

There's not much effort involved in keeping them 'in sync' because the only way they can ever lose synchronisation is when you rebuild the data file to recover the space occupied by deleted records. Typically you would perform that operation only infrequently.

Quote:
I think the simplest thing to do is use one-record files and access them (randomly !) with the file dialog statement.

That's likely to be very wasteful of disk space. Consider the classic example of a database - an address list. A record might need to be something like 200 bytes long to contain (for example) a name, address, telephone number and email. But the minimum amount of disk space occupied by a file (however small) is typically 4 Kbytes - and that doesn't take into account the size of the directory itself - so you could easily end up using more than 20 times the amount of disk space than your database should occupy!

Richard.


Re: RANDOM ACCESS LIBRARY?
Post by joker on Oct 24th, 2015, 7:33pm

Can you explain what application uses a "randomly" accessed file system?

on Oct 24th, 2015, 5:34pm, Alincon wrote:
I think the simplest thing to do is use one-record files and access them (randomly !) with the file dialog statement.