dbase

package
v0.0.0-...-e4b95c5 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2024 License: BSD-3-Clause Imports: 20 Imported by: 0

Documentation

Overview

This go-dbase package offers tools for managing dBase-format database files. It supports tailored I/O operations for Unix and Windows platforms, provides flexible data representations like maps, JSON, and Go structs, and ensures safe concurrent operations with built-in mutex locks.

The package facilitates defining, manipulating, and querying columns and rows in dBase tables, converting between dBase-specific data types and Go data types, and performing systematic error handling.

Typical use cases include data retrieval from legacy dBase systems, conversion of dBase files to modern formats, and building applications that interface with dBase databases.

Index

Constants

View Source
const (
	MaxColumnNameLength = 10
	MaxCharacterLength  = 254
	MaxNumericLength    = 20
	MaxFloatLength      = 20
	MaxIntegerValue     = math.MaxInt32
	MinIntegerValue     = math.MinInt32
)

Variables

View Source
var (
	// Returned when the end of a dBase database file is reached
	ErrEOF = errors.New("EOF")
	// Returned when the row pointer is attempted to be moved before the first row
	ErrBOF = errors.New("BOF")
	// Returned when the read of a row or column did not finish
	ErrIncomplete = errors.New("INCOMPLETE")
	// Returned when a file operation is attempted on a non existent file
	ErrNoFPT = errors.New("FPT_FILE_NOT_FOUND")
	ErrNoDBF = errors.New("DBF_FILE_NOT_FOUND")
	// Returned when an invalid column position is used (x<1 or x>number of columns)
	ErrInvalidPosition = errors.New("INVALID_POSITION")
	ErrInvalidEncoding = errors.New("INVALID_ENCODING")
	// Returned when an invalid data type is used
	ErrUnknownDataType = errors.New("UNKNOWN_DATA_TYPE")
)

Functions

func Debug

func Debug(enabled bool, out io.Writer)

Debug the dbase package If debug is true, debug messages will be printed to the defined io.Writter (default: os.Stdout)

func ValidateFileVersion

func ValidateFileVersion(version byte, untested bool) error

Check if the file version is tested

Types

type Column

type Column struct {
	FieldName [11]byte // Column name with a maximum of 10 characters. If less than 10, it is padded with null characters (0x00).
	DataType  byte     // Column type
	Position  uint32   // Displacement of column in row
	Length    uint8    // Length of column (in bytes)
	Decimals  uint8    // Number of decimal places
	Flag      byte     // Column flag
	Next      uint32   // Value of autoincrement Next value
	Step      uint16   // Value of autoincrement Step value
	Reserved  [7]byte  // Reserved
}

Column is a struct containing the column information

func NewColumn

func NewColumn(name string, dataType DataType, length uint8, decimals uint8, nullable bool) (*Column, error)

Create a new column with the specified name, data type, length, decimals and nullable flag The length is only used for character, varbinary, varchar, numeric and float data types

func (*Column) Name

func (c *Column) Name() string

Returns the name of the column as a trimmed string (max length 10)

func (*Column) Reflect

func (c *Column) Reflect() (reflect.Type, error)

func (*Column) Type

func (c *Column) Type() string

Returns the type of the column as string (length 1)

type ColumnFlag

type ColumnFlag byte

Column flags indicate wether a column is hidden, can be null, is binary or is autoincremented

const (
	HiddenFlag        ColumnFlag = 0x01
	NullableFlag      ColumnFlag = 0x02
	BinaryFlag        ColumnFlag = 0x04
	AutoincrementFlag ColumnFlag = 0x0C
)

type Config

type Config struct {
	Filename                          string            // The filename of the DBF file.
	Converter                         EncodingConverter // The encoding converter to use.
	Exclusive                         bool              // If true the file is opened in exclusive mode.
	Untested                          bool              // If true the file version is not checked.
	TrimSpaces                        bool              // Trimspaces default value
	DisableConvertFilenameUnderscores bool              // If false underscores in the table filename are converted to spaces.
	ReadOnly                          bool              // If true the file is opened in read-only mode.
	WriteLock                         bool              // Whether or not the write operations should lock the record
	ValidateCodePage                  bool              // Whether or not the code page mark should be validated.
	InterpretCodePage                 bool              // Whether or not the code page mark should be interpreted. Ignores the defined converter.
	IO                                IO                // The IO interface to use.
}

Config is a struct containing the configuration for opening a Foxpro/dbase databse or table. The filename is mandatory.

The other fields are optional and are false by default. If Converter and InterpretCodePage are both not set the package will try to interpret the code page mark. To open untested files set Untested to true. Tested files are defined in the constants.go file.

type DataType

type DataType byte

DataType defines the possible types of a column

const (
	Character DataType = 0x43 // C - Character (string)
	Currency  DataType = 0x59 // Y - Currency (float64)
	Double    DataType = 0x42 // B - Double (float64)
	Date      DataType = 0x44 // D - Date (time.Time)
	DateTime  DataType = 0x54 // T - DateTime (time.Time)
	Float     DataType = 0x46 // F - Float (float64)
	Integer   DataType = 0x49 // I - Integer (int32)
	Logical   DataType = 0x4C // L - Logical (bool)
	Memo      DataType = 0x4D // M - Memo (string)
	Numeric   DataType = 0x4E // N - Numeric (int64)
	Blob      DataType = 0x57 // W - Blob ([]byte)
	General   DataType = 0x47 // G - General (string)
	Picture   DataType = 0x50 // P - Picture (string)
	Varbinary DataType = 0x51 // Q - Varbinary ([]byte)
	Varchar   DataType = 0x56 // V - Varchar (string)
)

func (DataType) Reflect

func (t DataType) Reflect() (reflect.Type, error)

func (DataType) String

func (t DataType) String() string

Returns the type of the column as string

type Database

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

func OpenDatabase

func OpenDatabase(config *Config) (*Database, error)

OpenDatabase opens a dbase/foxpro database file and all related tables The database file must be a DBC file and the tables must be DBF files and in the same directory as the database

func (*Database) Close

func (db *Database) Close() error

Close the database file and all related tables

func (*Database) Names

func (db *Database) Names() []string

Returns the names of every table in the database

func (*Database) Schema

func (db *Database) Schema() map[string][]*Column

Returns the complete database schema

func (*Database) Tables

func (db *Database) Tables() map[string]*File

Returns all table of the database

type DefaultConverter

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

func ConverterFromCodePage

func ConverterFromCodePage(codePageMark byte) DefaultConverter

NewDefaultConverterFromCodePage returns a new EncodingConverter from a code page mark

func NewDefaultConverter

func NewDefaultConverter(encoding *charmap.Charmap) DefaultConverter

func (DefaultConverter) CodePage

func (c DefaultConverter) CodePage() byte

CodePageMark returns corresponding code page mark for the encoding

func (DefaultConverter) Decode

func (c DefaultConverter) Decode(in []byte) ([]byte, error)

Decode decodes a specified encoding to byte slice to a UTF8 byte slice

func (DefaultConverter) Encode

func (c DefaultConverter) Encode(in []byte) ([]byte, error)

Decode decodes a UTF8 byte slice to the specified encoding byte slice

type EncodingConverter

type EncodingConverter interface {
	Decode(in []byte) ([]byte, error)
	Encode(in []byte) ([]byte, error)
	CodePage() byte
}

EncodingConverter is an interface for encoding conversion between UTF8 and other encoding

type Error

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

Error is a wrapper for errors that occur in the dbase package

func NewError

func NewError(err string) Error

NewError creates a new Error

func NewErrorf

func NewErrorf(format string, a ...interface{}) Error

func WrapError

func WrapError(err error) Error

func (Error) Details

func (e Error) Details(err error) Error

func (Error) Error

func (e Error) Error() string

type Field

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

Field is a row data field

func (Field) Column

func (field Field) Column() *Column

Column returns the field column definition

func (Field) GetValue

func (field Field) GetValue() interface{}

Value returns the field value

func (Field) Name

func (field Field) Name() string

Name returns the field name

func (*Field) SetValue

func (field *Field) SetValue(value interface{}) error

SetValue allows to change the field value

func (Field) Type

func (field Field) Type() DataType

Type returns the field type

type File

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

File is the main struct to handle a dBase file. Each file type is basically a Table or a Memo file.

func NewTable

func NewTable(version FileVersion, config *Config, columns []*Column, memoBlockSize uint16, io IO) (*File, error)

Create a new DBF file with the specified version, configuration and columns Please only use this for development and testing purposes and dont build new applications with it

func OpenTable

func OpenTable(config *Config) (*File, error)

Opens a dBase database file (and the memo file if needed). The config parameter is required to specify the file path, encoding, file handles (IO) and others. If IO is nil, the default implementation is used depending on the OS.

func (*File) BOF

func (file *File) BOF() bool

Returns if the internal row pointer is before first row

func (*File) BytesToRow

func (file *File) BytesToRow(data []byte) (*Row, error)

Converts raw row data to a Row struct If the data points to a memo (FPT) file this file is also read

func (*File) Close

func (file *File) Close() error

Closes all file handlers.

func (*File) Column

func (file *File) Column(pos int) *Column

Returns the requested column

func (*File) ColumnNames

func (file *File) ColumnNames() []string

Returns a slice of all the column names

func (*File) ColumnPos

func (file *File) ColumnPos(column *Column) int

Returns the column position of a column or -1 if not found.

func (*File) ColumnPosByName

func (file *File) ColumnPosByName(colname string) int

Returns the column position of a column by name or -1 if not found.

func (*File) Columns

func (file *File) Columns() []*Column

Returns all columns

func (*File) ColumnsCount

func (file *File) ColumnsCount() uint16

Returns the number of columns

func (*File) Create

func (file *File) Create() error

Creates a new dBase database file (and the memo file if needed).

func (*File) Deleted

func (file *File) Deleted() (bool, error)

Returns if the row at internal row pointer is deleted

func (*File) EOF

func (file *File) EOF() bool

Returns if the internal row pointer is at end of file

func (*File) GetColumnModification

func (file *File) GetColumnModification(position int) *Modification

Returns the column modification for a column at the given position

func (*File) GetHandle

func (file *File) GetHandle() (interface{}, interface{})

Returns the used file handle (DBF,FPT)

func (*File) GetIO

func (file *File) GetIO() IO

Returns the used IO implementation

func (*File) GoTo

func (file *File) GoTo(row uint32) error

GoTo sets the internal row pointer to row rowNumber Returns and EOF error if at EOF and positions the pointer at lastRow+1

func (*File) Header

func (file *File) Header() *Header

Returns the dBase table file header struct for inspecting

func (*File) Init

func (file *File) Init() error

Write creates the dbase files and writes the header and columns to it

func (*File) Interpret

func (file *File) Interpret(raw []byte, column *Column) (interface{}, error)

Converts raw column data to the correct type for the given column For C and M columns a charset conversion is done For M columns the data is read from the memo file At this moment not all FoxPro column types are supported. When reading column values, the value returned by this package is always `interface{}`.

The supported column types with their return Go types are:

| Column Type | Column Type Name | Golang type | | ----------- | ---------------- | ----------- | | B | Double | float64 | | C | Character | string | | D | Date | time.Time | | F | Float | float64 | | I | Integer | int32 | | L | Logical | bool | | M | Memo | string | | M | Memo (Binary) | []byte | | N | Numeric (0 decimals) | int64 | | N | Numeric (with decimals) | float64 | | T | DateTime | time.Time | | Y | Currency | float64 |

Not all available column types have been implemented because we don't use them in our DBFs

func (*File) NewField

func (file *File) NewField(pos int, value interface{}) (*Field, error)

Creates a new field with the given value and column

func (*File) NewFieldByName

func (file *File) NewFieldByName(name string, value interface{}) (*Field, error)

Creates a new field with the given value and column specified by name

func (*File) NewRow

func (file *File) NewRow() *Row

Returns a new Row struct with the same column structure as the dbf and the next row pointer

func (*File) Next

func (file *File) Next() (*Row, error)

Reads the row and increments the row pointer by one

func (*File) Pointer

func (file *File) Pointer() uint32

Returns the current row pointer position

func (*File) ReadColumns

func (file *File) ReadColumns() ([]*Column, *Column, error)

ReadColumns reads from DBF header, starting at pos 32, until it finds the Header row terminator END_OF_COLUMN(0x0D).

func (*File) ReadHeader

func (file *File) ReadHeader() error

Reads the DBF header from the file handle.

func (*File) ReadMemo

func (file *File) ReadMemo(address []byte) ([]byte, bool, error)

Reads one or more blocks from the FPT file, called for each memo column. the return value is the raw data and true if the data read is text (false is RAW binary data).

func (*File) ReadMemoHeader

func (file *File) ReadMemoHeader() error

ReadMemoHeader reads the memo header from the given file handle.

func (*File) ReadNullFlag

func (file *File) ReadNullFlag(position uint64, column *Column) (bool, bool, error)

Read the nullFlag field at the end of the row The nullFlag field indicates if the field has a variable length If varlength is true, the field is variable length and the length is stored in the last byte If varlength is false, we read the complete field If the field is null, we return true as second return value

func (*File) ReadRow

func (file *File) ReadRow(position uint32) ([]byte, error)

Reads raw row data of one row at rowPosition

func (*File) Represent

func (file *File) Represent(field *Field, padding bool) ([]byte, error)

Represent converts column data to the byte representation of the columns data type For M values the data is written to the memo file and the address is returned

func (*File) Row

func (file *File) Row() (*Row, error)

Returns the requested row at file.rowPointer.

func (*File) RowFromJSON

func (file *File) RowFromJSON(j []byte) (*Row, error)

Converts a JSON-encoded row into the row representation

func (*File) RowFromMap

func (file *File) RowFromMap(m map[string]interface{}) (*Row, error)

Converts a map of interfaces into the row representation

func (*File) RowFromStruct

func (file *File) RowFromStruct(v interface{}) (*Row, error)

Converts a struct into the row representation The struct must have the same field names as the columns in the table or the dbase tag must be set. The dbase tag can be used to name the field. For example: `dbase:"my_field_name"`

func (*File) Rows

func (file *File) Rows(skipInvalid bool, skipDeleted bool) ([]*Row, error)

Returns all rows as a slice

func (*File) RowsCount

func (file *File) RowsCount() uint32

returns the number of rows

func (*File) Search

func (file *File) Search(field *Field, exactMatch bool) ([]*Row, error)

Search searches for a row with the given value in the given field

func (*File) SetColumnModification

func (file *File) SetColumnModification(position int, mod *Modification)

SetColumnModification sets a modification for a column

func (*File) SetColumnModificationByName

func (file *File) SetColumnModificationByName(name string, mod *Modification) error

func (*File) Skip

func (file *File) Skip(offset int64)

Skip adds offset to the internal row pointer If at end of file positions the pointer at lastRow+1 If the row pointer would be become negative positions the pointer at 0 Does not skip deleted rows

func (*File) TableName

func (file *File) TableName() string

func (*File) WriteColumns

func (file *File) WriteColumns() error

WriteColumns writes the columns at the end of header in dbase file

func (*File) WriteHeader

func (file *File) WriteHeader() error

WriteHeader writes the header to the dbase file.

func (*File) WriteMemo

func (file *File) WriteMemo(data []byte, text bool, length int) ([]byte, error)

WriteMemo writes a memo to the memo file and returns the address of the memo.

func (*File) WriteMemoHeader

func (file *File) WriteMemoHeader(size int) error

WriteMemoHeader writes the memo header to the memo file. Size is the number of blocks the new memo data will take up.

func (*File) WriteRow

func (file *File) WriteRow(row *Row) error

WriteRow writes a raw row data to the given row position

type FileExtension

type FileExtension string

Allowed file extensions for the different file types

const (
	DBC FileExtension = ".DBC" // Database file extension
	DCT FileExtension = ".DCT" // Database container file extension
	DBF FileExtension = ".DBF" // Table file extension
	FPT FileExtension = ".FPT" // Memo file extension
	SCX FileExtension = ".SCX" // Form file extension
	LBX FileExtension = ".LBX" // Label file extension
	MNX FileExtension = ".MNX" // Menu file extension
	PJX FileExtension = ".PJX" // Project file extension
	RPX FileExtension = ".RPX" // Report file extension
	VCX FileExtension = ".VCX" // Visual class library file extension
)

type FileVersion

type FileVersion byte

Supported and testet file versions - other files may work but are not tested The file version check has to be bypassed when opening a file type that is not supported https://learn.microsoft.com/en-us/previous-versions/visualstudio/foxpro/st4a0s68(v=vs.71)

const (
	FoxPro              FileVersion = 0x30
	FoxProAutoincrement FileVersion = 0x31
	FoxProVar           FileVersion = 0x32
)

Supported and testet file types - other file types may work but are not tested

