atbas logo


Basic Apps and Software

 miniDB: Example

Example commands using the mDB executable: New file creation: Ex. mdb customer c 'custid:i6|seak:c8|name:a30|place:a30|_idx:1|_idx:2:1|' Will create a new isamfile called customer with 2 indexes. each field is seperated by '|' and each field specifies a type and length so: custid:n6 = numeric, length 6 seak:c8 = ascii, length 8 name:a30 = ascii, length 30 types: a - ascii field c - ascii field, in keys it is uppercased and stripped from spaces ex. 'John Doe' will be used in an index as 'JOHNDOE' but in the data it will still be 'John Doe' n - numeric field i - numeric field, when 0 it is given an autoincrement value f - float field (syntax f8.2) All data is saved as ascii in the isam file with '|' as a seperator. Adding data: Ex. mdb customer a '0|doe|John Doe|New York|' 1|1201|doe|John Doe|New York| Adds a new record to file customer and its indexes. fieldvalues seperated by '|', autoincrement fields can be 0 Will output the added record to standard out with its recordnumber prefixed and with the generated autoincement values. mdb -u'place|name|custid|seak' customer a '1201' 'London|John Doe|1201|doe' The -u flag maps the record fields from the last parameter (record values) Retrieving data: Ex. mdb customer e '1201' retrieve exact matching key '1201' mdb customer n '1201' retrieve the next key mdb customer p '1201' retrieve the previous key mdb customer f retrieve the first record using index 1 mdb -k2 customer l retrieve the last record using index 2 mdb -k2 -r10 customer s 'do' search on index 2 as >= 'do' and retrieve 10 rows mdb -r-10 customer s 'do' same, but does the previous records Updating: ex. mdb -b'#' customer u '1201' '#|#|London|' Will retrieve indexkey '1201' (index 1) and update its field contents, leaving the '#' fields to the original values. Note: Will update only 1 record. mdb -b'#' -u'place|name' customer u '1201' 'London|Doe' The -u flag will specify the last parameter and internally it will be build like: '#|#|Doe|London|' Deleting: Ex. mdb customer d '1201' Will delete the record with indexkey '1201' (index 1) . Adding and deleting indexes: Ex. mdb -k2 customer D Delete index 2 mdb -k2 customer C '2:1' Add index 2 on field 2 and 1 (seak/id) mdb -k2 customer B Rebuilds index 2 mdb -k0 customer B Rebuilds all indexes Enable/disable logging: Ex. mdb customer L on Enable file logging Ex. mdb customer L off Disable file logging With filelogging all inserts,updates and deletes are logged into a seperate logfile. With this logfile changes can be traced and for instance an incremental backup can be made or changes can be reversed. When updates are logged the old and new records are being logged. Information: Ex. mdb customer i gives some mdb information JSON output example: mdb -f -r2 demo s '12344'|mdb2json -p "tbl_" -r { "tbl_Result": [ { "tbl_recno": 11344, "tbl_id": 12344, "tbl_seak": "infirm", "tbl_name": "infirm", "tbl_street": "street 12344", "tbl_postal": "ZIP 1234", "tbl_place": "nfirm" },{ "tbl_recno": 11345, "tbl_id": 12345, "tbl_seak": "affirmed", "tbl_name": "affirmed", "tbl_street": "street 12345", "tbl_postal": "ZIP 1234", "tbl_place": "ffirmed" } ], "tbl_NoRows": 2 }