value

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: MIT Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package value decodes field values from unpacked records, using the field descriptors stored in RDB$FORMATS, and formats them for output.

Index

Constants

View Source
const (
	TypeText        = 1
	TypeVarying     = 3
	TypeShort       = 8
	TypeLong        = 9
	TypeQuad        = 10
	TypeReal        = 11
	TypeDouble      = 12
	TypeDate        = 14
	TypeTime        = 15
	TypeTimestamp   = 16
	TypeBlob        = 17
	TypeArray       = 18
	TypeInt64       = 19
	TypeBoolean     = 21
	TypeDec64       = 22
	TypeDec128      = 23
	TypeInt128      = 24
	TypeTimeTZ      = 25
	TypeTimestampTZ = 26
)

Physical data types (dsc_dtype).

View Source
const DescriptorSize = 12

DescriptorSize is the on-disk size of a Field.

Variables

This section is empty.

Functions

func Alignment

func Alignment(dtype uint8) uint32

Alignment is the engine's alignment of a field of type dtype in a record: fields are laid out in field id order after the null bitmap, each at the next multiple of its alignment. Checked against every record format in the corpus.

func BytesPerChar

func BytesPerChar(id int) int

BytesPerChar returns the maximum bytes per character of a character set.

func CharsetByName

func CharsetByName(name string) (int, bool)

CharsetByName finds a character set id by its Firebird name, ignoring case.

func CharsetName

func CharsetName(id int) string

CharsetName returns the Firebird name of a character set id.

func Convert

func Convert(v any, to Field) (any, error)

Convert converts a value read with an older format of a column to the column's current type, as the engine does when it reads old records. Only conversions that ALTER COLUMN TYPE allows between the types fbrescue decodes are supported.

func Decodable

func Decodable(id int) bool

Decodable reports whether text in this character set is converted to UTF-8 (true) or may be passed through as raw bytes (false).

func Decode

func Decode(rec []byte, f Field, opt Options) (any, error)

Decode returns the value of field f in record rec: nil for NULL, or one of Decimal, BigDecimal, DecFloat, float32, float64, Date, Time, Timestamp, TimeTZ, TimestampTZ, Text, Octets, bool, BlobRef.

func DecodeBytes

func DecodeBytes(b []byte, f Field, opt Options) (any, error)

DecodeBytes decodes a value stored in b (exactly f.Length bytes).

func IsNull

func IsNull(rec []byte, f Field) bool

IsNull reports whether field f is NULL in record rec.

Types

type BigDecimal

type BigDecimal struct {
	Int   *big.Int
	Scale int8
}

BigDecimal is an INT128 or NUMERIC/DECIMAL(19..38): Int * 10^Scale.

func (BigDecimal) IsMin

func (d BigDecimal) IsMin() bool

IsMin reports the most negative INT128, whose literal does not parse.

func (BigDecimal) String

func (d BigDecimal) String() string

String formats with exactly -Scale fraction digits.

type BlobRef

type BlobRef struct {
	Relation uint16
	Number   uint64 // record number of the blob header
	SubType  int16  // 1 text, 0 binary, others user-defined
	Charset  int    // text blobs
}

BlobRef is a blob id field; the blob is read separately.

type Date

type Date int32

Date is days since 1858-11-17.

func (Date) String

func (d Date) String() string

String formats a date as YYYY-MM-DD.

type DecFloat

type DecFloat string

DecFloat is a DECFLOAT value, formatted as decNumber's to-scientific-string does (and as Firebird shows it).

func (DecFloat) String

func (d DecFloat) String() string

type Decimal

type Decimal struct {
	Int   int64
	Scale int8
}

Decimal is an exact number: Int * 10^Scale, Scale <= 0.

func (Decimal) Float

func (d Decimal) Float() float64

Float returns the value as float64.

func (Decimal) String

func (d Decimal) String() string

String formats a Decimal with exactly -Scale fraction digits.

type Field

type Field struct {
	ID      int // position in the format; also the bit in the null bitmap
	DType   uint8
	Scale   int8
	Length  uint16
	SubType int16 // text: character set (low byte) and collation; numbers: 1 NUMERIC, 2 DECIMAL
	Flags   uint16
	Offset  uint32 // 0: not stored (computed field)
}

Field is one entry of a record format (Ods::Descriptor): 12 bytes on disk.

func ParseField

func ParseField(id int, b []byte) Field

ParseField decodes a 12-byte descriptor.

func (Field) CharLength

func (f Field) CharLength() int

CharLength is the declared length in characters of a text field.

func (Field) Charset

func (f Field) Charset() int

Charset is the character set id of a text field.

func (Field) SQLType

func (f Field) SQLType() string

SQLType returns the column type for CREATE TABLE. Precision of NUMERIC and DECIMAL is not stored in the format; the maximum for the storage size is used, so every stored value fits.

func (Field) Stored

func (f Field) Stored() bool

Stored reports whether the field has bytes in the record: dropped columns have type 0 and computed ones offset 0.

func (Field) Supported

func (f Field) Supported() bool

Supported reports whether values of this type can be decoded.

type Octets

type Octets []byte

Octets is binary data from a CHARACTER SET OCTETS field.

type Options

type Options struct {
	// NoneCharset decodes CHARACTER SET NONE text with this character set
	// id instead of passing the bytes through. 0 means pass through.
	NoneCharset int
}

Options controls decoding.

type Text

type Text struct {
	S   string
	Raw bool
}

Text is a decoded string. Raw is set when the bytes could not be decoded to UTF-8 (unknown character set, or NONE with non-UTF-8 bytes); the string then holds the original bytes.

func DecodeText

func DecodeText(b []byte, cs int, opt Options) Text

DecodeText converts text in character set cs to UTF-8.

type Time

type Time uint32

Time is 1/10000 seconds since midnight.

func (Time) String

func (t Time) String() string

String formats a time as HH:MM:SS.FFFF.

type TimeTZ

type TimeTZ struct {
	UTC  Time
	Zone uint16
}

TimeTZ is a TIME WITH TIME ZONE: UTC time of day and a zone.

func (TimeTZ) Format

func (t TimeTZ) Format() (string, error)

Format shows the local time and the zone, as SELECT does.

type Timestamp

type Timestamp struct {
	Date Date
	Time Time
}

Timestamp is a date and a time.

func (Timestamp) String

func (t Timestamp) String() string

String formats a timestamp as YYYY-MM-DD HH:MM:SS.FFFF.

type TimestampTZ

type TimestampTZ struct {
	UTC  Timestamp
	Zone uint16
}

TimestampTZ is a TIMESTAMP WITH TIME ZONE: UTC timestamp and a zone.

func (TimestampTZ) Format

func (t TimestampTZ) Format() (string, error)

Format shows the local timestamp and the zone, as SELECT does.

Jump to

Keyboard shortcuts

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