const (
	FoxBase         FileVersion = 0x02
	FoxBase2        FileVersion = 0xFB
	FoxBasePlus     FileVersion = 0x03
	DBaseSQLTable   FileVersion = 0x43
	FoxBasePlusMemo FileVersion = 0x83
	DBaseMemo       FileVersion = 0x8B
	DBaseSQLMemo    FileVersion = 0xCB
	FoxPro2Memo     FileVersion = 0xF5
)

Not tested

type GenericIO

type GenericIO struct {
	Handle        io.ReadWriteSeeker
	RelatedHandle io.ReadWriteSeeker
}

GenericIO implements the IO interface for generic io.ReadWriteSeeker. Handle is the main file handle, relatedHandle is the memo file handle.

func (GenericIO) Close

func (g GenericIO) Close(file *File) error

func (GenericIO) Create

func (g GenericIO) Create(file *File) error

func (GenericIO) Deleted

func (g GenericIO) Deleted(file *File) (bool, error)

func (GenericIO) GoTo

func (g GenericIO) GoTo(file *File, row uint32) error

func (GenericIO) OpenTable

func (g GenericIO) OpenTable(config *Config) (*File, error)

func (GenericIO) ReadColumns

func (g GenericIO) ReadColumns(file *File) ([]*Column, *Column, error)

func (GenericIO) ReadHeader

func (g GenericIO) ReadHeader(file *File) error

func (GenericIO) ReadMemo

func (g GenericIO) ReadMemo(file *File, address []byte) ([]byte, bool, error)

func (GenericIO) ReadMemoHeader

func (g GenericIO) ReadMemoHeader(file *File) error

func (GenericIO) ReadNullFlag

func (g GenericIO) ReadNullFlag(file *File, position uint64, column *Column) (bool, bool, error)

func (GenericIO) ReadRow

func (g GenericIO) ReadRow(file *File, position uint32) ([]byte, error)

func (GenericIO) Search

func (g GenericIO) Search(file *File, field *Field, exactMatch bool) ([]*Row, error)

func (GenericIO) Skip

func (g GenericIO) Skip(file *File, offset int64)

func (GenericIO) WriteColumns

func (g GenericIO) WriteColumns(file *File) error

func (GenericIO) WriteHeader

func (g GenericIO) WriteHeader(file *File) error

func (GenericIO) WriteMemo

func (g GenericIO) WriteMemo(file *File, raw []byte, text bool, length int) ([]byte, error)

func (GenericIO) WriteMemoHeader

func (g GenericIO) WriteMemoHeader(file *File, size int) error

func (GenericIO) WriteRow

func (g GenericIO) WriteRow(file *File, row *Row) error
type Header struct {
	FileType   byte     // File type flag
	Year       uint8    // Last update year (0-99)
	Month      uint8    // Last update month
	Day        uint8    // Last update day
	RowsCount  uint32   // Number of rows in file
	FirstRow   uint16   // Position of first data row
	RowLength  uint16   // Length of one data row, including delete flag
	Reserved   [16]byte // Reserved
	TableFlags byte     // Table flags
	CodePage   byte     // Code page mark
}

Containing DBF header information like dBase FileType, last change and rows count. https://docs.microsoft.com/en-us/previous-versions/visualstudio/foxpro/st4a0s68(v=vs.80)#table-header-record-structure

func (*Header) ColumnsCount

func (h *Header) ColumnsCount() uint16

Returns the calculated number of columns from the header info alone (without the need to read the columninfo from the header). This is the fastest way to determine the number of rows in the file.

func (*Header) FileSize

func (h *Header) FileSize() int64

Returns the calculated file size based on the header info

func (*Header) Modified

func (h *Header) Modified(base int) time.Time

Parses the year, month and day to time.Time. The year is stored in decades (2 digits) and added to the base century (2000). Note: we assume the year is between 2000 and 2099 as default.

func (*Header) RecordsCount

func (h *Header) RecordsCount() uint32

Returns the amount of records in the table

type IO

type IO interface {
	OpenTable(config *Config) (*File, error)
	Close(file *File) error
	Create(file *File) error
	ReadHeader(file *File) error
	WriteHeader(file *File) error
	ReadColumns(file *File) ([]*Column, *Column, error)
	WriteColumns(file *File) error
	ReadMemoHeader(file *File) error
	WriteMemoHeader(file *File, size int) error
	ReadMemo(file *File, address []byte) ([]byte, bool, error)
	WriteMemo(file *File, raw []byte, text bool, length int) ([]byte, error)
	ReadNullFlag(file *File, position uint64, column *Column) (bool, bool, error)
	ReadRow(file *File, position uint32) ([]byte, error)
	WriteRow(file *File, row *Row) error
	Search(file *File, field *Field, exactMatch bool) ([]*Row, error)
	GoTo(file *File, row uint32) error
	Skip(file *File, offset int64)
	Deleted(file *File) (bool, error)
}

IO is the interface to work with the DBF file. Three implementations are available: - WindowsIO (for direct file access with Windows) - UnixIO (for direct file access with Unix) - GenericIO (for any custom file access implementing io.ReadWriteSeeker)

type Marker

type Marker byte

Important byte marker for the dbase file

const (
	Null      Marker = 0x00
	Blank     Marker = 0x20
	ColumnEnd Marker = 0x0D
	Active    Marker = Blank
	Deleted   Marker = 0x2A
	EOFMarker Marker = 0x1A
)

type MemoHeader

type MemoHeader struct {
	NextFree  uint32  // Location of next free block
	Unused    [2]byte // Unused
	BlockSize uint16  // Block size (bytes per block)
}

The raw header of the Memo file.

type Modification

type Modification struct {
	TrimSpaces  bool                                   // Trim spaces from string values
	Convert     func(interface{}) (interface{}, error) // Conversion function to convert the value
	ExternalKey string                                 // External key to use for the column
}

Modification allows to change the column name or value type of a column when reading the table The TrimSpaces option is only used for a specific column, if the general TrimSpaces option in the config is false.

type Row

type Row struct {
	Position   uint32 // Position of the row in the file
	ByteOffset int64  // Byte offset of the row in the file
	Deleted    bool   // Deleted flag
	// contains filtered or unexported fields
}

Row is a struct containing the row Position, deleted flag and data fields

func (*Row) Add

func (row *Row) Add() error

Appends the row as a new entry to the file

func (*Row) BoolValueByName

func (row *Row) BoolValueByName(name string) (bool, error)

Returns the value of a row at the given column name as a bool If the value is not a bool, an error is returned

func (*Row) BytesValueByName

func (row *Row) BytesValueByName(name string) ([]byte, error)

Returns the value of a row at the given column name as a []byte If the value is not a []byte, []uint8 or string, an error is returned

func (*Row) Field

func (row *Row) Field(pos int) *Field

Returns the field of a row by position or nil if not found

func (*Row) FieldByName

func (row *Row) FieldByName(name string) *Field

Returns the field of a row by name or nil if not found

func (*Row) Fields

func (row *Row) Fields() []*Field

Returns all fields of the current row

func (*Row) FloatValueByName

func (row *Row) FloatValueByName(name string) (float64, error)

Returns the value of a row at the given column name as a float64 If the value is not castable to a float64, an error is returned

func (*Row) Increment

func (row *Row) Increment() error

Increment increases set the value of the auto increment Column to the Next value Also increases the Next value by the amount of Step Rewrites the columns header

func (*Row) IntValueByName

func (row *Row) IntValueByName(name string) (int64, error)

Returns the value of a row at the given column name as an int64 If the value is not castable to an int64, an error is returned

func (*Row) MustBoolValueByName

func (row *Row) MustBoolValueByName(name string) bool

Returns the value of a row at the given column name as a bool MustBoolValueByName panics if the value is not found or not a bool

func (*Row) MustBytesValueByName

func (row *Row) MustBytesValueByName(name string) []byte

Returns the value of a row at the given column name as a []byte MustBytesValueByName panics if the value is not found or not a []byte

func (*Row) MustFloatValueByName

func (row *Row) MustFloatValueByName(name string) float64

Returns the value of a row at the given column name as a float64 MustFloatValueByName panics if the value is not found or not a float64

func (*Row) MustIntValueByName

func (row *Row) MustIntValueByName(name string) int64

Returns the value of a row at the given column name as an int32 MustIntValueByName panics if the value is not found or not an int32

func (*Row) MustStringValueByName

func (row *Row) MustStringValueByName(name string) string

Returns the value of a row at the given column name as a string MustStringValueByName panics if the value is not found or not a string

func (*Row) MustTimeValueByName

func (row *Row) MustTimeValueByName(name string) time.Time

Returns the value of a row at the given column name as a time.Time MustTimeValueByName panics if the value is not found or not a time.Time

func (*Row) MustValueByName

func (row *Row) MustValueByName(name string) interface{}

Returns the value of a row at the given column name MustValueByName panics if the value is not found

func (*Row) StringValueByName

func (row *Row) StringValueByName(name string) (string, error)

Returns the value of a row at the given column name as a string If the value is neither a string nor a byte slice, an error is returned

func (*Row) TimeValueByName

func (row *Row) TimeValueByName(name string) (time.Time, error)

Returns the value of a row at the given column name as a time.Time If the value is not a time.Time, an error is returned

func (*Row) ToBytes

func (row *Row) ToBytes() ([]byte, error)

Converts the row back to raw dbase data

func (*Row) ToJSON

func (row *Row) ToJSON() ([]byte, error)

Returns a complete row as a JSON object.

func (*Row) ToMap

func (row *Row) ToMap() (map[string]interface{}, error)

Returns a complete row as a map.

func (*Row) ToStruct

func (row *Row) ToStruct(v interface{}) error

Converts a row to a struct. The struct must have the same field names as the columns in the table or the dbase tag must be set. dbase tags can be used to name the field. For example: `dbase:"<table_name>.<field_name>"` or `dbase:"<field_name>"`

func (*Row) Value

func (row *Row) Value(pos int) interface{}

Returns the value of a row at the given position

func (*Row) ValueByName

func (row *Row) ValueByName(name string) (interface{}, error)

Returns the value of a row at the given column name

func (*Row) Values

func (row *Row) Values() []interface{}

Returns all values of a row as a slice of interface{}

func (*Row) Write

func (row *Row) Write() error

Writes the row to the file at the row pointer position

type Table

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

Table is a struct containing the table columns, modifications and the row pointer

type TableFlag

type TableFlag byte

Table flags inidicate the type of the table https://learn.microsoft.com/en-us/previous-versions/visualstudio/foxpro/st4a0s68(v=vs.71)

const (
	StructuralFlag TableFlag = 0x01
	MemoFlag       TableFlag = 0x02
	DatabaseFlag   TableFlag = 0x04
)

func (TableFlag) Defined

func (t TableFlag) Defined(flag byte) bool

type UnixIO

type UnixIO struct{}

UnixIO implements the IO interface for unix systems.

var DefaultIO UnixIO

func (UnixIO) Close

func (u UnixIO) Close(file *File) error

func (UnixIO) Create

func (u UnixIO) Create(file *File) error

func (UnixIO) Deleted

func (u UnixIO) Deleted(file *File) (bool, error)

func (UnixIO) GoTo

func (u UnixIO) GoTo(file *File, row uint32) error

func (UnixIO) OpenTable

func (u UnixIO) OpenTable(config *Config) (*File, error)

func (UnixIO) ReadColumns

func (u UnixIO) ReadColumns(file *File) ([]*Column, *Column, error)

func (UnixIO) ReadHeader

func (u UnixIO) ReadHeader(file *File) error

func (UnixIO) ReadMemo

func (u UnixIO) ReadMemo(file *File, blockdata []byte) ([]byte, bool, error)

func (UnixIO) ReadMemoHeader

func (u UnixIO) ReadMemoHeader(file *File) error

func (UnixIO) ReadNullFlag

func (u UnixIO) ReadNullFlag(file *File, rowPosition uint64, column *Column) (bool, bool, error)

func (UnixIO) ReadRow

func (u UnixIO) ReadRow(file *File, position uint32) ([]byte, error)

func (UnixIO) Search

func (u UnixIO) Search(file *File, field *Field, exactMatch bool) ([]*Row, error)

func (UnixIO) Skip

func (u UnixIO) Skip(file *File, offset int64)

func (UnixIO) WriteColumns

func (u UnixIO) WriteColumns(file *File) error

func (UnixIO) WriteHeader

func (u UnixIO) WriteHeader(file *File) error

func (UnixIO) WriteMemo

func (u UnixIO) WriteMemo(file *File, raw []byte, text bool, length int) ([]byte, error)

func (UnixIO) WriteMemoHeader

func (u UnixIO) WriteMemoHeader(file *File, size int) error

func (UnixIO) WriteRow

func (u UnixIO) WriteRow(file *File, row *Row) error

Jump to

Keyboard shortcuts

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