modulepackage
0.0.0-20230225131734-eb960bd795f8
Repository: https://github.com/kirides/go-dbf.git
Documentation: pkg.go.dev
# README
Opening a DBF to read from it
package main
import (
"github.com/Kirides/go-dbf"
"golang.org/x/text/encoding/charmap"
)
func main() {
db, err := dbf.Open(`C:\Path\To\Some.dbf`, charmap.Windows1252.NewDecoder())
if err != nil {
panic(err)
}
defer db.Close()
}
Table scan
err = db.Scan(func(r dbf.Record) error {
if !r.Deleted() {
_, err = r.ToMap() // returns a map[string]interface{}
if err != nil {
panic(err)
}
}
return nil
})
if err != nil {
panic(err)
}
Reading a specific record
// recno is zero based
err := db.RecordAt(/*recno:*/ 5, func(r dbf.Record) {
if !r.Deleted() {
_, err = r.ToMap() // returns a map[string]interface{}
if err != nil {
panic(err)
}
}
})
if err != nil {
panic(err)
}
Extened fieldnames from DBC
Quick and easy
// Read the accompanying DBC file
err := db.ReadDBC()
Pre-read a DBC for reuse with multiple tables
// Read a DBC that lies relative to a .dbf
dbc, err := dbf.ReadDBC(filepath.Join(`location/of/dbf/`), db.DBC()), charmap.Windows1252.NewDecoder())
err := db.ReadFromDBC(dbc)
Example of reusing a dbc
knownDbcs := make(map[string]*dbf.Dbc)
dec := charmap.Windows1252.NewDecoder()
db, _ := dbf.Open(`...`, dec)
if db.DBC() != "" {
if d, ok := knownDbcs[db.DBC()]; ok {
db.ReadFromDBC(d)
} else {
dbc, err := dbf.ReadDBC(
filepath.Join(
filepath.Dir(dbfPath), db.DBC()),
dec)
// ...
db.ReadFromDBC(dbc)
knownDbcs[db.DBC()] = dbc
}
}
Mapped datatypes
C
-> stringV
-> string (basic support, might fail on tables with large amount of nullables and/or varchars)M
-> stringD
-> time.Time (in local timezone)T
-> time.Time (in local timezone)I
-> uint32L
-> boolN
- No decimals: int64
- Decimals: float64
Currently unsupported datatypes
G
General (COM)Q
BinaryB
Double
# Functions
MinimumDateTime returns 0001-01-01T00:00:00 @ time.Local.
Open opens the specifid DBF.
No description provided by the author
# Constants
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
FlagCDX File has a supporting structural index.
FlagDBC File is part of a DBC.
FlagMemo File has a supporting Memo file.
FlagNone no flags specified.
ParseDefault default options.
ParseTrimRight strings.TrimRight(s, " ") is applied to `C`-type fields.
TypeDBaseIVMemo ...
TypeDBaseIVSystem ...
TypeDBaseIVTable ...
TypeDBaseIVTableMemo ...
TypeFoxBase ...
TypeFoxBase2 ...
TypeFoxBasePlusDBaseIII ...
TypeFoxBasePlusDBaseIIIMemo ...
TypeFoxPro2Memo ...
TypeNone ...
TypeVisualFoxPro ...
TypeVisualFoxProAutoInc ...
TypeVisualFoxProVar ...
# Variables
ErrInvalidRecordNumber is returned whenever a provided record number is invalid.
# Type aliases
No description provided by the author
Flag defines flags.
ParseOption options for handling row parsing.
Type specifies the table type.