These functions allow you to access records stored in dBase-format (dbf) databases. You can download lua-dbase from gitand report bug for me and i'll fix it as quickly as i can.
dBase files are simple sequential files of fixed length records. Records are appended to the end of the file and delete records are kept until you call dbf:pack().
The types of dBase fields available are:
| Field | dBase Type | Format | Additional information |
|---|---|---|---|
| M | Memo | n/a | This type is not supported, such field will be ignored |
| D | Date | YYYYMMDD | The field length is limited to 8 |
| N | Number | A number | You must declare a length and a precision (the number of digits after the decimal point) |
| C | String | A string | You must declare a length. When retrieving data, the string will be right-padded with spaces to fit the declared length. |
| L | Boolean | T or Y for TRUE, F or N for FALSE | Stored and returned as an integer (1 or 0) |
| F | Float | A float number |
after download,you can install like this.
tar xzvf lua-dbase.* cd lua-dbase.* make make install
require "dbase"
dbase.version()return the lua-dbase version info. just like:
luadbase (1.0.0) - Dbase-format(dbf) driver (c) 2009-19 Alacner zhang <alacner@gmail.com> This content is released under the MIT License.
local db, err = pgsql.open('/tmp/tmp.dbf', 2)
mode: An integer which correspond to those for the open() system call (Typically 0 means read-only, 1 means write-only, and 2 means read and write).
local def = {
{"date", "d"},
{"name", "C", 50},
{"age", "N", 3, 0},
{"email", "C", 128},
{"ismember", "L"},
}
local dbh,a,b,c = dbase.create('/tmp/base/test.dbf', def)
dbh:add_record{os.time(), "alacner", 18, 'alacner@gmail.com', 1}
dbh:add_record{os.time(), "name", 28, 'w@g.j', 0}
fields: An array of arrays, each array describing the format of one field of the database. Each field consists of a name, a character indicating the field type, and optionally, a length, and a precision.