Page 1 of 1

Keyed access file or similar?

Posted: Mon Jun 05, 2023 9:45 pm
by jhendrickx
Hi, I came from Business BASIC (BBx, ProvideX, PxPlus, etc), and bought a PureBASIC because I used it several (many!) years ago, and I liked it a lot. But, now, I think perhaps I can write some programs in PB instead of Business BASIC; but my main concern is I don't know if there a file storage similar to Business BASIC, where I can do:

! MYFILE is simple file, like STUDENTS.DAT or XXX.TXT or NOTHING.PNG, just with an internal structure
open(chan)MYFILE$
input "Key: ",cust_code$
read (chan,key=cust_code$)
...
write(chan)
...

The record access is made by a string (alphanumeric) key and is almost instantly; not Databases, no external tools, just a plain file with a excellent I/O method, and very fast (and we can store millions of records). Of course the language also support DataBase access, but that's not the question for me...

I've read a lot of pages, and only found a map structure that looks like keyed files, but I don't know if they can be used in the same (or similar) way. I know each language has is advantages and differences, but I'm used to this kind of storage and is ideal (for me) in small projects.

Best regards,
Jean H//

Re: Keyed access file or similar?

Posted: Mon Jun 05, 2023 10:36 pm
by jassing
I suppose you could use preference... but really, there WAS something else going on - some library that was linked in to provide that functionality.
I suppose you could say if you use sqlite, nothing "external" is used, it's all in one exe and provides full database support.
I think (I'm not sure) but if you search forums for "simple database" or "text database" you'll find code for something simple; but I'm not sure it will still work; I recall it from years ago, and purebasic has a way of dropping or changing functions over time.
I think preferences will be your simplest & easist solution.

Re: Keyed access file or similar?

Posted: Mon Jun 05, 2023 11:55 pm
by jhendrickx
Thanks for yourfast and kindly answer ... I'll look into preferences.

Jean H//

Re: Keyed access file or similar?

Posted: Tue Jun 06, 2023 12:14 am
by jassing
jhendrickx wrote: Mon Jun 05, 2023 11:55 pm Thanks for yourfast and kindly answer ... I'll look into preferences.
it's not ideal by any stretch, but it's probably the closest thing you're after...

Re: Keyed access file or similar?

Posted: Tue Jun 06, 2023 6:01 am
by Bitblazer
It does sound a bit like you want to use a huge file with fixed-length records to avoid using some kind of database "for speed reasons".

You can simply do that in purebasic with the file commands - where you use fileseek to position absolutely on a specific record.

IMHO it is a bad idea from the past, but you can easily implement that in purebasic.

Databases can be super fast, a better way would probably to find the best database solution for your task and access it with purebasic.

Re: Keyed access file or similar?

Posted: Tue Jun 06, 2023 10:39 am
by Fred
If you use a structure with fixedstrings instead of dynamic one, you can write it to disk in one go with https://www.purebasic.com/documentation ... edata.html and use fileseek (using SizeOf(YourStructure))

Re: Keyed access file or similar?

Posted: Wed Jun 07, 2023 5:19 pm
by jhendrickx
Thanks! I'll take a look into the answers!

Jean H//