⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 myldbtypes.pas

📁 一个本地database引擎,支持中文T_Sql查询,兼容DELPHI标准数据库控件
💻 PAS
📖 第 1 页 / 共 5 页
字号:
    doRAND,
    doROUND,
    doSIGN,
    doSIN,
    doSQR,
    doSQRT
 );

//------------------------------------------------------------------------------
// record types
//------------------------------------------------------------------------------

 // used in MYLDBMemEngine for saving / loading table to stream
 TMYLDBMemoryTableFileHeader = packed record
  Signature:            array [0..3] of char ;
  Version:              Double;
  RecordCount:          TMYLDBRecordNo;
  // compression params
  UncompressedSize:     Int64;
  NumBlocks:            Int64;
  BlockSize:            Integer;
  CompressionAlgorithm: Byte;
  CompressionMode:      Byte;
  NameLength:           Byte;
 end; // 43 bytes

 TMYLDBIndexPosition = TObject;
 TMYLDBSearchInfo = Pointer;

  // bookmark information type
  TMYLDBBookmarkFlag = (abfCurrent, abfBOF, abfEOF, abfInserted);
  TMYLDBBookmarkInfo = packed record
   BookmarkData: TMYLDBRecordID;      // record ID
   BookmarkFlag: TMYLDBBookmarkFlag;  // bookmark flag
  end;
  PMYLDBBookmarkInfo = ^TMYLDBBookmarkInfo;

 TMYLDBSequenceValue = Int64;

 TMYLDBTimeoutParams = record
  RetryCount:   Word;
  Timeout:      Integer;
 end;

 //------------------------- Search types --------------------------------------
  TMYLDBKeyIndex = (kiLookup, kiRangeStart, kiRangeEnd, kiCurRangeStart,
    kiCurRangeEnd, kiSave);
  TMYLDBSearchCondition = (scNone,scEqual,scLower,scGreater,scLowerEqual,scGreaterEqual);
  TMYLDBKeySearchType = (kstFirst,kstLast,kstAny);

  PMYLDBKeyBuffer = ^TMYLDBKeyBuffer;
  TMYLDBKeyBuffer = packed record
    Modified: Boolean;
    Exclusive: Boolean;
    FieldCount: Integer;
  end;

  TMYLDBNavigationInfo = packed record
    // in
    GetRecordMode:    TMYLDBGetRecordMode;
    IndexID:          TMYLDBObjectID; // current index id (INVALID_OBJECT_ID if no active index)
    // in and out
    RecordID:         TMYLDBRecordID;
    RecordBuffer:     TMYLDBRecordBuffer;
    FirstPosition:    Boolean;
    LastPosition:     Boolean;
    // out
    GetRecordResult:  TMYLDBGetRecordResult;
  end;

  TMYLDBDateTimeExtractField = (dtefYear, dtefMonth, dtefDay, dtefHour, dtefMinute, dtefSecond);

////////////////////////////////////////////////////////////////////////////////
//
// TMYLDBIndexPositionCache
//
////////////////////////////////////////////////////////////////////////////////

  TMYLDBIndexPositionCache = class(TObject)
   public
    Position:   Pointer;      // last used position in index
    IndexID:    TMYLDBObjectID; // last used index
    RecordID:   TMYLDBRecordID; // last used RecordID
    TableState: Integer;      // table state actual on caching moment

    constructor Create;
    destructor Destroy; override;
  end;// TMYLDBIndexPositionCache


////////////////////////////////////////////////////////////////////////////////
//
// TMYLDBScanSearchCondition
//
////////////////////////////////////////////////////////////////////////////////

  TMYLDBScanSearchCondition = class(TObject)
   public
    Expression:                Pointer; // if nil then KeyBuffer will be used
    // index scan key info
    Condition:                 TMYLDBSearchCondition;
    KeyRecordBuffer:           TMYLDBRecordBuffer; // if nil then Expression will be used
    KeyRecordBufferSize:       Integer;
    KeyFieldCount:             Integer;
    IndexID:                   TMYLDBObjectID;
    CreatedFromExpression:     Boolean;
    ParentExpressions:         TList;
    ParentExpressionNodes:     TList;
    FExternalKeyRecordBuffer:  Boolean;
    PartialCompare:            Boolean;

    procedure ClearKeyRecordBuffer;

    constructor Create(ExternalKeyRecordBuffer: Boolean);
    destructor Destroy; override;
    procedure Assign(ScanSearchCondition: TMYLDBScanSearchCondition);
  end;

  TMYLDBExtractedConditionInfo = packed record
    KeyRecordBuffer:           TMYLDBRecordBuffer;
    ExtractedExpressionNode:   Pointer;
    Expression:                Pointer; // if nil then KeyBuffer will be used
  end;
  PMYLDBExtractedConditionInfo = ^TMYLDBExtractedConditionInfo;

