Keyed access file or similar?

Just starting out? Need help? Post your questions and find answers here.
jhendrickx
New User
New User
Posts: 3
Joined: Thu Aug 04, 2022 10:28 pm
Location: Valencia, Venezuela

Keyed access file or similar?

Post 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//
jassing
Addict
Addict
Posts: 1745
Joined: Wed Feb 17, 2010 12:00 am

Re: Keyed access file or similar?

Post 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.
jhendrickx
New User
New User
Posts: 3
Joined: Thu Aug 04, 2022 10:28 pm
Location: Valencia, Venezuela

Re: Keyed access file or similar?

Post by jhendrickx »

Thanks for yourfast and kindly answer ... I'll look into preferences.

Jean H//
jassing
Addict
Addict
Posts: 1745
Joined: Wed Feb 17, 2010 12:00 am

Re: Keyed access file or similar?

Post 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...
Bitblazer
Enthusiast
Enthusiast
Posts: 733
Joined: Mon Apr 10, 2017 6:17 pm
Location: Germany
Contact:

Re: Keyed access file or similar?

Post 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.
webpage - discord chat links -> purebasic GPT4All
Fred
Administrator
Administrator
Posts: 16618
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Keyed access file or similar?

Post 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))
jhendrickx
New User
New User
Posts: 3
Joined: Thu Aug 04, 2022 10:28 pm
Location: Valencia, Venezuela

Re: Keyed access file or similar?

Post by jhendrickx »

Thanks! I'll take a look into the answers!

Jean H//
Post Reply