?? myldbmain.pas
字號:
unit MYLDBMain;
interface
{$I MYLDBVer.inc}
uses SysUtils, Math, Classes,Db,Windows {$IFNDEF NO_DIALOGS},Forms, Controls, Dialogs{$ENDIF},
{$IFDEF D6H}
DBCommon,
Variants,
SqlTimSt,
{$ENDIF}
// MYLDBoluteDatabase units
{$IFDEF LOCAL_VERSION}
MYLDBLocalEngine,
{$ENDIF}
{$IFNDEF D6H}
MYLDBD4Routines,
{$ENDIF}
{$IFDEF DEBUG_MEMCHECK}
MemCheck,
{$ENDIF}
{$IFDEF DEBUG_LOG}
MYLDBDebug,
{$ENDIF}
{$IFDEF CLIENT_VERSION}
MYLDBClient,
{$ENDIF}
MYLDBBase,
{$IFNDEF NO_DIALOGS}
MYLDBDlgWait,
{$ENDIF}
MYLDBCompression,
MYLDBSecurity,
MYLDBVariant,
MYLDBConverts,
MYLDBExcept,
MYLDBSQLProcessor,
MYLDBLexer,
MYLDBTypes,
MYLDBConst,
MYLDBMemory; // UNIT MYLDBMemory MUST BE LAST !!!
const
// TMYLDBDataset flags
dbfOpened = 0;
dbfPrepared = 1;
dbfExecSQL = 2;
dbfTable = 3;
dbfFieldList = 4;
dbfIndexList = 5;
dbfStoredProc = 6;
dbfExecProc = 7;
dbfProcDesc = 8;
dbfDatabase = 9;
dbfProvider = 10;
dbfRepair = 11;
type
TMYLDBEngineType = (etLocal, etClient, etServer);
TCompressionAlgorithm = (caNone,caZLIB,caBZIP,caPPM);
{
TMYLDBCryptoAlgorithm = (
craNone,
craRijndael_128,craRijndael_256,
craBlowfish,
craTwofish_128,craTwofish_256,
craSquare,
craDES_Single_8,
craDES_Double_8,craDES_Double_16,
craDES_Triple_8,craDES_Triple_16,craDES_Triple_24
);
}
// forward declarations
TMYLDBSession = class;
TMYLDBDatabase = class;
TMYLDBDataSet = class;
TMYLDBTable = class;
TMYLDBAdvFieldDefs = class;
TMYLDBAdvIndexDefs = class;
////////////////////////////////////////////////////////////////////////////////
//
// EMYLDBEngineError
//
////////////////////////////////////////////////////////////////////////////////
EMYLDBEngineError = class(EDatabaseError)
private
FErrorCode: Integer;
FErrorMessage: string;
public
constructor Create(ErrorCode: Integer; ErrMessage: String = '');
property ErrorCode: Integer read FErrorCode;
property ErrorMessage: string read FErrorMessage;
end;
////////////////////////////////////////////////////////////////////////////////
//
// TMYLDBBLOBStream
//
////////////////////////////////////////////////////////////////////////////////
TMYLDBBLOBStream = class (TMYLDBStream)
private
FField: TBlobField;
FDataSet: TMYLDBDataSet;
FBLOBStream: TMYLDBStream; // local or client blob stream
protected
// sets new size of the stream
procedure InternalSetSize(const NewSize: Int64);
// sets new size of the stream
procedure SetSize(NewSize: Longint);
{$IFDEF D6H}
overload;
{$ENDIF}
override;
{$IFDEF D6H}
procedure SetSize(const NewSize: Int64); overload; override;
{$ENDIF}
public
function Read(var Buffer; Count: Longint): Longint; override;
function Write(const Buffer; Count: Longint): Longint; override;
function Seek(Offset: Longint; Origin: Word): Longint;
{$IFDEF D6H}
overload;
{$ENDIF}
override;
{$IFDEF D6H}
function Seek(const Offset: Int64; Origin: TSeekOrigin): Int64; overload; override;
{$ENDIF}
constructor Create(Field: TBlobField; Mode: TBlobStreamMode);
destructor Destroy; override;
procedure Truncate;
public
// blob stream interface
end; // TMYLDBBLOBStream
////////////////////////////////////////////////////////////////////////////////
//
// TMYLDBSessionList
//
////////////////////////////////////////////////////////////////////////////////
// global list of sessions
TMYLDBSessionList = class(TObject)
private
FSessions: TThreadList;
FSessionNumbers: TBits;
// adds session to list
procedure AddSession(ASession: TMYLDBSession);
// closes all sessions
procedure CloseAll;
// Gets sessions count
function GetCount: Integer;
// Gets session by No
function GetSession(Index: Integer): TMYLDBSession;
// gets current session
function GetCurrentSession: TMYLDBSession;
// Gets session by Name
function GetSessionByName(const SessionName: string): TMYLDBSession;
// Sets current session
procedure SetCurrentSession(Value: TMYLDBSession);
public
constructor Create;
destructor Destroy; override;
// Finds session by name
function FindSession(const SessionName: string): TMYLDBSession;
// Gets list of sessions names
procedure GetSessionNames(List: TStrings);
// Opens session by name
function OpenSession(const SessionName: string): TMYLDBSession;
property Count: Integer read GetCount;
property CurrentSession: TMYLDBSession read GetCurrentSession write SetCurrentSession;
property Sessions[Index: Integer]: TMYLDBSession read GetSession; default;
property List[const SessionName: string]: TMYLDBSession read GetSessionByName;
end;
////////////////////////////////////////////////////////////////////////////////
//
// TMYLDBSession
//
////////////////////////////////////////////////////////////////////////////////
TMYLDBDatabaseEvent = (dbOpen, dbClose, dbAdd, dbRemove);
TMYLDBDatabaseNotifyEvent = procedure(DBEvent: TMYLDBDatabaseEvent; const Param) of object;
TMYLDBPasswordEvent = procedure(Sender: TObject; var Continue: Boolean) of object;
TMYLDBProgressEvent = procedure(Sender: TObject; PercentDone: Integer; var Continue: Boolean) of object;
TMYLDBDataSetNotifyEvent = procedure(DataSet: TObject) of object;
// TSession replacement for thread-safe use
TMYLDBSession = class(TComponent)
private
FHandle: TMYLDBSessionComponentManager;
FDatabases: TList;
FStreamedActive: Boolean;
FKeepConnections: Boolean;
FDefault: Boolean;
FAutoSessionName: Boolean;
FUpdatingAutoSessionName: Boolean;
FSessionName: string;
FSessionNumber: Integer;
FOnDBNotify: TMYLDBDatabaseNotifyEvent;
FOnStartup: TNotifyEvent;
// adds database
procedure AddDatabase(Value: TMYLDBDatabase);
// raises exception if active
procedure CheckInactive;
// sends notification
procedure DBNotification(DBEvent: TMYLDBDatabaseEvent; const Param);
// finds database with specified owner
function DoFindDatabase(const DatabaseName: string; AOwner: TComponent): TMYLDBDatabase;
// opens database (thread-safe)
function DoOpenDatabase(const DatabaseName: string;
AOwner: TComponent): TMYLDBDatabase;
// find DB manager by db name
function FindDatabaseHandle(const DatabaseName: string): TMYLDBBaseSession;
// session is active?
function GetActive: Boolean;
// gets database by No
function GetDatabase(Index: Integer): TMYLDBDatabase;
// gets count of connected databases
function GetDatabaseCount: Integer;
// gets handle
function GetHandle: TMYLDBSessionComponentManager;
// not auto-session?
function SessionNameStored: Boolean;
// makes session current
procedure MakeCurrent;
// removes database from list
procedure RemoveDatabase(Value: TMYLDBDatabase);
// opens session
procedure SetActive(Value: Boolean);
// sets auto-session name
procedure SetAutoSessionName(Value: Boolean);
// sets the name of session
procedure SetSessionName(const Value: string);
// sets session name to datasets and databases
procedure SetSessionNames;
// starts session
procedure StartSession(Value: Boolean);
// updates auto-session name
procedure UpdateAutoSessionName;
// auto-session name is valid?
procedure ValidateAutoSession(AOwner: TComponent; AllSessions: Boolean);
protected
// loaded
procedure Loaded; override;
// send notification to datasets and databases
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
property OnDBNotify: TMYLDBDatabaseNotifyEvent read FOnDBNotify write FOnDBNotify;
// set name of component
procedure SetName(const NewName: TComponentName); override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
// locks session
procedure LockSession;
// unlocks session
procedure UnlockSession;
// closes session
procedure Close;
// closes database
procedure CloseDatabase(Database: TMYLDBDatabase);
// drops all connections
procedure DropConnections;
// finds database by name
function FindDatabase(const DatabaseName: string): TMYLDBDatabase;
// get list of database names
procedure GetDatabaseNames(List: TStrings);
// get list of database tables
procedure GetTableNames(const DatabaseName: string; List: TStrings);
// opens session
procedure Open;
// opens database
function OpenDatabase(const DatabaseName: string): TMYLDBDatabase;
property DatabaseCount: Integer read GetDatabaseCount;
property Databases[Index: Integer]: TMYLDBDatabase read GetDatabase;
property Handle: TMYLDBSessionComponentManager read GetHandle;
published
property Active: Boolean read GetActive write SetActive default False;
property AutoSessionName: Boolean read FAutoSessionName write SetAutoSessionName default False;
property KeepConnections: Boolean read FKeepConnections write FKeepConnections default True;
property SessionName: string read FSessionName write SetSessionName stored SessionNameStored;
property OnStartup: TNotifyEvent read FOnStartup write FOnStartup;
end;
////////////////////////////////////////////////////////////////////////////////
//
// TMYLDBDataset
//
////////////////////////////////////////////////////////////////////////////////
TMYLDBDBFlags = set of 0..15;
TMYLDBDataset = class (TDataset)
private
FCurrentVersion: String;
FHandle: TMYLDBCursor;
FSessionName: String;
FFilterBuffer: TMYLDBRecordBuffer; // filter record buffer
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -