Is there a plan to support indexed files? Sometimes it would be easier to use an indexed file instead of a database. For example if I only need one (or relatively small number of files) indexed file. I think that working with the database can also be very hard if you don't have enough experience. Indexed files are very easy to use.
More info could be provided if required. Some info is here:
https://documentation.microfocus.com/he ... _4_7_1_1_3
Other file organizations: https://documentation.microfocus.com/he ... _7_4_7_1_1
There are two ways how to handle indexes:
1. one is to store this information in the .dat file itself
2. the other is to have two separate files: .dat and .idx
Saso
Indexed files
Re: Indexed files
For a small amount of data, you could use a structure with fixed length strings.
In this case it's very easy to read or write an entire array.
If you are working with a file instead of an array, it's also easy to seek a record by changing the file pointer.
Code: Select all
Structure Record
MembershipNumber.w
Name.s{20}
EndStructure
Dim Records.Record(99)
With Records(0)
\MembershipNumber = 1000
\Name = "John"
EndWith
With Records(99)
\MembershipNumber = 1100
\Name = "Luke"
EndWith
If CreateFile(0, "SimpleDatabase.dat")
WriteData(0, @Records(), 100 * SizeOf(Record))
CloseFile(0)
EndIf
If you are working with a file instead of an array, it's also easy to seek a record by changing the file pointer.
Windows (x64)
Raspberry Pi OS (Arm64)
Raspberry Pi OS (Arm64)
Re: Indexed files
Quite simple, actually. Here are the component functions, broken down for clarity.miskox wrote:...working with the database can also be very hard...
1. Creating an empty SQLite database file (first time only):
Code: Select all
CreateFile(0, GetTemporaryDirectory() + "myDB.sqlite")
CloseFile(0)
Code: Select all
UseSQLiteDatabase()
OpenDatabase(0, GetTemporaryDirectory() + "myDB.sqlite", "", "")
DatabaseUpdate(0, "CREATE TABLE indexFile (name CHAR(200), age INT)")
CloseDatabase(0)
Code: Select all
UseSQLiteDatabase()
OpenDatabase(0, GetTemporaryDirectory() + "myDB.sqlite", "", "")
DatabaseUpdate(0, "INSERT INTO indexFile (name, age) VALUES ('Einstein', '76')")
DatabaseUpdate(0, "INSERT INTO indexFile (name, age) VALUES ('DaVinci', '67')")
DatabaseUpdate(0, "INSERT INTO indexFile (name, age) VALUES ('Newton', '84')")
CloseDatabase(0)
Code: Select all
UseSQLiteDatabase()
OpenDatabase(0, GetTemporaryDirectory() + "myDB.sqlite", "", "")
DatabaseUpdate(0, "UPDATE indexFile SET name='Isaac Newton' WHERE name='Newton'")
CloseDatabase(0)
Code: Select all
UseSQLiteDatabase()
OpenDatabase(0, GetTemporaryDirectory() + "myDB.sqlite", "", "")
DatabaseQuery(0, "SELECT * from indexFile WHERE name='Isaac Newton'")
While NextDatabaseRow(0)
age = GetDatabaseLong(0, 1)
Wend
Debug "Isaac Newton was " + Str(age) + " years old."
CloseDatabase(0)
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel
Re: Indexed files
Or the easy-json way
Testing
Code: Select all
Structure strDaten
name.s
id.d
EndStructure
Structure strD
List daten.strDaten()
EndStructure
Procedure saveData(file.s,*d.strD)
Protected json=CreateJSON(#PB_Any)
InsertJSONStructure(JSONValue(json),*d,strD)
SaveJSON(json,file)
FreeJSON(json)
EndProcedure
Procedure loadData(file.s)
Protected *d.strD=AllocateStructure(strD)
Protected json=LoadJSON(#PB_Any,file)
ExtractJSONStructure(JSONValue(json),*d,strD)
FreeJSON(json)
ProcedureReturn *d
EndProcedure
Code: Select all
Protected *d.strD=AllocateStructure(strD)
AddElement(*d\daten())
*d\daten()\id=1
*d\daten()\name="Test 1"
AddElement(*d\daten())
*d\daten()\id=2
*d\daten()\name="Test 2"
saveData("Daten.json",*d)
Protected *d2.strD=loadData("Daten.json")
ForEach *d2\daten()
Debug *d2\daten()\name
Next