////////////////////////////////////////////////////////////////////////////////
//
// TMYLDBScanSearchConditionArray
//
////////////////////////////////////////////////////////////////////////////////

  TMYLDBScanSearchConditionArray = class(TObject)
   public
    Items:    array of TMYLDBScanSearchCondition;
    Count:    Integer;

    constructor Create;
    destructor Destroy; override;
    procedure Delete(ItemNo: Integer);
    procedure AddExpression(Expression: Pointer);
    procedure AddCondition(ScanSearchCondition: TMYLDBScanSearchCondition);
   private
    procedure TryToExtendMultiFieldIndexCondition(ConditionNo: Integer; IndexDef: Pointer; Expressions: TList);
   public
    procedure CreateIndexScanConditionsFromExpressions(IndexDefs: Pointer; SessionID: TMYLDBSessionID);
    procedure RemoveUnusedConditionsCreatedFromExpressions(var ScanConditionNo, ScanEndConditionNo: Integer);
    procedure ExtractChosenConditionsFromExpressions(ScanConditionNo, ScanEndConditionNo: Integer);
    procedure ReturnExtractedConditionsToExpressions(ScanConditionNo, ScanEndConditionNo: Integer);
  end;

 // ORDER BY clause element
 TMYLDBSortSpecification = record
   TableName: string;   // table or its pseudonym
   ColumnName: string;  // field name or pseudonym
   Descending: Boolean; // ASC | DESC
 end;


//----------------------- Field Types ------------------------------------------

 PMYLDBDate = ^TMYLDBDate;
 TMYLDBDate = Integer;  // Number of days from Christmas ( -5 883 516 .. 5 883 516 )

 PMYLDBTime = ^TMYLDBTime;
 TMYLDBTime = Integer; // Number of milliseconds from day begin ( 0 .. 24*60*60*1000 )

 PMYLDBDateTime = ^TMYLDBDateTime;
 TMYLDBDateTime = packed record  // Total 8 byte
   Date: TMYLDBDate;  // Number of days from Christmas ( -5 883 516 .. 5 883 516 )
   Time: TMYLDBTime; // Number of milliseconds from day begin ( 0 .. 24*60*60*1000 )
 end;//TMYLDBDateTime                                                = 86 400 000

 PMYLDBLogical = ^TMYLDBLogical;
 //TMYLDBLogical = ByteBool;
 TMYLDBLogical = WordBool; //TDataset using WordBool

 PMYLDBCurrency = ^TMYLDBCurrency;
 //TMYLDBCurrency = Currency;
 TMYLDBCurrency = Double;  // Overflow fix

 PMYLDBGuid = ^TMYLDBGuid;
 TMYLDBGuid = TGuid;

//------------------------------------------------------------------------------
// Delphi 4,5 types
//------------------------------------------------------------------------------

{$IFNDEF D6H}
 PWord = ^Word;
 PInteger = ^Integer;
 PByte = ^Byte;
 PCardinal = ^Cardinal;
{$ENDIF}

TMYLDBIntegerArray = class;

TMYLDBPagesArray = TMYLDBIntegerArray;


////////////////////////////////////////////////////////////////////////////////
//
// TMYLDBIntegerArray
//
////////////////////////////////////////////////////////////////////////////////

 TMYLDBIntegerArray = class(TObject)
   public
     Items:          array of Integer;
     ItemCount:      Integer;
     AllocBy:        Integer;
     deAllocBy:      Integer;
     MaxAllocBy:     Integer;
     AllocItemCount: Integer;

     constructor Create(
      size: Integer = 0;
      DefaultAllocBy: Integer = 10;
      MaximumAllocBy: Integer = 100
     );
     destructor Destroy; override;
     procedure SetSize(newSize: Integer);
     procedure Assign(v: TMYLDBIntegerArray);
     procedure Append(value: Integer);
     procedure Insert(ItemNo: Integer; value: Integer);
     procedure Delete(ItemNo: Integer);
     procedure MoveTo(itemNo, newItemNo: Integer);
     procedure CopyTo(
                      var ar: array of Integer;
                      itemNo, iCount: Integer
                      );
     function IsValueExists(value: Integer): Boolean;
     function IndexOf(value: Integer): Integer;
 end; // TMYLDBIntegerArray


////////////////////////////////////////////////////////////////////////////////
//
// TMYLDBPtrArray
//
////////////////////////////////////////////////////////////////////////////////
(*
 TMYLDBPtrArray = class(TObject)
   private
    FItems:           array of Pointer;
    FSizes:           array of Integer;
    FOverallSize:     Integer;
    FItemCount:       Integer;
    FAllocBy:         Integer;
    FDeAllocBy:       Integer;
    FMaxAllocBy:      Integer;
    FAllocItemCount:  Integer;
    FMemoryManager:   TMYLDBMemoryManager;
   public
//     constructor Create(
//                        Size, MaxAllocBy, AllocBy, DeAllocaBy: Integer = 0;
//                        MemoryManager: TMYLDBMemoryManager = nil
//                         );
//     destructor Destroy; override;
     procedure SetSize(NewSize: Integer); virtual; abstract;
     procedure Append(
                      Buffer:     Pointer;
                      BufferSize: Integer;
                      CopyFlag:   Boolean = False // to copy buffer contents or not
                      ); virtual; abstract;
 end; // TMYLDBPtrArray
*)



 TMYLDBSortedStringPtrArray = class(TList);



////////////////////////////////////////////////////////////////////////////////
//
// Compressed Stream Block Headers Array and related stuff
//
////////////////////////////////////////////////////////////////////////////////

 TMYLDBBLOBDescriptor = packed record
  BlockSize:             Integer; // block size
  NumBlocks:             Int64;  // number of blocks
  UncompressedSize:      Int64; // size of uncompressed data
  StartPosition:         Int64; // position in stream where first block header is stored
  CompressionAlgorithm:  Byte; // compression algorithm
  CompressionMode:       Byte; // compression mode (0-9)
  Reserved:              array [0..1] of Byte;
 end; // TMYLDBBLOBDescriptor - 32 bytes
 PMYLDBBLOBDescriptor = ^TMYLDBBLOBDescriptor;

 // blob descriptor that stores for each blob value
 TMYLDBPartialBLOBDescriptor = packed record
  NumBlocks:             Integer; // number of blocks
  UncompressedSize:      Int64; // size of uncompressed data
 end; // TMYLDBPartialBLOBDescriptor - 8 bytes
 PMYLDBPartialBLOBDescriptor = ^TMYLDBPartialBLOBDescriptor;

 // blob descriptor that stores for each blob value
 TMYLDBPartialTemporaryBLOBDescriptor = packed record
  NumBlocks:             Integer; // number of blocks
  UncompressedSize:      Int64; // size of uncompressed data
  CompressedSize:        Int64; // size of compressed data
 end; // TMYLDBPartialTemporaryBLOBDescriptor - 8 bytes
 PMYLDBPartialTemporaryBLOBDescriptor = ^TMYLDBPartialTemporaryBLOBDescriptor;

 TMYLDBCompressedStreamBlockHeader = packed record
       CompressedSize:      Integer; // packed block size
       UncompressedSize:    Integer; // unpacked block size
       Crc32:               Cardinal; // check sum for this block page
       OffsetToNextHeader:  Int64;  // offset from beginning of the compressed stream
                                    // to next block header
 end; // 20

 TMYLDBCompressedStreamBlockHeadersArray = class
    private
     AllocBy:             Int64;
     DeAllocBy:           Int64;
     MaxAllocBy:          Int64;
     AllocItemCount:      Int64;
    public
     Items:               array of TMYLDBCompressedStreamBlockHeader;
     Positions:           array of Int64; // block positions
     ItemCount:           Int64; // all files quantity (including deleted files)
    public
     constructor Create;
     destructor Destroy; override;
     procedure SetSize(NewSize: Int64);
     procedure AppendItem(Value: TMYLDBCompressedStreamBlockHeader; Pos: Int64);
     function FindPosition(Pos: Int64) : Integer;
   end; // TMYLDBCompressedStreamBlockHeadersArray


{
const
 // size in bytes of the compressed stream header (16)
 MYLDBCompressedStreamBlockHeaderSize = sizeof(TMYLDBCompressedStreamHeader);
 // size in bytes of the compressed stream block header (16)
 MYLDBCompressedStreamBlockHeaderSize = sizeof(TMYLDBCompressedStreamBlockHeader);
}


 TMYLDBDiskBLOBCache = packed record
  NumBlocks:             Integer; // number of blocks
  UncompressedSize:      Int64; // size of uncompressed data
  Modified:              Boolean;
  BlobData:              PChar;
 end;// TMYLDBDiskBLOBCache
 PMYLDBDiskBLOBCache = ^TMYLDBDiskBLOBCache;
 PPMYLDBDiskBLOBCache = ^PMYLDBDiskBLOBCache;

 TMYLDBDiskBLOBHeader = packed record
  BlobID:                Word;
  NumBlocks:             Integer; // number of blocks
  CompressedSize:        Int64; // size of compressed data
  UncompressedSize:      Int64; // size of uncompressed data
 end;// TMYLDBDiskBLOBHeader
 PMYLDBDiskBLOBHeader = ^TMYLDBDiskBLOBHeader;


 TMYLDBPageListLink = packed record
  StartPageNo: TMYLDBPageNo;
  StartOffset: Word;
  ItemCount: TMYLDBPageNo;
 end;


////////////////////////////////////////////////////////////////////////////////
//
// TMYLDBBitsArray
//
////////////////////////////////////////////////////////////////////////////////


  TMYLDBBitsArray = class (TObject)
   private
    FBits:              PChar;
    FBitCount:          Integer; // total number of bits
    FNonZeroBitCount:   Integer; // number of bits equal to 1
    FBitsTable:         array [0..255] of byte;
   protected
    function GetNonZeroBitCount: Integer;
    procedure SetSize(NewSize: Integer);
   public
    procedure LoadFromStream(Stream: TStream);
    procedure SaveToStream(Stream: TStream);
    constructor Create;
    destructor Destroy; override;
    function GetBit(BitNo: Integer): Boolean;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -