Here is the Script BASIC include file for the
BerkleyDB extension module that hasn't been updated in years. If you would like a zip of the extension module source for it, let me know.
This document describes how to install and use the module BDB developed to help programmers writing database-handling programs in ScriptBasic. The module BDB is based on the Berkeley Data Base from Sleepy Cat Software Inc.
There are separate documents that describe the language (Users’ Guide), the major architecture of the source code (Source Guide).
This document describes the version 2.0 of the module.
The Berkeley Database (bdb) is a set of database handling routines. The program using the bdb directly calls these routines. There is no SQL server or a database daemon. In this sense this is a library collection that can handle simple database structures.
Although it is cumbersome to write complex database application using the Berkeley database lacking SQL interface it pays back on performance.
The Berkeley Database is available on Windows NT as well as on UNIX. It supports transaction handling and is it capable handling really huge databases. Therefore it is an ideal choice for several types of application where there is no need to separate the application from the database.
The bdb module developed for ScriptBasic provides an interface to a subset of the Berkeley Database functions. Using the module the BASIC program can use database handling functions, and transactions. On the other hand BASIC programs can not directly use the shared memory management functions, or locking (only through transactions). Application programmers needing these functions should rather consider developing their own ScriptBasic module using the language C delivering their application specific functions using the underlying Berkeley Database functions.
The functions available to BASIC programmers allow database creation, inserting, deleting, updating, searching data element with single or duplicated keys, start, commit and abort transactions. Some functions are simplified. The BASIC interface does not resemble to the C API of the Berkeley Database. Rather it is a BASIC language database-handling interface that happens to use the Berkeley Database.
'
' FILE: bdb.bas
'
' This is the module declaration of the ScriptBasic external module bdb
'
' To use this module you have to have bdb.dll or bdb.so installed in the
' modules directory.
'
' These implement the interface to the Berkeley Data Base library
module bdb
' Error codes
Const ErrorInvalidFileName = &H80001
Const ErrorInvalidDbHandle = &H80002
Const ErrorTransactionnotClosed = &H80003
Const ErrorTransactionNotOpened = &H80004
Const ErrorKeyNotFound = &H80005
Const ErrorIncomplete = &H80006
Const ErrorKeyEmpty = &H80007
Const ErrorKeyExist = &H80008
Const ErrorLockDeadLock = &H80009
Const ErrorLockNotGranted = &H8000A
Const ErrorNotFound = &H8000B
Const ErrorOldVersion = &H8000C
Const ErrorRunRecovery = &H8000D
Const ErrorDeleted = &H8000E
Const ErrorNeedSplit = &H8000F
Const ErrorSwapBytes = &H80010
Const ErrorTxnCkp = &H80011
' Table types
Const BTree = &H01
Const Hash = &H02
Const Recno = &H04
Const Queue = &H08
Const Unknown = &H10
' put flags
Const Append = &HFFFFFFFE
Const NoOverWrite = &HFFFFFFFD
' Table opening flags
Const Create = &HFFFFFFFE
Const NoMap = &HFFFFFFFD
Const RdOnly = &HFFFFFFFB
Const Thread = &HFFFFFFF7
Const Trunc = &HFFFFFFEF
Const New = &HFFFFFFDF
' open the database
' DB = bdb::Open(DataBase,type,flags,unixmode)
declare sub ::
Open alias "sb_db_open" lib "bdb"' close the DB
' bdb::Close DB
declare sub ::
Close alias "sb_db_close" lib "bdb"' put a new, possibly duplicated key/value pairinto DB
' bdb::Put DB,key,value
declare sub ::Put
alias "sb_db_put" lib "bdb"' update the last accessed record
' bdb::Update DB,value
declare sub ::Update
alias "sb_db_update" lib "bdb"' delete the last accessed record
' bdb::DeleteRecord DB
declare sub ::DeleteRecord
alias "sb_db_eracrec" lib "bdb"' get value matching the key from DB
' if there are more than one values for the same key return the first one
' value = bdb::Get(DB,key)
declare sub ::Get
alias "sb_db_get" lib "bdb"' value = bdb::First(DB,key) or value = bdb::First(DB)
declare sub ::First
alias "sb_db_get" lib "bdb"' get the last value from DB
' value = bdb::Last(DB)
declare sub ::Last
alias "sb_db_last" lib "bdb"' get the next value for the key or undef if there are no more
' value = bdb::Next(DB,key)
declare sub ::
Next alias "sb_db_next" lib "bdb"' get the previous value for the key or undef if there are no more
' value = bdb::Previous(DB,key)
declare sub ::Previous
alias "sb_db_prev" lib "bdb"' delete all records for the given key
' bdb::DeleteAll DB,key
declare sub ::DeleteAll
alias "sb_db_del" lib "bdb"' get the key of the last accessed record
' bdb::Key(DB)
declare sub ::Key
alias "sb_db_key" lib "bdb"' transaction handling, no arguments
declare sub ::BeginTransaction
alias "sb_db_transact" lib "bdb"declare sub ::CommitTransaction
alias "sb_db_trcommit" lib "bdb"declare sub ::EndTransaction
alias "sb_db_trcommit" lib "bdb"declare sub ::AbortTransaction
alias "sb_db_trabort" lib "bdb"' delete a database table
' bdb::Drop "databasename"
declare sub ::Drop
alias "sb_db_remove" lib "bdb"end module