gomdb

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: May 31, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package gomdb is a pure Go implementation of an MDB (Microsoft Access) file reader. It provides the same capabilities as the C-based cmdb driver but without CGo dependencies.

The public API mirrors cmdb.Query for easy driver integration.

Package gomdb is a pure Go implementation of an MDB (Microsoft Access) file reader. It provides the same capabilities as the C-based mdbtools but without CGo dependencies.

Index

Constants

View Source
const (
	PageDB    = 0
	PageData  = 1
	PageTable = 2
	PageIndex = 3
	PageLeaf  = 4
	PageMap   = 5
)

Page types

View Source
const (
	Jet3      = 0
	Jet4      = 1
	Accdb2007 = 2
	Accdb2010 = 3
	Accdb2013 = 4
	Accdb2016 = 5
	Accdb2019 = 6
)

Jet version constants

View Source
const (
	ObjForm             = 0
	ObjTable            = 1
	ObjMacro            = 2
	ObjSystemTable      = 3
	ObjReport           = 4
	ObjQuery            = 5
	ObjLinkedTable      = 6
	ObjModule           = 7
	ObjRelationship     = 8
	ObjUnknown09        = 9
	ObjUnknown0A        = 10
	ObjDatabaseProperty = 11
	ObjAny              = -1
)

Object types

View Source
const (
	TypeBool     = 0x01
	TypeByte     = 0x02
	TypeInt      = 0x03
	TypeLongInt  = 0x04
	TypeMoney    = 0x05
	TypeFloat    = 0x06
	TypeDouble   = 0x07
	TypeDateTime = 0x08
	TypeBinary   = 0x09
	TypeText     = 0x0a
	TypeOLE      = 0x0b
	TypeMemo     = 0x0c
	TypeRepID    = 0x0f
	TypeNumeric  = 0x10
	TypeComplex  = 0x12
)

Column data types

View Source
const (
	OpOr      = 1
	OpAnd     = 2
	OpNot     = 3
	OpEqual   = 4
	OpGT      = 5
	OpLT      = 6
	OpGTEQ    = 7
	OpLTEQ    = 8
	OpLike    = 9
	OpIsNull  = 10
	OpNotNull = 11
	OpILike   = 12
	OpNEQ     = 13
)

Search argument operators

View Source
const (
	IdxUnique      = 0x01
	IdxIgnoreNulls = 0x02
	IdxRequired    = 0x08

	Asc  = 0
	Desc = 1

	MaxIdxCols   = 10
	MaxObjName   = 256
	MaxCols      = 256
	PageSize     = 4096
	MemoOverhead = 12
	BindSize     = 16384

	OffsetMask = 0x1fff
)

Index-related

View Source
const (
	TableScan = iota
	LeafScan
	IndexScan
)

Scan strategies

View Source
const (
	UUIDBraces4228   = 0
	UUIDNoBraces4226 = 1
)

UUID format

Variables

View Source
var Jet3FormatConstants = MdbFormatConstants{
	PgSize:             2048,
	RowCountOffset:     0x08,
	TabNumRowsOffset:   12,
	TabNumColsOffset:   25,
	TabNumIdxsOffset:   27,
	TabNumRidxsOffset:  31,
	TabUsageMapOffset:  35,
	TabFirstDpgOffset:  36,
	TabColsStartOffset: 43,
	TabRidxEntrySize:   8,
	ColScaleOffset:     9,
	ColPrecOffset:      10,
	ColFlagsOffset:     13,
	ColSizeOffset:      16,
	ColNumOffset:       1,
	TabColEntrySize:    18,
	TabFreeMapOffset:   39,
	TabColOffsetVar:    3,
	TabColOffsetFixed:  14,
	TabRowColNumOffset: 5,
}

Jet3FormatConstants are the format offsets for Jet 3 (Access 97) databases.

View Source
var Jet4FormatConstants = MdbFormatConstants{
	PgSize:             4096,
	RowCountOffset:     0x0c,
	TabNumRowsOffset:   16,
	TabNumColsOffset:   45,
	TabNumIdxsOffset:   47,
	TabNumRidxsOffset:  51,
	TabUsageMapOffset:  55,
	TabFirstDpgOffset:  56,
	TabColsStartOffset: 63,
	TabRidxEntrySize:   12,
	ColScaleOffset:     11,
	ColPrecOffset:      12,
	ColFlagsOffset:     15,
	ColSizeOffset:      23,
	ColNumOffset:       5,
	TabColEntrySize:    25,
	TabFreeMapOffset:   59,
	TabColOffsetVar:    7,
	TabColOffsetFixed:  21,
	TabRowColNumOffset: 9,
}

Jet4FormatConstants are the format offsets for Jet 4 (Access 2000+) databases.

Functions

func ASCIItoUCS2

func ASCIItoUCS2(src string) []byte

ASCIItoUCS2 converts an ASCII/UTF-8 string to UCS-2LE bytes, used for temp table field packing in LIST TABLES and DESCRIBE TABLE commands.

func ASCIItoUCS2Len

func ASCIItoUCS2Len(src []byte) ([]byte, int)

ASCIItoUCS2Len is like ASCIItoUCS2 but takes a byte slice and returns UCS-2LE bytes along with their length.

func ColDispSize

func ColDispSize(colType, colSize int) int

ColDispSize returns the display size for a column type.

func ColFixedSize

func ColFixedSize(colType int) int

ColFixedSize returns the fixed byte size for a column type, or -1 if variable.

func ColIsShortDate

func ColIsShortDate(col *MdbColumn) bool

ColIsShortDate checks if a DateTime column is formatted as a short date.

func ColTypeName

func ColTypeName(typ int) string

ColTypeName returns the Access type name for a column type constant.

func DateToTime

func DateToTime(td float64) time.Time

DateToTime converts an Access date double to a time.Time. The integer part is days since 12/30/1899. The fractional part is the fraction of a day.

func FillTempCol

func FillTempCol(col *MdbColumn, name string, colSize, colType int, isFixed bool)

FillTempCol fills a MdbColumn with the specified attributes.

func FillTempField

func FillTempField(field *MdbField, value []byte, siz int, isFixed bool, isNull bool, start int, colNum int)

FillTempField fills a MdbField with the specified attributes.

func GetByte

func GetByte(buf []byte, offset int) byte

GetByte reads a single byte at offset from a buffer.

func GetDouble

func GetDouble(buf []byte, offset int) float64

GetDouble reads a 64-bit IEEE 754 double (little-endian) at offset from a buffer.

func GetInt16

func GetInt16(buf []byte, offset int) int

GetInt16 reads a little-endian signed 16-bit integer at offset from a buffer.

func GetInt32

func GetInt32(buf []byte, offset int) int

GetInt32 reads a little-endian signed 32-bit integer at offset from a buffer.

func GetInt32MSB

func GetInt32MSB(buf []byte, offset int) int

GetInt32MSB reads a big-endian (MSB) 32-bit integer at offset from a buffer.

func GetSingle

func GetSingle(buf []byte, offset int) float32

GetSingle reads a 32-bit IEEE 754 float (little-endian) at offset from a buffer.

func GetUint16

func GetUint16(buf []byte, offset int) uint16

GetUint16 reads a little-endian unsigned 16-bit integer at offset from a buffer.

func GetUint32

func GetUint32(buf []byte, offset int) uint32

GetUint32 reads a little-endian unsigned 32-bit integer at offset from a buffer.

func ILikeCmp

func ILikeCmp(s, r string) bool

ILikeCmp tests whether string s matches the SQL LIKE pattern r, case-insensitively using Unicode case folding.

func IsLogicalOp

func IsLogicalOp(op int) bool

IsLogicalOp returns true if the operator is a logical connective (AND, OR, NOT).

func IsRelationalOp

func IsRelationalOp(op int) bool

IsRelationalOp returns true if the operator is a comparison operator.

func IsSystemTable

func IsSystemTable(entry *CatalogEntry) bool

IsSystemTable returns true if this is a system table.

func IsUserTable

func IsUserTable(entry *CatalogEntry) bool

IsUserTable returns true if this is a user table (not system, not linked).

func Jet3CodePageToUTF8

func Jet3CodePageToUTF8(src []byte, codePage uint16) string

Jet3CodePageToUTF8 converts a Jet3 string using the specified code page to UTF-8. Currently supports common code pages. For unsupported code pages, falls back to Latin-1.

In a full implementation, this would use golang.org/x/text/encoding/charmap. For now we handle the most common case: code page 1252 (Windows Latin-1).

func LikeCmp

func LikeCmp(s, r string) bool

LikeCmp tests whether string s matches the SQL LIKE pattern r. In the pattern:

  • '%' matches any sequence of zero or more characters
  • '_' matches exactly one character
  • All other characters match literally (case-sensitive)

Returns true if s matches the pattern.

func MoneyToString

func MoneyToString(buf []byte, offset int) string

MoneyToString converts an 8-byte Currency field to a string. Currency is stored as an 8-byte signed integer scaled by 10^4. Negative values use two's complement.

func NumericToString

func NumericToString(buf []byte, start int, scale, prec int) string

NumericToString converts a 16-byte Numeric field to a string. The first byte contains a sign flag (0x80 = negative). The remaining 16 bytes are stored in a specific byte order.

func ObjTypeName

func ObjTypeName(typ int) string

ObjTypeName returns the human-readable name for an object type constant.

func ParseFloat

func ParseFloat(s string) (float64, bool)

ParseFloat parses a string as a float64. Returns (value, true) on success.

func ParseInt

func ParseInt(s string) (int64, bool)

ParseInt parses a string as an int64. Returns (value, true) on success.

func TestSargs

func TestSargs(mdb *MdbHandle, table *MdbTableDef, fields []MdbField) bool

TestSargs evaluates the sarg tree against the provided fields. Returns true if the row passes all conditions.

func TmToDate

func TmToDate(t time.Time) float64

TmToDate converts a time.Time to an Access date double.

func UnicodeToUTF8

func UnicodeToUTF8(src []byte, isJet4 bool) string

UnicodeToUTF8 converts an Access string (possibly Unicode Compressed) to a UTF-8 string. For Jet4 databases, the text may be prefixed with 0xFF 0xFE to indicate compression. For Jet3 databases, text is typically single-byte in the database code page.

Parameters:

  • src: raw byte data from the database
  • isJet4: true if Jet4 database, false if Jet3

Returns the UTF-8 string.

func UnicodeToUTF8Len

func UnicodeToUTF8Len(src []byte, isJet4 bool) (string, int)

UnicodeToUTF8Len converts bytes and returns both the UTF-8 string and its byte length.

Types

type CatalogEntry

type CatalogEntry struct {
	Mdb        *MdbHandle
	ObjectName string
	ObjectType int
	TablePg    uint32
	Flags      int
	Props      []*Properties
}

CatalogEntry represents an entry in the MSysObjects catalog table.

type Column

type Column struct {
	Name         string
	DatabaseType string
	Type         int
	Size         int64
}

Column represents metadata about a single column in a query result.

type Error

type Error struct {
	Msg string
}

Error implements the error interface for gomdb errors.

func (*Error) Error

func (e *Error) Error() string

type IndexChain

type IndexChain struct {
	CurDepth      int
	LastLeafFound uint32
	CleanUpMode   int
	Pages         [10]*MdbIndexPage
}

IndexChain tracks state while walking an index's B-tree.

type MdbAny

type MdbAny struct {
	I int
	D float64
	S string
}

MdbAny is a union type for sarg values.

type MdbColumn

type MdbColumn struct {
	Table    *MdbTableDef
	Name     string
	ColType  int
	ColSize  int
	ColNum   int
	ColPrec  int
	ColScale int

	IsFixed     bool
	IsLongAuto  bool
	IsUUIDAuto  bool
	FixedOffset int
	VarColNum   int
	RowColNum   int

	// Sargs for this column
	Sargs []*MdbSarg

	// Current row value state
	CurValueStart  int
	CurValueLen    int
	CurValueIsNull bool
	CurBlobPgRow   uint32
	ChunkSize      int

	// Binding
	BindPtr []byte
	LenPtr  *int

	// Column properties
	Props *Properties
}

MdbColumn represents a column in an Access table.

type MdbField

type MdbField struct {
	Value   []byte
	Siz     int
	Start   int
	IsNull  bool
	IsFixed bool
	ColNum  int
	Offset  int
}

MdbField represents a parsed field value from a row.

type MdbFile

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

MdbFile represents an open MDB database file.

type MdbFormatConstants

type MdbFormatConstants struct {
	PgSize             int
	RowCountOffset     int
	TabNumRowsOffset   int
	TabNumColsOffset   int
	TabNumIdxsOffset   int
	TabNumRidxsOffset  int
	TabUsageMapOffset  int
	TabFirstDpgOffset  int
	TabColsStartOffset int
	TabRidxEntrySize   int
	ColScaleOffset     int
	ColPrecOffset      int
	ColFlagsOffset     int
	ColSizeOffset      int
	ColNumOffset       int
	TabColEntrySize    int
	TabFreeMapOffset   int
	TabColOffsetVar    int
	TabColOffsetFixed  int
	TabRowColNumOffset int
}

MdbFormatConstants holds Jet-version-dependent offsets for reading table/page metadata.

type MdbHandle

type MdbHandle struct {
	Catalog []*CatalogEntry
	// contains filtered or unexported fields
}

MdbHandle holds all state for reading an MDB database.

func OpenMDB

func OpenMDB(filename string) (*MdbHandle, error)

OpenMDB opens an MDB file at the given path and returns a handle.

func (*MdbHandle) AddRowToTempTable

func (mdb *MdbHandle) AddRowToTempTable(table *MdbTableDef, rowData []byte, rowSize int)

AddRowToTempTable adds a row to a temporary table's page buffer.

func (*MdbHandle) BinaryValue

func (mdb *MdbHandle) BinaryValue(col *MdbColumn) []byte

BinaryValue returns the raw bytes for a binary column.

func (*MdbHandle) Close

func (mdb *MdbHandle) Close() error

Close closes the MDB handle and releases resources.

func (*MdbHandle) CodePage

func (mdb *MdbHandle) CodePage() uint16

CodePage returns the database code page.

func (*MdbHandle) CrackRow

func (mdb *MdbHandle) CrackRow(table *MdbTableDef, rowStart, rowSize int) ([]MdbField, error)

CrackRow parses a raw row into individual fields. This is a direct port of mdb_crack_row from mdbtools write.c.

func (*MdbHandle) CreateTempTable

func (mdb *MdbHandle) CreateTempTable(name string) *MdbTableDef

CreateTempTable creates a temporary table (used for LIST TABLES, DESCRIBE TABLE).

func (*MdbHandle) DateTimeValue

func (mdb *MdbHandle) DateTimeValue(col *MdbColumn) (time.Time, bool)

DateTimeValue returns the time.Time for a DateTime column.

func (*MdbHandle) DescribeTable

func (mdb *MdbHandle) DescribeTable(sql *SQL, tableName string) error

DescribeTable implements the "DESCRIBE TABLE name" SQL command.

func (*MdbHandle) FetchRow

func (mdb *MdbHandle) FetchRow(table *MdbTableDef) (bool, error)

FetchRow reads the next matching row from a table. Returns true if a row was read, false if no more rows.

func (*MdbHandle) Fmt

func (mdb *MdbHandle) Fmt() *MdbFormatConstants

Fmt returns the format constants for this database.

func (*MdbHandle) FreeTableDef

func (mdb *MdbHandle) FreeTableDef(table *MdbTableDef)

FreeTableDef frees a table definition and associated resources.

func (*MdbHandle) GetBoundValue

func (mdb *MdbHandle) GetBoundValue(table *MdbTableDef, idx int) string

GetBoundValue returns the bound string value for a column index.

func (*MdbHandle) GetCatalogEntryByName

func (mdb *MdbHandle) GetCatalogEntryByName(name string) *CatalogEntry

GetCatalogEntryByName finds a catalog entry by name (case-insensitive).

func (*MdbHandle) IsJet3

func (mdb *MdbHandle) IsJet3() bool

IsJet3 returns true if the database is Jet3 (Access 97) format.

func (*MdbHandle) IsJet4

func (mdb *MdbHandle) IsJet4() bool

IsJet4 returns true if the database is Jet4 (Access 2000+) format.

func (*MdbHandle) ListTables

func (mdb *MdbHandle) ListTables(sql *SQL) error

ListTables implements the "LIST TABLES" SQL command.

func (*MdbHandle) OleReadFull

func (mdb *MdbHandle) OleReadFull(col *MdbColumn, bindBuf []byte) ([]byte, int, error)

OleReadFull reads the complete OLE field data.

func (*MdbHandle) OpenQuery

func (mdb *MdbHandle) OpenQuery(query string) (*SQL, error)

OpenQuery executes a SQL query against the database.

func (*MdbHandle) PackRow

func (mdb *MdbHandle) PackRow(table *MdbTableDef, rowBuf []byte, numFields int, fields []MdbField) int

PackRow packs fields into a Jet4 row buffer for a temp table. The row format matches what CrackRow (mdb_crack_row) expects:

[2 bytes: total col count] [fixed data] [var data] [var offsets+count] [null mask]

func (*MdbHandle) PgGetByte

func (mdb *MdbHandle) PgGetByte() byte

PgGetByte reads a single byte at the current position, advancing it by 1.

func (*MdbHandle) PgGetFirstByte

func (mdb *MdbHandle) PgGetFirstByte() byte

PgGetFirstByte returns the first byte of the current page.

func (*MdbHandle) PgGetInt16

func (mdb *MdbHandle) PgGetInt16() int

PgGetInt16 reads a little-endian 16-bit integer at the current position, advancing by 2.

func (*MdbHandle) PgGetInt32

func (mdb *MdbHandle) PgGetInt32() int

PgGetInt32 reads a little-endian 32-bit integer at the current position, advancing by 4.

func (*MdbHandle) PgGetInt32MSB

func (mdb *MdbHandle) PgGetInt32MSB() int

PgGetInt32MSB reads a big-endian 32-bit integer at the current position, advancing by 4.

func (*MdbHandle) ReadCatalog

func (mdb *MdbHandle) ReadCatalog(objType int) error

ReadCatalog reads the MSysObjects table and populates the catalog. If objType is ObjAny, all object types are included.

func (*MdbHandle) ReadColumns

func (mdb *MdbHandle) ReadColumns(table *MdbTableDef) error

ReadColumns reads the column definitions for a table.

func (*MdbHandle) ReadIndices

func (mdb *MdbHandle) ReadIndices(table *MdbTableDef) error

ReadIndices reads the index definitions for a table.

func (*MdbHandle) ReadNextDpg

func (mdb *MdbHandle) ReadNextDpg(table *MdbTableDef) error

ReadNextDpg reads the next data page for a table into the page buffer. Returns the physical page number, or 0 if no more pages.

func (*MdbHandle) ReadPgIf8

func (mdb *MdbHandle) ReadPgIf8() byte

ReadPgIf8 reads a single byte, advancing pages if needed.

func (*MdbHandle) ReadPgIf16

func (mdb *MdbHandle) ReadPgIf16() uint16

ReadPgIf16 reads a little-endian uint16, advancing pages if needed.

func (*MdbHandle) ReadPgIf32

func (mdb *MdbHandle) ReadPgIf32() uint32

ReadPgIf32 reads a little-endian uint32, advancing pages if needed.

func (*MdbHandle) ReadPgIfN

func (mdb *MdbHandle) ReadPgIfN(dst []byte, n int) int

ReadPgIfN reads n bytes from the current position, advancing across pages as needed. Returns the actual number of bytes read.

func (*MdbHandle) ReadRow

func (mdb *MdbHandle) ReadRow(table *MdbTableDef, row int) (bool, error)

ReadRow reads a single row and binds its column values.

func (*MdbHandle) ReadTable

func (mdb *MdbHandle) ReadTable(entry *CatalogEntry) (*MdbTableDef, error)

ReadTable reads a table definition from a catalog entry.

func (*MdbHandle) ReadTableByName

func (mdb *MdbHandle) ReadTableByName(name string, objType int) (*MdbTableDef, error)

ReadTableByName reads a table definition by table name and object type.

func (*MdbHandle) RewindTable

func (mdb *MdbHandle) RewindTable(table *MdbTableDef)

RewindTable resets the iteration state for a table.

func (*MdbHandle) TempTableAddCol

func (mdb *MdbHandle) TempTableAddCol(table *MdbTableDef, col *MdbColumn)

TempTableAddCol adds a column to a temporary table.

type MdbIndex

type MdbIndex struct {
	IndexNum    int
	Name        string
	IndexType   int
	FirstPg     uint32
	NumRows     int
	NumKeys     int
	KeyColNum   [MaxIdxCols]int // 1-based column numbers
	KeyColOrder [MaxIdxCols]int // Asc or Desc
	Flags       int
	Table       *MdbTableDef
}

MdbIndex represents an index on a table.

type MdbIndexPage

type MdbIndexPage struct {
	Pg         uint32
	Offset     int
	StartPos   int
	Len        int
	RC         int
	CacheValue [256]byte
	IdxStarts  [2000]int
}

MdbIndexPage holds state for a single index page.

type MdbSarg

type MdbSarg struct {
	Op    int
	Value MdbAny
}

MdbSarg holds a single search argument on a column.

type MdbTableDef

type MdbTableDef struct {
	Entry *CatalogEntry
	Name  string

	NumCols    int
	Columns    []*MdbColumn
	NumRows    int
	NumVarCols int

	NumIdxs     int
	NumRealIdxs int
	Indices     []*MdbIndex

	FirstDataPg uint32
	IndexStart  int

	// Page tracking for iteration
	CurPgNum  uint32
	CurPhysPg uint32
	CurRow    int
	NoSkipDel int

	// Usage maps
	MapBasePg     uint32
	MapSz         int
	UsageMap      []byte
	FreemapBasePg uint32
	FreemapSz     int
	FreeUsageMap  []byte

	// Sarg tree (WHERE clause)
	SargTree *SargNode

	// Scan strategy
	Strategy int
	ScanIdx  *MdbIndex
	MdbIdx   *MdbHandle
	Chain    *IndexChain

	// Temp table support
	IsTempTable    bool
	TempTablePages [][]byte

	Props *Properties
	// contains filtered or unexported fields
}

MdbTableDef represents a table definition in an MDB database.

type Properties

type Properties struct {
	Name string
	Hash map[string]string
}

Properties represents parsed KKD property data.

type Query

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

Query represents an open query on an MDB database. It provides methods to iterate over rows and extract column values.

func OpenQuery

func OpenQuery(path, query string) (*Query, error)

OpenQuery opens an MDB database and executes a SQL query. The returned Query owns the MdbHandle and closes it when Close() is called.

func OpenQueryOnHandle added in v0.0.8

func OpenQueryOnHandle(mdb *MdbHandle, query string) (*Query, error)

OpenQueryOnHandle executes a SQL query on an already-open MdbHandle. The returned Query does NOT own the MdbHandle — Close() on the Query will not close the underlying file. The caller is responsible for the MdbHandle's lifecycle.

func (*Query) BinaryValue

func (q *Query) BinaryValue(i int) []byte

BinaryValue returns the raw bytes for a binary column in the current row.

func (*Query) Close

func (q *Query) Close() error

Close frees resources associated with the query. If the Query owns its MdbHandle (created via OpenQuery), the handle is closed. If created via OpenQueryOnHandle, the MdbHandle is left open.

func (*Query) ColumnInfo

func (q *Query) ColumnInfo() []Column

ColumnInfo returns metadata about the result columns.

func (*Query) Columns

func (q *Query) Columns() []string

Columns returns the column names.

func (*Query) DateTimeValue

func (q *Query) DateTimeValue(i int) (time.Time, bool)

DateTimeValue returns the time.Time value for a DateTime column in the current row.

func (*Query) IsNull

func (q *Query) IsNull(i int) bool

IsNull returns true if column i is NULL in the current row.

func (*Query) Next

func (q *Query) Next() (bool, error)

Next advances to the next row in the result set. Returns (true, nil) if a row is available, (false, nil) if no more rows, or (false, error) on error.

func (*Query) Value

func (q *Query) Value(i int) string

Value returns the string value for column i in the current row.

type SQL

type SQL struct {
	Mdb *MdbHandle

	// Parsed columns
	Columns    []*SQLColumn
	NumColumns int
	AllColumns bool
	SelCount   bool

	// Parsed tables
	Tables    []*SQLTable
	NumTables int

	// Sarg tree (WHERE clause)
	SargTree  *SargNode
	SargStack []*SargNode

	// Bound values
	BoundValues [][]byte

	// Current table being queried
	CurTable *MdbTableDef

	// Limit
	Limit        int
	LimitPercent bool
	RowCount     int

	// Error
	ErrorMsg string
	HasError bool
}

SQL holds the state for a parsed SQL query.

func NewSQL

func NewSQL(mdb *MdbHandle) *SQL

NewSQL creates a new SQL state for query execution.

func (*SQL) AddColumn

func (sql *SQL) AddColumn(name string)

AddColumn adds a column to the SQL result set.

func (*SQL) AddTable

func (sql *SQL) AddTable(name string)

AddTable adds a table to the SQL query.

func (*SQL) BinaryValue

func (sql *SQL) BinaryValue(idx int) []byte

BinaryValue returns the raw bytes for a binary column.

func (*SQL) ColumnCount

func (sql *SQL) ColumnCount() int

ColumnCount returns the number of columns.

func (*SQL) ColumnInfo

func (sql *SQL) ColumnInfo() []Column

ColumnInfo returns metadata about the result columns.

func (*SQL) ColumnName

func (sql *SQL) ColumnName(idx int) string

ColumnName returns the name of a column by index.

func (*SQL) DateTimeValue

func (sql *SQL) DateTimeValue(idx int) (time.Time, bool)

DateTimeValue returns the time.Time for a DateTime column.

func (*SQL) FetchRow

func (sql *SQL) FetchRow() (bool, error)

FetchRow fetches the next row from the current table.

func (*SQL) IsNull

func (sql *SQL) IsNull(idx int) bool

IsNull checks if a column value is NULL.

func (*SQL) Value

func (sql *SQL) Value(idx int) string

Value returns the bound string value for a column.

type SQLColumn

type SQLColumn struct {
	Name     string
	DispSize int
}

SQLColumn represents a column reference in the SQL query.

type SQLTable

type SQLTable struct {
	Name  string
	Alias string
}

SQLTable represents a table reference in the SQL query.

type SargNode

type SargNode struct {
	Op       int
	Col      *MdbColumn
	ValType  int // Type flag for the stored value
	Value    MdbAny
	Parent   *SargNode // Internal: used during SQL parsing
	Children []*SargNode
	Left     *SargNode
	Right    *SargNode
}

SargNode is a node in the search argument tree (WHERE clause).

Jump to

Keyboard shortcuts

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