main 9.0
Loading...
Searching...
No Matches
'abrain' - a server who provide a simple 'sqlLite' based database server

Introduction

abrain is a LibMsgque server and a wrapper for the sqlLite library to provide a database.
abrain server is best explained with a picture:

and the workflow:

abrain is a small database server for sqlLite.

The server is addressed via pipe, unix-domain-socket or network-socket and finally forwards the SQL to sqlLite.

The supported data-types are the data-types supported in LibMkKernel and are mapped to sqlLite. In order to enforce the data-types supported by LibMkKernel, these are checked in the passed SQL argument as well as in the results.


public database services

OPEN open-name

Open the database using open-name as:

Parameters
open-nameone of file-name, :memory: or ""
Returns
nothing, the context is linked to the database-id
type open-name
file based file-name
memory :memory:
tempdb ""

CLOS

Close database, reset DATA

Returns
nothing, but instance can be reused again

EXEC sql-string

Execute sql-string.

Parameters
sql-stringSQL string using sqlLite syntax
Returns
nothing, no results are expected

PREP ?prepare-id? sql-string → prepare-id

Prepare sql-string

Parameters
prepare-id(optional) - use this id
sql-string(required) - SQL string using sqlLite syntax
Returns
prepare-id - initial one or next free one
example
A simple SQL insert
  • /* in:IDC */ INSERT INTO testtbl (id, dval, cval) VALUES (?, ?, ?);
The in:IDC is an addition to SQL to enforce the datatype.
  • Supported are in:xxx and out:xxx
The xxx argument is one or more ONE character type-identifer from PRIMITIVE TYPE.
  • in:IDC = input argument type: I Integer, D Double and C String

FINA prepare-id

Finalize prepare-id

Parameters
prepare-idresult from PREP
Returns
nothing

STEP prepare-id args... → results

Call prepare-id with argument and propably expect result

Parameters
prepare-idresult from PREP
args...multiple arguments
Returns
list of results

The STEP is using the definition from in:xxx and out:xxx to extract the required results from the prepare-id

example
Create a simple workflow to fill and select a table:
# create working context
set FH [tclmsgque::MqMsgque::MqContextC Create]
# link to the database server
$FH LinkCreate --host rmthost --port rmtPort
# open remote database - using file "myDatabase.db"
$FH Send "W" "OPEN:C" "myDatabase.db"
# 1. create table
$FH Send "W" "EXEC:C" "CREATE TABLE testtbl (id INTEGER PRIMARY KEY, dval double, cval TEXT NOT NULL);"
# 2. prepare statement for insert using "prepare-id" == 0
$FH Send "W" "PREP:IC@I" 0 "/* in:IDC */ INSERT INTO testtbl (id, dval, cval) VALUES (?, ?, ?);"
# 3. insert data
$FH Send "W" "STEP:IIDC" 0 1 0.3 otto
$FH Send "W" "STEP:IIDC" 0 2 0.4 otto2
$FH Send "W" "STEP:IIDC" 0 3 0.5 otto3
# 4. prepare select statement using "prepare-id" == 1
$FH Send "W" "PREP:IC@I" 1 "/* in:I out:DC */ SELECT dval, cval FROM testtbl WHERE id < ?;"
# 5. select data
$FH Send "W" "STEP:II@L" 1 2
# delete connection
$FH Delete

Source-Code of "abrain"

abrain.c

usage: abrain [OPTION]... [ARGUMENT]...

  This tool is the database server of NHI1.
    main: https://theBrain.nhi1.de
    tool: https://thebrain.nhi1.de/theBrain.htm

  abrain [ARGUMENT]... syntax:
    aclient [OPTION]... @ abrain [OPTION]... [ARGUMENT]

  msgque [OPTION]:
    --help-msgque    print msgque specific help

  abrain [OPTION]:
    -h, --help       print this help