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

📄 myldbbaseengine.pas

📁 一个本地database引擎,支持中文T_Sql查询,兼容DELPHI标准数据库控件
💻 PAS
📖 第 1 页 / 共 5 页
字号:
    // scan records bitmap to find record
    function FindRecordByBitmapScan(SessionID: TMYLDBSessionID;
                                    Restart, GoForward: Boolean;
                                    CurrentRecordID: TMYLDBRecordID;
                                    var ResultRecordID: TMYLDBRecordID;
                                    RecordBitmap: TMYLDBRecordBitmap;
                                    IndexID: TMYLDBObjectID): Boolean;
    // return true if record was found and is visible by cursor
    // prepares params for FindRecordByScan and calls it
    function FindRecord(
                        Cursor:           TMYLDBCursor;
                        SearchExpression: TMYLDBExpression; // locate
                        KeyCondition:     TMYLDBScanSearchCondition; // find key
                        // find first or last record in order specified by index settings
                        Restart:          Boolean;
                        // go from first record to last or vice versa
                        GoForward:        Boolean;
                        // if record was found then return record id
                        ResultRecordID:   PMYLDBRecordID;
                        RecordBitmap:     TMYLDBRecordBitmap;
                        // if specified - fill the whole record bitmap
                        ForceFillWholeBitmap: Boolean = False
                       ): Boolean;
    // return true if record match specified condition
    function IsRecordMatchCondition(
                                var Condition:        TMYLDBScanSearchCondition;
                                RecordBuffer:         TMYLDBRecordBuffer
                                   ): Boolean;
    // need to check conditions or index conditions are enough
    function NeedToCheckOtherConditions(
                              Conditions:           TMYLDBScanSearchConditionArray;
                              ExcludedConditionNo:  Integer; // INVALID_ID4 if not specified
                              ExcludedConditionNo2: Integer; // INVALID_ID4 if not specified
                              FilterRecordPtr:      Pointer): Boolean;
    // return true if record match specified conditions
    function IsRecordMatchConditions(
                              Conditions:           TMYLDBScanSearchConditionArray;
                              ExcludedConditionNo:  Integer; // INVALID_ID4 if not specified
                              ExcludedConditionNo2: Integer; // INVALID_ID4 if not specified
                              FilterRecordPtr:      Pointer;
                              Dataset:              Pointer;
                              RecordBuffer:         TMYLDBRecordBuffer;
                              RecordID:             TMYLDBRecordID
                                    ): Boolean;

    // scan all records and check conditions
    function FindRecordByScanWithoutCondition(
                              SessionID:          TMYLDBSessionID;
                              Conditions:         TMYLDBScanSearchConditionArray;
                              ScanConditionNo:    Integer; // INVALID_ID4 if not specified
                              ScanEndConditionNo: Integer; // INVALID_ID4 if not specified
                              CurrentIndexID:     TMYLDBObjectID; // INVALID_OBJECT_ID if not specified
                              FilterRecordPtr:    Pointer;
                              Dataset:            Pointer;
                              CurrentRecordID:    TMYLDBRecordID;
                              // find first or last record in order specified by index settings
                              Restart:            Boolean;
                              // go from first record to last or vice versa
                              GoForward:          Boolean;
                              // if record was found then return record id
                              ResultRecordID:     PMYLDBRecordID;
                              // if specified - fill record bitmap
                              RecordBitmap:       TMYLDBRecordBitmap;
                              ForceFillWholeBitmap: Boolean
                             ): Boolean;

    // find records by index and condition specified by ScanConditionNo
    // condition index is the same as CurrentIndex
    function FindRecordByScanWithConditionAndConditionIndex(
                              SessionID:          TMYLDBSessionID;
                              Conditions:         TMYLDBScanSearchConditionArray;
                              ScanConditionNo:    Integer; // INVALID_ID4 if not specified
                              ScanEndConditionNo: Integer; // INVALID_ID4 if not specified
                              CurrentIndexID:     TMYLDBObjectID; // INVALID_OBJECT_ID if not specified
                              FilterRecordPtr:    Pointer;
                              Dataset:            Pointer;
                              CurrentRecordID:    TMYLDBRecordID;
                              // find first or last record in order specified by index settings
                              Restart:            Boolean;
                              // go from first record to last or vice versa
                              GoForward:          Boolean;
                              // if record was found then return record id
                              ResultRecordID:     PMYLDBRecordID;
                              // if specified - fill record bitmap
                              RecordBitmap:       TMYLDBRecordBitmap;
                              ForceFillWholeBitmap: Boolean
                             ): Boolean;

    // find records by index and condition specified by ScanConditionNo
    // there is no active index
    function FindRecordByScanWithConditionAndWihtoutCurrentIndex(
                              SessionID:          TMYLDBSessionID;
                              Conditions:         TMYLDBScanSearchConditionArray;
                              ScanConditionNo:    Integer; // INVALID_ID4 if not specified
                              ScanEndConditionNo: Integer; // INVALID_ID4 if not specified
                              CurrentIndexID:     TMYLDBObjectID; // INVALID_OBJECT_ID if not specified
                              FilterRecordPtr:    Pointer;
                              Dataset:            Pointer;
                              CurrentRecordID:    TMYLDBRecordID;
                              // find first or last record in order specified by index settings
                              Restart:            Boolean;
                              // go from first record to last or vice versa
                              GoForward:          Boolean;
                              // if record was found then return record id
                              ResultRecordID:     PMYLDBRecordID;
                              // if specified - fill record bitmap
                              RecordBitmap:       TMYLDBRecordBitmap;
                              ForceFillWholeBitmap: Boolean
                             ): Boolean;

    // find records by index and condition specified by ScanConditionNo
    // condition index is NOT the same as CurrentIndex
    function FindRecordByScanWithConditionAndNonConditionIndex(
                              SessionID:          TMYLDBSessionID;
                              Conditions:           TMYLDBScanSearchConditionArray;
                              ScanConditionNo:      Integer; // INVALID_ID4 if not specified
                              ScanEndConditionNo:   Integer; // INVALID_ID4 if not specified
                              CurrentIndexID:       TMYLDBObjectID; // INVALID_OBJECT_ID if not specified
                              FilterRecordPtr:      Pointer;
                              Dataset:              Pointer;
                              CurrentRecordID:      TMYLDBRecordID;
                              // find first or last record in order specified by index settings
                              Restart:              Boolean;
                              // go from first record to last or vice versa
                              GoForward:            Boolean;
                              // if record was found then return record id
                              ResultRecordID:       PMYLDBRecordID;
                              // if specified - fill record bitmap
                              RecordBitmap:         TMYLDBRecordBitmap;
                              ForceFillWholeBitmap: Boolean
                             ): Boolean;

    // return true if record was found
    function FindRecordByScan(
                              SessionID:            TMYLDBSessionID;
                              Conditions:           TMYLDBScanSearchConditionArray;
                              ScanConditionNo:      Integer; // INVALID_ID4 if not specified
                              ScanEndConditionNo:   Integer; // INVALID_ID4 if not specified
                              CurrentIndexID:       TMYLDBObjectID; // INVALID_OBJECT_ID if not specified
                              FilterRecordPtr:      Pointer;
                              Dataset:              Pointer;
                              CurrentRecordID:      TMYLDBRecordID;
                              // find first or last record in order specified by index settings
                              Restart:              Boolean;
                              // go from first record to last or vice versa
                              GoForward:            Boolean;
                              // if record was found then return record id
                              ResultRecordID:       PMYLDBRecordID;
                              RecordBitmap:         TMYLDBRecordBitmap;
                              // if specified - fill record bitmap
                              ForceFillWholeBitmap: Boolean
                             ): Boolean;
    // used by GetRecordBuffer - find or get record
    function InternalFindOrGetRecordBuffer(
                              Cursor:         TMYLDBCursor;
                              GetRecordMode:  TMYLDBGetRecordMode;
                              // if specified - fill record bitmap
                              ForceFillWholeBitmap: Boolean=False
                            ): TMYLDBGetRecordResult;
    // get record using current index or physical order
    procedure InternalGetRecordBuffer(
                                   SessionID:          TMYLDBSessionID;
                                   var NavigationInfo: TMYLDBNavigationInfo;
                                   IndexPositionCache: TMYLDBIndexPositionCache;
                                   TableState:         Integer
                                      );
   public
    procedure ClearBlobsCacheInRecordBuffer(Buffer: TMYLDBRecordBuffer); virtual;
    // read record with Distinct, SQLFilter, SQLTopRowCount, Filter, Range, OnFilterRecord
    function GetRecordBuffer(
                              Cursor:         TMYLDBCursor;
                              GetRecordMode:  TMYLDBGetRecordMode
                            ): TMYLDBGetRecordResult; virtual;
    // locate
    function Locate(Cursor: TMYLDBCursor; SearchExpression: TMYLDBExpression): Boolean; virtual;
    // find key
    function FindKey(Cursor: TMYLDBCursor; SearchCondition: TMYLDBSearchCondition): Boolean; virtual;

    //---------------------------------------------------------------------------
    // BLOB methods
    //---------------------------------------------------------------------------
    procedure WriteBLOBFieldToRecordBuffer(
              Cursor:     TMYLDBCursor;
              FieldNo:    Integer;
              BLOBStream: TMYLDBStream
              ); virtual; abstract;

    procedure ClearBLOBFieldInRecordBuffer(
              RecordBuffer: TMYLDBRecordBuffer;
              FieldNo:    Integer
              ); virtual;

    procedure ClearBLOBFieldsInRecordBuffer(
              RecordBuffer: TMYLDBRecordBuffer
              ); virtual;

    function InternalCreateBlobStream(
              Cursor:   TMYLDBCursor;
              ToInsert: Boolean;
              FieldNo:  Integer;
              OpenMode: TMYLDBBLOBOpenMode
              ): TMYLDBStream; virtual; abstract;

    procedure GetDirectBlobData(
              Cursor:     TMYLDBCursor;
              FieldNo:    Integer;
              RecordBuffer: TMYLDBRecordBuffer;
              var BLOBDescriptor: TMYLDBPartialTemporaryBLOBDescriptor;
              var pBlobData: PChar); virtual; abstract;

    procedure SetDirectBlobData(
              Cursor:     TMYLDBCursor;
              FieldNo:    Integer;
              RecordBuffer: TMYLDBRecordBuffer;
              var BLOBDescriptor: TMYLDBPartialTemporaryBLOBDescriptor;
              var pBlobData: PChar); virtual; abstract;

    procedure FreeDirectBlobData(
              Cursor:     TMYLDBCursor;
              FieldNo:    Integer;
              RecordBuffer: TMYLDBRecordBuffer;
              var BLOBDescriptor: TMYLDBPartialTemporaryBLOBDescriptor;
              var pBlobData: PChar); virtual; abstract;

    function InsertRecord(var Cursor: TMYLDBCursor): Boolean; virtual; abstract;
    function DeleteRecord(Cursor: TMYLDBCursor): Boolean; virtual; abstract;
    function UpdateRecord(Cursor: TMYLDBCursor): Boolean; virtual; abstract;

    // record operations
    function GetRecordCount(Cursor: TMYLDBCursor): TMYLDBRecordNo;
    procedure SetRecNo(Cursor: TMYLDBCursor; RecNo: TMYLDBRecordNo); virtual;
    function GetRecNo(Cursor: TMYLDBCursor): TMYLDBRecordNo; virtual;

    procedure InternalSetRecNo(Cursor: TMYLDBCursor; RecNo: TMYLDBRecordNo); virtual; abstract;
    function InternalGetRecNo(Cursor: TMYLDBCursor): TMYLDBRecordNo; virtual; abstract;
    function InternalGetRecordCount(Cursor: TMYLDBCursor): TMYLDBRecordNo; virtual; abstract;

    function LastAutoincValue(FieldNo: Integer; Session: TMYLDBBaseSession): Int64; virtual;

    // transaction
    procedure Rollback(SessionID: TMYLDBSessionID); virtual;
    procedure RebuildTemporaryIndexes(SessionID: TMYLDBSessionID);

   public
    property TableName: String read FTableName write FTableName;
    property DatabaseData: TMYLDBDatabaseData read FDatabaseData;
    property FieldManager: TMYLDBBaseFieldManager read FFieldManager;
    property RecordManager: TMYLDBBaseRecordManager read FRecordManager;
    property ConstraintManager: TMYLDBBaseConstraintManager read FConstraintManager;
    property IndexManager: TMYLDBBaseIndexManager read FIndexManager;
    property PageManager: TMYLDBPageManager read FPageManager;
    property CursorList: TList read FCursorList;
    property IsRepairing: Boolean read FIsRepairing write FIsRepairing;
  end; // TMYLDBTableData


////////////////////////////////////////////////////////////////////////////////
//
// TMYLDBDatabaseData
//
////////////////////////////////////////////////////////////////////////////////


  TMYLDBDatabaseData = class (TObject)
   protected
    FCSect:               TRTLCriticalSection;
    FSessionList:         TList;
    FTableDataList:       TList;
    FDatabaseName:        String;
    FPageManager:         TMYLDBPageManager;
    FReadOnly:            Boolean;
    FTryCount:            Integer;
    FDelayMS:             Integer;
    FMultiUser:           Boolean;
    // 5.12 fix read-only problem in multiuser mode within application
    FSessionName: string;
   public
    constructor Create;
    destructor Destroy; override;
    procedure Lock;
    procedure Unlock;
    procedure ConnectSession(Session: TMYLDBBaseSession); virtual;
    procedure DisconnectSession(Session: TMYLDBBaseSession); virtual;
    procedure FreeIfNoSessionsConnected; virtual;
    procedure GetTablesList(List: TStrings); virtual;
    function TableExists(TableName: String): Boolean;

⌨️ 快捷键说明

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