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:


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


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:


//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"
$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

//clear all from memory

And now for the methods:

Initializes the Component, call before anything else

Create a table with the fields you need.

Deletes a table and all the data in it from the schema

Delete all records from a table without changing its definition

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.

Update the record with the number passed, setting the field values passed in the key/value parameter pairs.

Deletes the record with the record number passed

Returns a field value for the record number given and the requested field

Returns in an array the field value for the record numbers given in the array

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

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

Returns the number of records in the table

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.

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!

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

Shows a minimalistic list based editor for your AC_QuickBase data.


And now…
go create!

Leave a Reply

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