godbf

package module
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 21, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

README

go-dbf

Build Status GoDoc

A pure Go library for reading and writing dBase/xBase database files

This project is a part of go-shp library. go-shp is a pure Go implementation of Esri Shapefile format.

You can incorporate the library into your local workspace with the following 'go get' command:

go get github.com/LindsayBradford/go-dbf

Code needing to call into the library needs to include the following import statement:

import (
  "github.com/LindsayBradford/go-dbf"
)

Here is a very simple snippet of example 'load' code to get you going:

  dbfTable, err := godbf.NewFromFile("exampleFile.dbf", "UTF8")

  exampleList := make(ExampleList, dbfTable.NumberOfRecords())

  for i := 0; i < dbfTable.NumberOfRecords(); i++ {
    exampleList[i] = new(ExampleListEntry)

    exampleList[i].someColumnId, err = dbfTable.FieldValueByName(i, "SOME_COLUMN_ID")
  }

Further examples can be found by browsing the library's test suite.

Projects using godbf

dbfcsv - A command line utility for dbf/csv conversion

Documentation

Overview

Package godbf offers functionality for loading and saving "dBASE Version 5" dbf formatted files. (https://en.wikipedia.org/wiki/.dbf#File_format_of_Level_5_DOS_dBASE) file structure. For the definitive source, see http://www.dbase.com/manuals/57LanguageReference.zip

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SaveToFile

func SaveToFile(dt *DbfTable, filename string) (saveErr error)

SaveToFile saves the supplied DbfTable to a file of the specified filename

Types

type DbaseDataType

type DbaseDataType byte

DbaseDataType is dBase data type, as per https://www.dbase.com/Knowledgebase/INT/db7_file_fmt.htm, under heading "Storage of dBASE Data Types".

const (
	Character DbaseDataType = 'C'
	Logical   DbaseDataType = 'L'
	Date      DbaseDataType = 'D'
	Numeric   DbaseDataType = 'N'
	Float     DbaseDataType = 'F'
	Memo      DbaseDataType = 'M'
)

type DbfTable

type DbfTable struct {
	// contains filtered or unexported fields
}

DbfTable is an in-memory container for dbase formatted data, and state that helps manage that data.

func New

func New(encoding string) (table *DbfTable)

New creates a new dbase table from scratch for the given character encoding

func NewFromByteArray

func NewFromByteArray(data []byte, fileEncoding string) (table *DbfTable, newErr error)

NewFromByteArray creates a DbfTable, reading it from a raw byte array, expecting the supplied encoding.

func NewFromFile

func NewFromFile(fileName string, fileEncoding string) (table *DbfTable, newErr error)

NewFromFile creates a DbfTable, reading it from a file with the given file name, expecting the supplied encoding.

func (*DbfTable) AddBooleanField

func (dt *DbfTable) AddBooleanField(fieldName string) (err error)

func (*DbfTable) AddDateField

func (dt *DbfTable) AddDateField(fieldName string) (err error)

func (*DbfTable) AddFloatField

func (dt *DbfTable) AddFloatField(fieldName string, length byte, decimalPlaces uint8) (err error)

func (*DbfTable) AddMemoField

func (dt *DbfTable) AddMemoField(fieldName string) (err error)

func (*DbfTable) AddNewRecord

func (dt *DbfTable) AddNewRecord() (newRecordNumber int, addErr error)

AddNewRecord adds a new empty record to the table, and returns the index number of the record.

func (*DbfTable) AddNumberField

func (dt *DbfTable) AddNumberField(fieldName string, length byte, decimalPlaces uint8) (err error)

func (*DbfTable) AddTextField

func (dt *DbfTable) AddTextField(fieldName string, length byte) (err error)

func (*DbfTable) DecimalPlacesInField

func (dt *DbfTable) DecimalPlacesInField(fieldName string) (uint8, error)

DecimalPlacesInField returns the number of decimal places for the field with the given name. If the field does not exist, or does not use decimal places, an error is returned.

func (*DbfTable) FieldNames

func (dt *DbfTable) FieldNames() []string

FieldNames return the names of fields in the table as a slice

func (*DbfTable) FieldValue

func (dt *DbfTable) FieldValue(row int, fieldIndex int) (value string)

FieldValue returns the content for the record at the given row and field index as a string If the row or field index is invalid, an error is returned .

func (*DbfTable) FieldValueByName

func (dt *DbfTable) FieldValueByName(row int, fieldName string) (value string, err error)

FieldValueByName returns the value of a field given row number and name provided

func (*DbfTable) Fields

func (dt *DbfTable) Fields() []FieldDescriptor

Fields return the fields of the table as a slice

func (*DbfTable) Float64FieldValueByName

func (dt *DbfTable) Float64FieldValueByName(row int, fieldName string) (value float64, err error)

Float64FieldValueByName returns the value of a field given row number and name provided as a float64

func (*DbfTable) GetRowAsSlice

func (dt *DbfTable) GetRowAsSlice(row int) []string

GetRowAsSlice return the record values for the row specified as a string slice

func (*DbfTable) HasField

func (dt *DbfTable) HasField(fieldName string) bool

HasField returns true if the table has a field with the given name If the field does not exist an error is returned.

func (*DbfTable) HasRecord

func (dt *DbfTable) HasRecord(recordNumber int) bool

HasRecord returns true if the table has a record with the given number otherwise, false is returned. Use this method before FieldValue() to avoid index-out-of-range errors.

func (*DbfTable) Int64FieldValueByName

func (dt *DbfTable) Int64FieldValueByName(row int, fieldName string) (value int64, err error)

Int64FieldValueByName returns the value of a field given row number and name provided as an int64

func (*DbfTable) NumberOfRecords

func (dt *DbfTable) NumberOfRecords() int

NumberOfRecords returns the number of records in the table

func (*DbfTable) RowIsDeleted

func (dt *DbfTable) RowIsDeleted(row int) bool

RowIsDeleted returns whether a row has marked as deleted

func (*DbfTable) SaveFile deprecated

func (dt *DbfTable) SaveFile(filename string) error

Deprecated: Use SaveToFile() instead.

func (*DbfTable) SetFieldValue

func (dt *DbfTable) SetFieldValue(row int, fieldIndex int, value string) (err error)

SetFieldValue sets the value for the given row and field index as specified If the field index is invalid, or the value is incompatible with the field's type, an error is returned.

func (*DbfTable) SetFieldValueByName

func (dt *DbfTable) SetFieldValueByName(row int, fieldName string, value string) (err error)

SetFieldValueByName sets the value for the given row and field name as specified If the field name does not exist, or the value is incompatible with the field's type, an error is returned.

type FieldDescriptor

type FieldDescriptor struct {
	// contains filtered or unexported fields
}

FieldDescriptor describes one field/column in a DbfTable as per https://www.dbase.com/Knowledgebase/INT/db7_file_fmt.htm, Heading 1.2.

func (*FieldDescriptor) DecimalPlaces

func (fd *FieldDescriptor) DecimalPlaces() byte

DecimalPlaces returns the count of decimal places for the field

func (*FieldDescriptor) FieldType

func (fd *FieldDescriptor) FieldType() DbaseDataType

FieldType returns the type of data stored for the field as a DbaseDataType

func (*FieldDescriptor) Length

func (fd *FieldDescriptor) Length() byte

Length returns the length of data stored for the field

func (*FieldDescriptor) Name

func (fd *FieldDescriptor) Name() string

Name returns the column name of the field

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL