AC_QuickBase, a Memory based Data storage for 4D V14

Ever needed to keep structured data without creating tables?
Need simple data structures for a component without adding persistent storage tables to the host database or using an external database?
Well, I may have a thing for you:

AC_QuickBase

A simple, memory based Database Component for 4D.

The command set at a glance:

AC_QuickBase – initializes the database system

ACQB_CreateTable – create a database table
ACQB_DropTable – drop the table specified
ACQB_Truncate – clears all records from a table

ACQB_Insert – create a new record
ACQB_Update – modify an existing record
ACQB_Delete – delete a record

ACQB_Value – retrieves a field value
ACQB_ValueToArray – retrieves a field value for multiple records

ACQB_Find – find a specific record, the first match is returned
ACQB_FindSel – find all records matching the request

ACQB_Count – Count records in a table

ACQB_Export – exports the database to disk
ACQB_Import – imports a database from disk

ACQB_Clear – clears the database from memory

ACQB_Editor – displays a data view and editor

Interested?

This memory-based database works with 2-d arrays and objects.
It supports the basic CRUD operations and simple AND queries on multiple fields.
There is only one data type: all is stored an passed back and forth as text.
There is no sort, as you can do that with the retrieved data.
All access to record data, deleting and updating requires a record number, but what I call record numbers is different from the 4d record numbers insofar as they can change if records get deleted. They are more like SELECTED RECORD NUMBER.

I do not plan on adding much more functionality, but any input or inspiration is greatly welcome.

Oh, and as I am inherently lazy and this is a tool for mature developers, calling the error checking rudimentary would be an euphemism…

Download the Component from here:

Freebies Repository

First an example for using the Component:

//initialise
AC_QuickBase 

//create the "movies" table
ACQB_CreateTable ("Movies";"Title";"Director";"Genre")

//insert a few records
$l_RecNum:=ACQB_Insert ("Movies";"Title";"2001 a Space Odyssee";"Director";"Kubrik";"Genre";"SciFi")
$l_RecNum:=ACQB_Insert ("Movies";"Title";"The Shining";"Director";"Kubrik";"Genre";"Horror")
$l_RecNum:=ACQB_Insert ("Movies";"Title";"Blade Runner";"Director";"Ridley Scott")
$l_RecNum:=ACQB_Insert ("Movies";"Title";"The Ring";"Genre";"Horror")

//get the reccord for "Blade Runner"
$l_RecNum:=ACQB_Find ("Movies";"Title";"Blade Runner")
//set the genre to "SciFi"
ACQB_Update ("Movies";$l_RecNum;"Genre";"SciFi")

//Find all movies with Genre "Horror"
ARRAY LONGINT($al_Recs;0)
$l_Records:=ACQB_FindSel ("Movies";->$al_Recs;"Genre";"Horror")
//put the titles into an array
ARRAY TEXT($at_Titles;0)
For ($i;1;$l_Records)
  APPEND TO ARRAY($at_Titles;ACQB_Value ("Movies";$al_Recs{$i};"Title"))
End for

//get the reccord for "Blade Runner"
$l_RecNum:=ACQB_Find ("Movies";"Title";"Blade Runner")
//set delete the record
ACQB_Delete ("Movies";$l_RecNum)

//export to default location
ACQB_Export

//clear all from memory
ACQB_Clear

And now for the methods:

AC_QuickBase
Initializes the Component, call before anything else

ACQB_CreateTable(Tablename;Field1{;Field2...{;Fieldn}}
Create a table with the fields you need.

ACQB_DropTable(TableName)
Deletes a table and all the data in it from the schema

ACQB_Truncate(TableName)
Delete all records from a table without changing its definition

RecNum:=ACQB_Insert(TableName;Field_1;Value_1{;Field_2;Value_2{...;Field_n;Value_n}})
Adds a record with values to a table and returns the record number. You do not need to pass all fields, just make sure you always pass pairs.

ACQB_Update(TableName;RecordNum;Field_1;Value_1{;Field_2;Value_2{...Field_n;Value_n}})
Update the record with the number passed, setting the field values passed in the key/value parameter pairs.

ACQB_Delete(TableName;RecordNumber)
Deletes the record with the record number passed

Value:=ACQB_Value(TableName;RecordNum;Field)
Returns a field value for the record number given and the requested field

ACQB_ValueToArray(TableName;->RecordNums;Field;->Values)
Returns in an array the field value for the record numbers given in the array

$l_RecNum:=ACQB_Find("Table";QueryField_1;QueryValue_1{;QueryField_2;QueryValue_2...{;QueryField_n;QueryValue_n}})
Returns the number of the first record matching the query criteria passed in the key/value pairs. Queries are always AND on the query parameters

Records:=ACQB_FindSel(TableName;ArrayPointer;QueryField_1;QueryValue_1{;QueryField_2;QueryValue_2...{;QueryField_n;QueryValue_n}})
Returns the record numbers of the all record matching the query criteria passed in the key/value pairs in the longing array passed to the method. Again, queries are always AND on the query parameters

RecCount:=ACQB_Count(TableName)
Returns the number of records in the table

Path:=ACQB_Export{(Path)}
Export the database to a file, either pass the full file path or it will be stored in the current 4d folder named like the host database with the suffix “.ACQB”. The storage path is returned.

ACQB_Import{(Path)}
Import a database from a file. Pass the path to the file or it will attempt to read from the default path as explained in ACQB_Export.
Careful: This command completely clears any databases currently in use!

ACQB_Clear
If you’re done with the database, use this to clear it from memory.

ACQB_Editor
Shows a minimalistic list based editor for your AC_QuickBase data.

4D

And now…
go create!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.