Compatibility Commands

The compatibility commands for old Dbm and Ndbm are described in the dbm manpage.

> berkdb dbminit filename

This command will invoke the dbminit function.   Filename is used as the name of the database.


> berkdb dbmclose

This command will invoke the dbmclose function.


> berkdb fetch key

This command will invoke the fetch function.   It will return the data associated with the given key or a Tcl error.


> berkdb store key data

This command will invoke the store function.   It will store the key/data pair.  It will return a 0 on success or throw a Tcl error.


> berkdb delete key

This command will invoke the deletet function.   It will delete the key from the database.  It will return a 0 on success or throw a Tcl error.


> berkdb firstkey

This command will invoke the firstkey function.   It will return the first key in the database or a Tcl error.


> berkdb nextkey key

This command will invoke the nextkey function.   It will return the next key after the given key or a Tcl error.


> berkdb hcreate nelem

This command will invoke the hcreate function with nelem elements.  It will return a 0 on success or a Tcl error.


> berkdb hsearch key data action

This command will invoke the hsearch function with key and data.  The action must be either find or enter.  If it is find, it will return the resultant data.  If it is enter, it will return a 0 on success or a Tcl error.


> berkdb hdestroy

This command will invoke the hdestroy function.  It will return a 0.


> berkdb ndbm_open [-create] [-rdonly] [-truncate] [-mode mode] [--] filename

This command will invoke the dbm_open function.    After it successfully gets a handle to a database, we bind it to a new Tcl command of the form ndbmX, where X is an integer starting at 0 (e.g. ndbm0, ndbm1, etc).  We use the Tcl_CreateObjCommand()  to create the top level database function.  It is through this handle that the user can access all of the commands described below.  Internally, the database handle is sent as the ClientData portion of the new command set so that all future database calls access the appropriate handle.

The arguments are:




> <ndbm> close

This command closes the database and renders the handle invalid.   This command directly translates to the dbm_close function call.  It returns either a 0 (for success),  or it throws a Tcl error with a system message.

Additionally, since the handle is no longer valid, we will call Tcl_DeleteCommand() so that further uses of the handle will be dealt with properly by Tcl itself. 



> <ndbm> clearerr

This command clears errors  the database.   This command directly translates to the dbm_clearerr function call.  It returns either a 0 (for success),  or it throws a Tcl error with a system message.



> <ndbm> delete key

This command deletes the key from thedatabase.   This command directly translates to the dbm_delete function call.  It returns either a 0 (for success),  or it throws a Tcl error with a system message.



> <ndbm> dirfno

This command directly translates to the dbm_dirfno function call.  It returns either resultts,  or it throws a Tcl error with a system message.



> <ndbm> error

This command returns the last error.   This command directly translates to the dbm_error function call.  It returns an error string..



> <ndbm> fetch key

This command gets the given key from the database.   This command directly translates to the dbm_fetch function call.  It returns either the data,  or it throws a Tcl error with a system message.



> <ndbm> firstkey

This command returns the first key in the database.   This command directly translates to the dbm_firstkey function call.  It returns either the key,  or it throws a Tcl error with a system message.



> <ndbm> nextkey

This command returns the next key in the database.   This command directly translates to the dbm_nextkey function call.  It returns either the key,  or it throws a Tcl error with a system message.



> <ndbm> pagfno

This command directly translates to the dbm_pagfno function call.  It returns either resultts,  or it throws a Tcl error with a system message.



> <ndbm> rdonly

This command changes the database to readonly.   This command directly translates to the dbm_rdonly function call.  It returns either a 0 (for success),  or it throws a Tcl error with a system message.



> <ndbm> store key data insert|replace

This command puts the given key and data pair into the database.   This command directly translates to the dbm_store function call.  It will either insert or replace the data based on the action given in the third argument.  It returns either a 0 (for success),  or it throws a Tcl error with a system message.