📄 jvquib.pas
字号:
{******************************************************************************}
{* WARNING: JEDI VCL To CLX Converter generated unit. *}
{* Manual modifications will be lost on next release. *}
{******************************************************************************}
{******************************************************************************}
{ UNIFIED INTERBASE (UIB) }
{ }
{ Project JEDI Code Library (JCL) }
{ }
{ The contents of this file are subject to the Mozilla Public License Version }
{ 1.1 (the "License"); you may not use this file except in compliance with the }
{ License. You may obtain a copy of the License at http://www.mozilla.org/MPL/ }
{ }
{ Software distributed under the License is distributed on an "AS IS" basis, }
{ WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for }
{ the specific language governing rights and limitations under the License. }
{ }
{ The Initial Developer of the Original Code is documented in the accompanying }
{ help file JCL.chm. Portions created by these individuals are Copyright (C) }
{ 2003 of these individuals. }
{ }
{ Unit owner: Henri Gourvest }
{ Last modified: September 21, 2003 }
{ }
{******************************************************************************}
{ @abstract(UIB Visual components.)
@author(Henri Gourvest: hgourvest@progdigy.com)
@lastmod(Jan 16, 2003)}
unit JvQUIB;
{$I jvcl.inc}
{$I JvUIB.inc}
(*------------------------------------------------------------------------------
This is a cascading programming style.
..............oOo...............................oOo.........oOo.................
States | Operations | Commands | Components
..............oOo...............................oOo.........oOo.................
qsDataBase | BeginDataBase(L) | | TUIBDataBase
--------------------------------------------------------------------------------
qsTransaction | |-> BeginTransaction | | TUIBTransaction
--------------------------------------------------------------------------------
qsExecImme | |-> BeginExecImme .........|.[ExecSQL] | TUIBQuery
qsStatement | |-> BeginStatement | |
qsPrepare | | |-> BeginPrepare | |
qsExecute | | | |-> BeginExecute |.[Execute] |
| | | | |-> Next ......|.[Open] |
| | | | | | | |
| R <- E E E E E | [Fields] |
| | | | | | |
qsExecute | | | |<- EndExecute |.[Close] |
qsPrepare | | |<- EndPrepare | |
qsStatement | |<- EndStatement | |
-------------------------------------------------------------------------------
qsTransaction | EndTransaction | | TUIBTransaction
..............oOo...............................oOo.........oOo.................
LEGEND
E = Except
R = Raise
-> = Call
------------------------------------------------------------------------------*)
interface
uses
{$IFDEF MSWINDOWS} Windows, {$ENDIF} JvQComponent,
Classes, SysUtils, SyncObjs, JvQUIBLib, JvQUIBase, JvQUIBSQLParser, JvQUIBConst;
type
{Oo.........................................................................oO
TJvUIBComponent
Synchronise Databases, Transactions and Queries.
TUIBLibrary | TUIBDatabase | TUIBTransaction | TUIBQuery
==========================================================================
Lock <---------|------------------|------------------|-----------------o
| Lock <-----------|------------------|---------------o
| | Lock <-----------|-------------o
| | | Lock <--o
| | | UnLock <--o
| | UnLock <---------|-------------o
| UnLock <---------|------------------|---------------o
UnLock <-------|------------------|------------------|-----------------o
Note: With Interbase 7, no need to synchronise anything but removing
Synchronisation you have exactly the same performance than IB6.01 with
Synchronisation on a single CPU !
Oo.........................................................................oO}
{ All UIB components inherith from this class to encapsulate Critical Sections.
Critical Sections make UIB THread Safe. }
TJvUIBComponent = class(TJvComponent)
private
FCriticalsection: TCriticalSection;
public
{ @exclude }
constructor Create(AOwner: TComponent); override;
{ @exclude }
destructor Destroy; override;
{ Lock the critical Section. }
procedure Lock; virtual;
{ UnLock the critical Section. }
procedure UnLock; virtual;
end;
// Forward declarations
TJvUIBTransaction = class;
TJvUIBQuery = class;
TJvUIBStatement = class;
TJvUIBDataBase = class;
{ The list of MetaData Objects returned by TJvUIBDatabase.GetMetadata function. }
TMetaDataOptions = class(TPersistent)
private
FObjects: TOIDDatabases;
FTables: TOIDTables;
FViews: TOIDViews;
FProcedures: TOIDProcedures;
FUDFs: TOIDUDFs;
FSysInfos: boolean;
public
{ @exclude }
constructor Create;
published
{ Metadata objects (Procedure, Generator, Exception, UDF, Role). }
property Objects: TOIDDatabases read FObjects write FObjects default ALLObjects;
{ Table properties (TableField, Primary, Foreign, TableTrigger, Unique, Index, Check)}
property Tables: TOIDTables read FTables write FTables default ALLTables;
{ View properties (Fields & Triggers)}
property Views: TOIDViews read FViews write FViews default AllViews;
{ Procedure properties (input & output parametters). }
property Procedures: TOIDProcedures read FProcedures write FProcedures default AllProcedures;
{ UDFs properties (Fields). }
property UDFs: TOIDUDFs read FUDFs write FUDFs default AllUDFs;
{ Include System tables, triggers and domains. }
property SysInfos: boolean read FSysInfos write FSysInfos default False;
end;
TJvUIBDataBase = class(TJvUIBComponent)
private
FLibrary: TUIBLibrary;
FLiBraryName: TFileName;
FDbHandle: IscDbHandle;
FHandleShared: boolean;
FParams: TStrings;
FDatabaseName: TFileName;
FAfterConnect: TNotifyEvent;
FAfterDisconnect: TNotifyEvent;
FBeforeConnect: TNotifyEvent;
FBeforeDisconnect: TNotifyEvent;
FTransactions: TList;
FOnConnectionLost: TNotifyEvent;
FExceptions: TList;
FMetadata: TObject;
FMetaDataOptions: TMetaDataOptions;
function ReadParamString(Param: String; Default: String = ''): String;
procedure WriteParamString(Param: String; Value: String);
function ReadParamInteger(Param: String; Default: Integer): Integer;
procedure WriteParamInteger(Param: String; Value: Integer);
procedure SetParams(const Value: TStrings);
procedure SetDatabaseName(const Value: TFileName);
procedure SetConnected(const Value: Boolean);
function GetConnected: Boolean;
procedure SetSQLDialect(const Value: Integer);
function GetSQLDialect: Integer;
function GetCharacterSet: TCharacterSet;
procedure SetCharacterSet(const Value: TCharacterSet);
function GetPassWord: string;
function GetUserName: string;
procedure SetPassWord(const Value: string);
procedure SetUserName(const Value: string);
procedure AddTransaction(Transaction: TJvUIBTransaction);
procedure RemoveTransaction(Transaction: TJvUIBTransaction);
procedure ClearTransactions;
procedure CloseTransactions;
procedure SetDbHandle(const Value: IscDbHandle);
procedure SetLibraryName(const Lib: TFileName);
function GetTransactions(const Index: Cardinal): TJvUIBTransaction;
function GetTransactionsCount: Cardinal;
function GetSegmentSize: Word;
procedure SetSegmentSize(const Value: Word);
protected
procedure DoOnConnectionLost(Lib: TUIBLibrary); virtual;
procedure DoOnGetDBExceptionClass(Number: Integer; out Excep: EUIBExceptionClass); virtual;
public
{ Constructor method. }
constructor Create(AOwner: TComponent); override;
{ Destructor method. }
destructor Destroy; override;
{ Execute a SQL statement without the need to have the database connected,
it is usefull to create a database by SQL. }
procedure ExecuteImmediate(const Statement: string);
{ Remove all Interbase Exception class registered using 'RegistedException'. }
procedure ClearExceptions;
{ Associate an Interbase Exception with a Delphi exception, ID is the Exception Identifier number. }
procedure RegisterException(Excpt: EUIBExceptionClass; ID: Integer); overload;
{ Associate an Interbase Exception with a Delphi exception, Name is the Interbase Exception name. }
function RegisterException(Excpt: EUIBExceptionClass; const Name: string): Integer; overload;
{ Remove the Registered Exception number. }
procedure UnRegisterException(Number: Integer);
{ Remove the Registered Exception class. }
procedure UnRegisterExceptions(Excpt: EUIBExceptionClass);
{ Create a database with a default page size of 2048. }
procedure CreateDatabase(PageSize: Integer = 2048);
{ Return a TMetaDatabase class corresponding to the current connection. }
function GetMetadata(Refresh: boolean = False): TObject;
{ The DbHandle can be used to share the current connection with other Interbase components like IBX. }
property DbHandle: IscDbHandle read FDbHandle write SetDbHandle;
{ Determine if the DbHandle is initialized by another component. }
property IsHandleShared : Boolean read FHandleShared;
{ List all transactions connected to the database component. }
property Transactions[const Index: Cardinal]: TJvUIBTransaction read GetTransactions;
{ Number of connected transactions. }
property TransactionsCount: Cardinal read GetTransactionsCount;
{ Can be used to access the low level API. }
property Lib: TUIBLibrary read FLibrary;
published
{ DataBase connection parametters. }
property Params: TStrings read FParams write SetParams;
{ Database file name. }
property DatabaseName: TFileName read FDatabaseName write SetDatabaseName;
{ Connect or disconnect a database. }
property Connected: Boolean read GetConnected write SetConnected default False;
{ The SQL dialect gives access to DSQL features, set the dialect to 1 or 3.
Dialect 3 gives access to features introduced in InterBase 6. }
property SQLDialect: Integer read GetSQLDialect write SetSQLDialect default 3;
{ Character set to be utilized. }
property CharacterSet: TCharacterSet read GetCharacterSet write SetCharacterSet default csNONE;
{ Set the user name. Default = SYSDBA. }
property UserName: string read GetUserName write SetUserName;
{ Set the Password. Default = masterkey. }
property PassWord: string read GetPassWord write SetPassWord;
{ Define wich library the connection use.}
property LibraryName: TFileName read FLiBraryName write SetLibraryName;
{ This event occur after the component is connected to database. }
property AfterConnect: TNotifyEvent read FAfterConnect write FAfterConnect;
{ This event occur before the component is connected to database. }
property BeforeConnect: TNotifyEvent read FBeforeConnect write FBeforeConnect;
{ This event occur after the component is disconnected from database. }
property AfterDisconnect: TNotifyEvent read FAfterDisconnect write FAfterDisconnect;
{ This event occur before the component is disconnected from database. }
property BeforeDisconnect: TNotifyEvent read FBeforeDisconnect write FBeforeDisconnect;
{ When connection lost, Database, Transactions and Queries are automatically closed.
Only one exception is raised to terminate the current stack and this event occur. }
property OnConnectionLost: TNotifyEvent read FOnConnectionLost write FOnConnectionLost;
{ The blob segment size used to write in database, this parametter depend on hard drive. }
property SegmentSize: Word read GetSegmentSize write SetSegmentSize default 16*1024;
{ The list of MetaData Objects returned by GetMetadata. }
property MetaDataOptions: TMetaDataOptions read FMetaDataOptions;
end;
{ Describe how a transaction is closed. }
TEndTransMode = (
etmDefault, // Use default Transaction Action
etmStayIn, // keep transaction without commit or rollback
etmCommit, // commit transaction
etmCommitRetaining, // commit transaction and keep transaction handle
etmRollback, // rollback transaction
etmRollbackRetaining // rollback transaction and keep transaction handle
);
{ Indicate the Query state.
order is important ! }
TQueryState = (
qsDataBase, // have a database handle
qsTransaction, // have a transaction handle
qsExecImme, // Query executed immediately without the need of statement handle
qsStatement, // have a statement handle
qsPrepare, // Query prepared
qsExecute // Query executed
);
{Oo.......................................................................oO
TUIBTransaction
Oo.......................................................................oO}
// Transaction parameters
TTransParam = (
{ prevents a transaction from accessing tables if they are written to by
other transactions.}
tpConsistency,
{ allows concurrent transactions to read and write shared data. }
tpConcurrency,
{ Concurrent, shared access of a specified table among all transactions. }
tpShared,
{ Concurrent, restricted access of a specified table. }
tpProtected,
tpExclusive,
{ Specifies that the transaction is to wait until the conflicting resource
is released before retrying an operation [Default]. }
tpWait,
{ Specifies that the transaction is not to wait for the resource to be
released, but instead, should return an update conflict error immediately. }
tpNowait,
{ Read-only access mode that allows a transaction only to select data from tables. }
tpRead,
{ Read-write access mode of that allows a transaction to select, insert,
update, and delete table data [Default]. }
tpWrite,
{ Read-only access of a specified table. Use in conjunction with tpShared,
tpProtected, and tpExclusive to establish the lock option. }
tpLockRead,
{ Read-write access of a specified table. Use in conjunction with tpShared,
tpProtected, and tpExclusive to establish the lock option [Default]. }
tpLockWrite,
tpVerbTime,
tpCommitTime,
tpIgnoreLimbo,
{ Unlike a concurrency transaction, a read committed transaction sees changes
made and committed by transactions that were active after this transaction started. }
tpReadCommitted,
tpAutoCommit,
{ Enables an tpReadCommitted transaction to read only the latest committed
version of a record. }
tpRecVersion,
tpNoRecVersion,
tpRestartRequests,
tpNoAutoUndo
);
{ Set of transaction parameters. }
TTransParams = set of TTransParam;
{This evenet occur before to end the transaction, you can change the ETM parametter.}
TOnEndTransaction = procedure(Sender: TObject; var Mode: TEndTransMode) of object;
{ The Transaction component. }
TJvUIBTransaction = class(TJvUIBComponent)
private
FDataBase: TJvUIBDataBase;
FDataBases: TList;
FTrHandle: IscTrHandle;
FSQLComponent: TList;
FStatements: Integer;
FOptions : TTransParams;
FLockRead : string;
FLockWrite : string;
FSQLDialect: Integer;
FOnStartTransaction: TNotifyEvent;
FOnEndTransaction: TOnEndTransaction;
FAutoRetain: boolean;
FAutoStart: boolean;
FAutoStop: boolean;
FDefaultAction: TEndTransMode;
function GetInTransaction: Boolean;
function TPB: string;
function GetOptions: TTransParams;
procedure SetOptions(const Value: TTransParams);
function GetLockRead: string;
function GetLockWrite: string;
procedure SetLockRead(const Value: string);
procedure SetLockWrite(const Value: string);
function GetDataBase: TJvUIBDataBase;
procedure BeginDataBase;
procedure BeginTransaction(Auto: boolean = True);
function EndTransaction(ETM: TEndTransMode; From: TJvUIBStatement;
Auto: boolean): boolean;
procedure AddSQLComponent(Component: TJvUIBStatement);
procedure RemoveSQLComponent(Component: TJvUIBStatement);
procedure ClearSQLComponents;
procedure Close(const Mode: TEndTransMode; Auto: boolean);
function GetStatements(const Index: Integer): TJvUIBStatement;
function GetStatementsCount: Integer;
procedure ClearDataBases;
function GetDatabases(const Index: Integer): TJvUIBDataBase;
function GetDatabasesCount: Integer;
function GetAutoRetain: boolean;
procedure SetAutoRetain(const Value: boolean);
procedure SetDefaultAction(const Value: TEndTransMode);
protected
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
procedure SetDataBase(const ADatabase: TJvUIBDataBase); virtual;
public
{ Constructor method. }
constructor Create(AOwner: TComponent); override;
{ Destructor method.}
destructor Destroy; override;
{ cf TjvUIBComponent.Lock }
procedure Lock; override;
{ cf TjvUIBComponent.UnLock }
procedure UnLock; override;
{ Add a database to the transaction. }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -