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
- Variables
- func ASCIItoUCS2(src string) []byte
- func ASCIItoUCS2Len(src []byte) ([]byte, int)
- func ColDispSize(colType, colSize int) int
- func ColFixedSize(colType int) int
- func ColIsShortDate(col *MdbColumn) bool
- func ColTypeName(typ int) string
- func DateToTime(td float64) time.Time
- func FillTempCol(col *MdbColumn, name string, colSize, colType int, isFixed bool)
- func FillTempField(field *MdbField, value []byte, siz int, isFixed bool, isNull bool, start int, ...)
- func GetByte(buf []byte, offset int) byte
- func GetDouble(buf []byte, offset int) float64
- func GetInt16(buf []byte, offset int) int
- func GetInt32(buf []byte, offset int) int
- func GetInt32MSB(buf []byte, offset int) int
- func GetSingle(buf []byte, offset int) float32
- func GetUint16(buf []byte, offset int) uint16
- func GetUint32(buf []byte, offset int) uint32
- func ILikeCmp(s, r string) bool
- func IsLogicalOp(op int) bool
- func IsRelationalOp(op int) bool
- func IsSystemTable(entry *CatalogEntry) bool
- func IsUserTable(entry *CatalogEntry) bool
- func Jet3CodePageToUTF8(src []byte, codePage uint16) string
- func LikeCmp(s, r string) bool
- func MoneyToString(buf []byte, offset int) string
- func NumericToString(buf []byte, start int, scale, prec int) string
- func ObjTypeName(typ int) string
- func ParseFloat(s string) (float64, bool)
- func ParseInt(s string) (int64, bool)
- func TestSargs(mdb *MdbHandle, table *MdbTableDef, fields []MdbField) bool
- func TmToDate(t time.Time) float64
- func UnicodeToUTF8(src []byte, isJet4 bool) string
- func UnicodeToUTF8Len(src []byte, isJet4 bool) (string, int)
- type CatalogEntry
- type Column
- type Error
- type IndexChain
- type MdbAny
- type MdbColumn
- type MdbField
- type MdbFile
- type MdbFormatConstants
- type MdbHandle
- func (mdb *MdbHandle) AddRowToTempTable(table *MdbTableDef, rowData []byte, rowSize int)
- func (mdb *MdbHandle) BinaryValue(col *MdbColumn) []byte
- func (mdb *MdbHandle) BoolValue(col *MdbColumn) (bool, bool)
- func (mdb *MdbHandle) Close() error
- func (mdb *MdbHandle) CodePage() uint16
- func (mdb *MdbHandle) CrackRow(table *MdbTableDef, rowStart, rowSize int) ([]MdbField, error)
- func (mdb *MdbHandle) CreateTempTable(name string) *MdbTableDef
- func (mdb *MdbHandle) DateTimeValue(col *MdbColumn) (time.Time, bool)
- func (mdb *MdbHandle) DescribeTable(sql *SQL, tableName string) error
- func (mdb *MdbHandle) FetchRow(table *MdbTableDef) (bool, error)
- func (mdb *MdbHandle) Float64Value(col *MdbColumn) (float64, bool)
- func (mdb *MdbHandle) Fmt() *MdbFormatConstants
- func (mdb *MdbHandle) FreeTableDef(table *MdbTableDef)
- func (mdb *MdbHandle) GetBoundValue(table *MdbTableDef, idx int) string
- func (mdb *MdbHandle) GetCatalogEntryByName(name string) *CatalogEntry
- func (mdb *MdbHandle) Int64Value(col *MdbColumn) (int64, bool)
- func (mdb *MdbHandle) IsJet3() bool
- func (mdb *MdbHandle) IsJet4() bool
- func (mdb *MdbHandle) ListTables(sql *SQL) error
- func (mdb *MdbHandle) OleReadFull(col *MdbColumn, bindBuf []byte) ([]byte, int, error)
- func (mdb *MdbHandle) OpenQuery(query string) (*SQL, error)
- func (mdb *MdbHandle) PackRow(table *MdbTableDef, rowBuf []byte, numFields int, fields []MdbField) int
- func (mdb *MdbHandle) PgGetByte() byte
- func (mdb *MdbHandle) PgGetFirstByte() byte
- func (mdb *MdbHandle) PgGetInt16() int
- func (mdb *MdbHandle) PgGetInt32() int
- func (mdb *MdbHandle) PgGetInt32MSB() int
- func (mdb *MdbHandle) ReadCatalog(objType int) error
- func (mdb *MdbHandle) ReadColumns(table *MdbTableDef) error
- func (mdb *MdbHandle) ReadIndices(table *MdbTableDef) error
- func (mdb *MdbHandle) ReadNextDpg(table *MdbTableDef) error
- func (mdb *MdbHandle) ReadPgIf8() byte
- func (mdb *MdbHandle) ReadPgIf16() uint16
- func (mdb *MdbHandle) ReadPgIf32() uint32
- func (mdb *MdbHandle) ReadPgIfN(dst []byte, n int) int
- func (mdb *MdbHandle) ReadRow(table *MdbTableDef, row int) (bool, error)
- func (mdb *MdbHandle) ReadTable(entry *CatalogEntry) (*MdbTableDef, error)
- func (mdb *MdbHandle) ReadTableByName(name string, objType int) (*MdbTableDef, error)
- func (mdb *MdbHandle) RewindTable(table *MdbTableDef)
- func (mdb *MdbHandle) TempTableAddCol(table *MdbTableDef, col *MdbColumn)
- type MdbIndex
- type MdbIndexPage
- type MdbSarg
- type MdbTableDef
- type OrderTerm
- type Plan
- type Properties
- type Query
- func (q *Query) BinaryValue(i int) []byte
- func (q *Query) BoolValue(i int) (bool, bool)
- func (q *Query) CapturePlan() *Plan
- func (q *Query) Close() error
- func (q *Query) ColumnInfo() []Column
- func (q *Query) Columns() []string
- func (q *Query) DateTimeValue(i int) (time.Time, bool)
- func (q *Query) DriverRow() []any
- func (q *Query) DriverValue(i int) any
- func (q *Query) Float64Value(i int) (float64, bool)
- func (q *Query) Int64Value(i int) (int64, bool)
- func (q *Query) IsNull(i int) bool
- func (q *Query) Next() (bool, error)
- func (q *Query) Value(i int) string
- type SQL
- func (sql *SQL) AddColumn(name string)
- func (sql *SQL) AddTable(name string)
- func (sql *SQL) BinaryValue(idx int) []byte
- func (sql *SQL) BoolValue(idx int) (bool, bool)
- func (sql *SQL) ColumnCount() int
- func (sql *SQL) ColumnInfo() []Column
- func (sql *SQL) ColumnName(idx int) string
- func (sql *SQL) DateTimeValue(idx int) (time.Time, bool)
- func (sql *SQL) FetchRow() (bool, error)
- func (sql *SQL) Float64Value(idx int) (float64, bool)
- func (sql *SQL) Int64Value(idx int) (int64, bool)
- func (sql *SQL) IsNull(idx int) bool
- func (sql *SQL) Value(idx int) string
- type SQLColumn
- type SQLTable
- type SargNode
Constants ¶
const ( PageDB = 0 PageData = 1 PageTable = 2 PageIndex = 3 PageLeaf = 4 PageMap = 5 )
Page types
const ( Jet3 = 0 Jet4 = 1 Accdb2007 = 2 Accdb2010 = 3 Accdb2013 = 4 Accdb2016 = 5 Accdb2019 = 6 )
Jet version constants
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
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
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 OpIn = 14 )
Search argument operators
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
const ( TableScan = iota LeafScan IndexScan )
Scan strategies
const ( UUIDBraces4228 = 0 UUIDNoBraces4226 = 1 )
UUID format
Variables ¶
var FileCacheMaxBytes int64 = 512 << 20
FileCacheMaxBytes bounds the total size of cached database files. Repeated opens of the same file reuse the in-memory copy (keyed by path, size, and modification time), avoiding a full re-read per connection. Set to 0 to disable the cache.
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.
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.
var MaxInMemoryFileSize int64 = 128 << 20
MaxInMemoryFileSize is the largest database that is fully loaded into memory at open time. MDB scans issue one ReadAt per page (and memos follow random page pointers), so loading the file once eliminates hundreds of thousands of syscalls per full-table scan. Larger files fall back to on-demand page reads.
Functions ¶
func ASCIItoUCS2 ¶
ASCIItoUCS2 widens each source byte to UCS-2LE, matching mdbtools' legacy temp-table conversion used by LIST TABLES and DESCRIBE TABLE. This is intentionally byte-oriented rather than a UTF-8-to-UTF-16 conversion.
func ASCIItoUCS2Len ¶
ASCIItoUCS2Len is like ASCIItoUCS2 but takes a byte slice and returns UCS-2LE bytes along with their length.
func ColDispSize ¶
ColDispSize returns the display size for a column type.
func ColFixedSize ¶
ColFixedSize returns the fixed byte size for a column type, or -1 if variable.
func ColIsShortDate ¶
ColIsShortDate checks if a DateTime column is formatted as a short date.
func ColTypeName ¶
ColTypeName returns the Access type name for a column type constant.
func DateToTime ¶
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 ¶
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 GetInt32MSB ¶
GetInt32MSB reads a big-endian (MSB) 32-bit integer at offset from a buffer.
func ILikeCmp ¶
ILikeCmp tests whether string s matches the SQL LIKE pattern r, case-insensitively using Unicode case folding.
func IsLogicalOp ¶
IsLogicalOp returns true if the operator is a logical connective (AND, OR, NOT).
func IsRelationalOp ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
ObjTypeName returns the human-readable name for an object type constant.
func ParseFloat ¶
ParseFloat parses a string as a float64. 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 UnicodeToUTF8 ¶
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.
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 Error ¶
type Error struct {
Msg string
}
Error implements the error interface for gomdb errors.
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 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
// Null-mask position, precomputed from ColNum so row cracking avoids
// per-column division and modulo.
NullByte int
NullBit uint8
NullReady bool
// Sargs for this column
Sargs []*MdbSarg
// Current row value state
CurValueStart int
CurValueLen int
CurValueIsNull bool
CurBlobPgRow uint32
ChunkSize int
// CurValueText is populated only when a caller asks for the legacy string
// representation. Native driver getters can therefore avoid formatting.
CurValueText string
CurValueTextValid bool
// Binding
BindPtr []byte
LenPtr *int
BindLen 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 (*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 ¶
BinaryValue returns the raw bytes for a binary column.
func (*MdbHandle) BoolValue ¶ added in v0.0.9
BoolValue returns a native boolean for a Boolean column.
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 ¶
DateTimeValue returns the time.Time for a DateTime column.
func (*MdbHandle) DescribeTable ¶
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) Float64Value ¶ added in v0.0.9
Float64Value returns a native floating-point value for floating and Currency columns. Currency is stored as a signed 64-bit integer scaled by 10,000.
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) Int64Value ¶ added in v0.0.9
Int64Value returns a native integer for the integral Access column types.
func (*MdbHandle) ListTables ¶
ListTables implements the "LIST TABLES" SQL command.
func (*MdbHandle) OleReadFull ¶
OleReadFull reads the complete OLE field data.
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 ¶
PgGetByte reads a single byte at the current position, advancing it by 1.
func (*MdbHandle) PgGetFirstByte ¶
PgGetFirstByte returns the first byte of the current page.
func (*MdbHandle) PgGetInt16 ¶
PgGetInt16 reads a little-endian 16-bit integer at the current position, advancing by 2.
func (*MdbHandle) PgGetInt32 ¶
PgGetInt32 reads a little-endian 32-bit integer at the current position, advancing by 4.
func (*MdbHandle) PgGetInt32MSB ¶
PgGetInt32MSB reads a big-endian 32-bit integer at the current position, advancing by 4.
func (*MdbHandle) ReadCatalog ¶
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) ReadPgIf16 ¶
ReadPgIf16 reads a little-endian uint16, advancing pages if needed.
func (*MdbHandle) ReadPgIf32 ¶
ReadPgIf32 reads a little-endian uint32, advancing pages if needed.
func (*MdbHandle) ReadPgIfN ¶
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 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 Plan ¶ added in v0.0.11
type Plan struct {
// contains filtered or unexported fields
}
Plan is a reusable prepared query: a fully executed SQL statement with its resolved table definition and sarg tree. Plans are shared within one MdbHandle across executions; scan state is reset on every Execute, so concurrent use of the same plan is not allowed (Execute returns an error while the plan is in use).
type Properties ¶
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 ¶
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
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 ¶
BinaryValue returns the raw bytes for a binary column in the current row.
func (*Query) CapturePlan ¶ added in v0.0.11
CapturePlan detaches the executed SQL from this query into a reusable Plan (stopping any running fast scan first). Returns nil for queries that cannot be reused, such as temp-table results. Callers should cache the returned plan and still call Close on the query.
func (*Query) Close ¶
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 ¶
ColumnInfo returns metadata about the result columns.
func (*Query) DateTimeValue ¶
DateTimeValue returns the time.Time value for a DateTime column in the current row.
func (*Query) DriverRow ¶ added in v0.0.11
DriverRow returns the preformatted native values for the current row on fast-scan queries, or nil when the synchronous path is in use. Callers should fall back to DriverValue when nil is returned.
func (*Query) DriverValue ¶ added in v0.0.11
DriverValue returns the native database/sql value for a result column in the current row: nil, bool, int64, float64, time.Time, []byte, or string. It resolves the bound column once and converts in a single switch, avoiding the per-column IsNull/getter/value lookup chain used by the legacy API.
func (*Query) Float64Value ¶ added in v0.0.9
Float64Value returns a native floating-point value for column i.
func (*Query) Int64Value ¶ added in v0.0.9
Int64Value returns a native integral value for column i.
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
BoundColumns []*MdbColumn
// Current table being queried
CurTable *MdbTableDef
// Limit
Limit int
LimitPercent bool
RowCount int
// ORDER BY terms and materialized sorted rows (non-nil SortedRows means
// FetchRow serves rows from the sorted snapshot instead of the table).
OrderBy []OrderTerm
SortedRows []sortedRow
// Error
ErrorMsg string
HasError bool
}
SQL holds the state for a parsed SQL query.
func (*SQL) BinaryValue ¶
BinaryValue returns the raw bytes for a binary column.
func (*SQL) ColumnCount ¶
ColumnCount returns the number of columns.
func (*SQL) ColumnInfo ¶
ColumnInfo returns metadata about the result columns.
func (*SQL) ColumnName ¶
ColumnName returns the name of a column by index.
func (*SQL) DateTimeValue ¶
DateTimeValue returns the time.Time for a DateTime column.
func (*SQL) Float64Value ¶ added in v0.0.9
Float64Value returns a native floating-point result value.
func (*SQL) Int64Value ¶ added in v0.0.9
Int64Value returns a native integral result value.
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
// IN list state, precomputed once per query by resolveInValues so the
// per-row evaluator never allocates or re-parses literals.
InValues []MdbAny // typed elements: I for int/bool, D for float/date, S for text/memo
InElemTypes []int // parallel literal origin: TypeText (quoted), TypeDouble (number), TypeInt (TRUE/FALSE)
InBytes [][]byte // UTF-8 forms for text IN lists; sorted+deduped when inSorted
// contains filtered or unexported fields
}
SargNode is a node in the search argument tree (WHERE clause).