📄 jvquib.pas
字号:
procedure AddDataBase(ADataBase: TJvUIBDataBase);
{ Remove a database from a transaction. }
procedure RemoveDatabase(ADataBase: TJvUIBDataBase); overload;
{ Remove a database from a transaction. }
procedure RemoveDatabase(Index: Integer); overload;
{Start Transaction.}
Procedure StartTransaction;
{Commit transaction.}
procedure Commit;
{Commit transaction but keep transaction handle.}
procedure CommitRetaining;
{Rollback transaction.}
procedure RollBack;
{Rollback transaction but keep transaction handle.}
procedure RollBackRetaining;
{Indicate if the transaction is active.}
{$IFDEF IB71_UP}
{ Interbase 7.1 spceficic, Release a savepoint.
On Firebird 1.5 this must be call by SQL.}
procedure SavepointRelease(const Name: string);
{ Interbase 7.1 spceficic, RollBack a savepoint.
On Firebird 1.5 this must be call by SQL.}
procedure SavepointRollback(const Name: string; Option: Word = 0);
{ Interbase 7.1 spceficic, Start a savepoint.
On Firebird 1.5 this must be call by SQL.}
procedure SavepointStart(const Name: string);
{$ENDIF IB71_UP}
property InTransaction: Boolean read GetInTransaction;
{Transaction handle.}
property TrHandle: IscTrHandle read FTrHandle;
{ Queries connected to this transaction.}
property Statements[const Index: Integer]: TJvUIBStatement read GetStatements;
{ Number of Queries connected to this transaction.}
property StatementsCount: Integer read GetStatementsCount;
{ Get all databases attached to the transaction. }
property Databases[const Index: Integer]: TJvUIBDataBase read GetDatabases;
{ How many databases attached to the transaction. }
property DatabasesCount: Integer read GetDatabasesCount;
published
{Database connection.}
property DataBase : TJvUIBDataBase read GetDataBase write SetDataBase;
{Transaction parametters.}
property Options : TTransParams read GetOptions write SetOptions default [tpConcurrency,tpWait,tpWrite];
{List of the tables to lock for read, tpLockRead option must set. ex: 'Table1;Table2'}
property LockRead : string read GetLockRead write SetLockRead;
{List of the tables to lock for write, tpLockWrite option must set. ex: 'Table1;Table2'}
property LockWrite : string read GetLockWrite write SetLockWrite;
{This event occur after a transaction is started.}
property OnStartTransaction: TNotifyEvent read FOnStartTransaction write FOnStartTransaction;
{This evenet occur before to end the transaction, you can change the ETM parametter.}
property OnEndTransaction: TOnEndTransaction read FOnEndTransaction write FOnEndTransaction;
{If false, commit and rollback close all connected statements and finally close transaction.
If True, commit and rollback are modified to commitretaining or rollbackretaining if at least one statement is open.}
property AutoRetain: boolean read GetAutoRetain write SetAutoRetain default False;
{If True, transaction automatically started when needed.
if False you must explicitely call "starttransaction".}
property AutoStart: boolean read FAutoStart write FAutoStart default True;
{default = false, if True you need to close transaction explicitly.}
property AutoStop: boolean read FAutoStop write FAutoStop default True;
{Transaction default action if closed automaticaly, commit or rollback only.}
property DefaultAction: TEndTransMode read FDefaultAction write SetDefaultAction default etmCommit;
end;
{ Simple query component. }
TJvUIBStatement = class(TJvUIBComponent)
private
FCurrentState: TQueryState;
FTransaction: TJvUIBTransaction;
FDataBase: TJvUIBDataBase;
FStHandle: IscStmtHandle;
FOnError: TEndTransMode;
FCursorName: string;
FSQLResult: TSQLResult;
FCachedFetch: boolean;
FFetchBlobs: boolean;
FBufferChunks: Cardinal;
FQuickScript: boolean;
FSQL: TStrings;
FParsedSQL: string;
FParameter: TSQLParams;
FParseParams: boolean;
FOnClose: TNotifyEvent;
FStatementType: TUIBStatementType;
FUseCursor: boolean;
function GetPlan: string;
function GetStatementType: TUIBStatementType;
procedure SetSQL(const Value: TStrings);
procedure DoSQLChange(Sender: TObject);
function GetFields: TSQLResult;
function GetEof: boolean;
function FindDataBase: TJvUIBDataBase;
function GetRowsAffected: Cardinal;
function GetBof: boolean;
protected
procedure SetTransaction(const Transaction: TJvUIBTransaction); virtual;
procedure SetDataBase(ADataBase: TJvUIBDataBase);
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
procedure BeginTransaction; virtual;
procedure BeginStatement; virtual;
procedure BeginPrepare; virtual;
procedure BeginExecute; virtual;
procedure BeginExecImme; virtual;
procedure EndTransaction(const ETM: TEndTransMode; Auto: boolean); virtual;
procedure EndStatement(const ETM: TEndTransMode; Auto: boolean); virtual;
procedure EndPrepare(const ETM: TEndTransMode; Auto: boolean); virtual;
procedure EndExecute(const ETM: TEndTransMode; Auto: boolean); virtual;
procedure EndExecImme(const ETM: TEndTransMode; Auto: boolean); virtual;
procedure InternalNext; virtual;
procedure InternalPrior; virtual;
procedure InternalClose(const Mode: TEndTransMode; Auto: boolean); virtual;
function ParamsClass: TSQLParamsClass; virtual;
function ResultClass: TSQLResultClass; virtual;
procedure InternalGetBlobSize(sqlda: TSQLDA; const Index: Word; out Size: Cardinal);
procedure InternalReadBlob(sqlda: TSQLDA; const Index: Word; Stream: TStream); overload;
procedure InternalReadBlob(sqlda: TSQLDA; const Index: Word; var str: string); overload;
procedure InternalReadBlob(sqlda: TSQLDA; const Index: Word; var Value: Variant); overload;
procedure InternalReadBlob(sqlda: TSQLDA; const Index: Word; Buffer: Pointer); overload;
property QuickScript: boolean read FQuickScript write FQuickScript default False;
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;
{ Close the statement. You can commit or rollback the transaction when closing. }
procedure Close(const Mode: TEndTransMode = etmStayIn); virtual;
{ Fetch all records returned by the query. }
procedure CloseCursor;
procedure FetchAll;
{ Open the query and fetch the first record if FetchFirst = true. }
procedure Open(FetchFirst: boolean = True);
{ Prepare the query. }
procedure Prepare;
{ Execute the query. }
procedure Execute;
{ Execute the query or the script (QuickScript = true) immediately. }
procedure ExecSQL;
{ Get the next record. }
procedure Next;
{ Get the prior record. }
procedure Prior;
{ Get the last record. }
procedure Last;
{ Get the first record. }
procedure First;
{ Read a the blob in a stream by index. }
procedure ReadBlob(const Index: Word; Stream: TStream); overload;
{ Read a the blob in a string by index. }
procedure ReadBlob(const Index: Word; var str: string); overload;
{ Read a the blob in a Variant by index. }
procedure ReadBlob(const Index: Word; var Value: Variant); overload;
{ Read a the blob in a PREALLOCATED buffer by index. }
procedure ReadBlob(const Index: Word; Buffer: Pointer); overload;
{ Read a the blob in a stream by name. }
procedure ReadBlob(const name: string; Stream: TStream); overload;
{ Read a the blob in a string by name. }
procedure ReadBlob(const name: string; var str: string); overload;
{ Read a the blob in a Variant by name. }
procedure ReadBlob(const name: string; var Value: Variant); overload;
{ Read a the blob in a PREALLOCATED buffer by name. }
procedure ReadBlob(const name: string; Buffer: Pointer); overload;
{ The the blob value of a parametter using a Stream. }
procedure ParamsSetBlob(const Index: Word; Stream: TStream); overload;
{ The the blob value of a parametter using a string. }
procedure ParamsSetBlob(const Index: Word; var str: string); overload;
{ The the blob value of a parametter using a Buffer. }
procedure ParamsSetBlob(const Index: Word; Buffer: Pointer; Size: Cardinal); overload;
{ The the blob value of a parametter using a Stream. }
procedure ParamsSetBlob(const Name: string; Stream: TStream); overload;
{ The the blob value of a parametter using a string. }
procedure ParamsSetBlob(const Name: string; var str: string); overload;
{ The the blob value of a parametter using a Buffer. }
procedure ParamsSetBlob(const Name: string; Buffer: Pointer; Size: Cardinal); overload;
{ Get the the blob size of the current record. }
function FieldBlobSize(const Index: Word): Cardinal;
{ Get the blob size of the corresonding parametter. }
function ParamBlobSize(const Index: Word): Cardinal;
{ The internal statement handle. }
property StHandle: IscStmtHandle read FStHandle;
{ Use fields to read the current record. }
property Fields: TSQLResult read GetFields;
{ use Params to set parametters, the param names are set dynamically
parsing the SQL query, by default the param values are null string.
The first time you set a parametter value, the field type is defined. }
property Params: TSQLParams read FParameter;
{ All UIB statements declare a unique cursor name, another query can use
this cursor to modify the current cursor, this feature is for unidirectionnal
statements !!.<br>
ex: UPDATE proj_dept_budget SET projected_budget = :value WHERE CURRENT OF %s; }
property CursorName: string read FCursorName;
{ Indicate the current state of the query. }
property CurrentState: TQueryState read FCurrentState;
{ if true there isn't anymore record to fetch. }
property Eof: boolean read GetEof;
property Bof: boolean read GetBof;
{ @exclude }
property ParseParams: boolean read FParseParams write FParseParams;
{ The plan used internally by interbase (the query must be prepared). }
property Plan: string read GetPlan;
{ Get the current statement type (the query must be prepared). }
property StatementType: TUIBStatementType read GetStatementType;
{ Return the number of rows affected by the query (stInsert, stUpdate or stDelete). }
property RowsAffected: Cardinal read GetRowsAffected;
property UseCursor: boolean read FUseCursor write FUseCursor default True;
published
{ The sql query. }
property SQL: TStrings read FSQL write SetSQL;
{ Transaction of the query. }
property Transaction: TJvUIBTransaction read FTransaction write SetTransaction;
{ Connected database, in most cases you don't need to set this property, it is
only needed if the transaction concern more than one database. }
property DataBase: TJvUIBDataBase read FDataBase write SetDataBase;
{ If an error occur, this action is applied to the connected transaction. }
property OnError: TEndTransMode read FOnError write FOnError default etmRollback;
{ If true all record are saved in memory. }
property CachedFetch: boolean read FCachedFetch write FCachedFetch default True;
{ If true the blob data is fetched with the record. }
property FetchBlobs: boolean read FFetchBlobs write FFetchBlobs default False;
{ Use BufferChunks to get or set the number of records for which the query
allocates buffer space at any time. When the query抯 buffer is full,
trying to fetch an additional record causes the dataset to reallocate
the buffer so that it has enough memory to hold an additional BufferChunks
records. <br>
Note: When CachedFetch is False, BufferChunks has no meaning. }
property BufferChunks: Cardinal read FBufferChunks write FBufferChunks default 1000;
{ OnClose event. }
property OnClose: TNotifyEvent read FOnClose write FOnClose;
end;
{Oo.......................................................................oO
TUIBQuery
Oo.......................................................................oO}
{ The query component. }
TJvUIBQuery = class(TJvUIBStatement)
public
{ Helper method to buid the SQL query needed to execute the stored procedure.
Input data type found using this method. }
procedure BuildStoredProc(const StoredProc: string);
published
{ If true you can use this component as a fast script component where each line is a query.
You must use the ExecSQL method ! }
property QuickScript;
end;
{ Parsing event, occur on each query executed. }
TOnParse = procedure(Sender: TObject; NodeType: TSQLNodeType;
const Statement: string; Position, Count: Integer) of object;
{ The script component. }
TJvUIBScript = class(TJvUIBComponent)
private
FQuery: TJvUIBQuery;
FScript: TStrings;
FAutoDDL: boolean;
FOnParse: TOnParse;
procedure SetTransaction(const Value: TJvUIBTransaction);
function GetTransaction: TJvUIBTransaction;
procedure SetScript(const Value: TStrings);
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure ExecuteScript;
published
property Transaction: TJvUIBTransaction read GetTransaction write SetTransaction;
property Script: TStrings read FScript write SetScript;
property AutoDDL: boolean read FAutoDDL write FAutoDDL default True;
property OnParse: TOnParse read FOnParse write FOnParse;
end;
TUIBProtocol = (
proLocalHost,
proTCPIP,
proNetBEUI
);
TJvUIBService = class(TJvUIBComponent)
private
FLibrary: TUIBLibrary;
FLiBraryName: string;
FUserName: string;
FPassWord: string;
FHost : string;
FProtocol: TUIBProtocol;
FHandle : IscSvcHandle;
procedure BeginService;
procedure EndService;
function CreateSPB: string; virtual;
procedure SetLibraryName(const Lib: String);
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
property UserName: string read FUserName write FUserName;
property PassWord: string read FPassWord write FPassWord;
property Host: string read FHost write FHost;
property Protocol: TUIBProtocol read FProtocol write FProtocol default proLocalHost;
{ Define wich library the connection use.}
property LibraryName: string read FLiBraryName write SetLibraryName;
end;
TVerboseEvent = procedure(Sender: TObject; Message: string) of object;
TJvUIBBackupRestore = class(TJvUIBService)
private
FBackupFiles: TStrings;
FDatabase: TFileName;
FOnVerbose: TVerboseEvent;
procedure SetBackupFiles(const Value: TStrings);
function CreateStartSPB: string; virtual; abstract;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure Run;
published
property BackupFiles: TStrings read FBackupFiles write SetBackupFiles;
property Database: TFileName read FDatabase write FDatabase;
property OnVerbose: TVerboseEvent read FOnVerbose write FOnVerbose;
end;
TBackupOption = (boIgnoreChecksums, boIgnoreLimbo, boMetadataOnly,
boNoGarbageCollection, boOldMetadataDesc, boNonTransportable,
boConvertExtTables, boExpand);
TBackupOptions = set of TBackupOption;
TJvUIBBackup = class(TJvUIBBackupRestore)
private
FOptions: TBackupOptions;
function CreateStartSPB: string; override;
published
property Options: TBackupOptions read FOptions write FOptions default [];
end;
TRestoreOption = (roDeactivateIndexes, roNoShadow, roNoValidityCheck,
roOneRelationAtATime, roReplace, roCreateNewDB, roUseAllSpace
{$IFDEF IB71_UP},roValidate{$ENDIF});
TRestoreOptions = set of TRestoreOption;
TJvUIBRestore = class(TJvUIBBackupRestore)
private
FOptions: TRestoreOptions;
FPageSize: Cardinal;
function CreateStartSPB: string; override;
public
constructor Create(AOwner: TComponent); override;
published
property Options: TRestoreOptions read FOptions write FOptions default [roCreateNewDB];
property PageSize: Cardinal read FPageSize write FPageSize default 0;
end;
implementation
uses
{$IFDEF UNITVERSIONING}
JclUnitVersioning,
{$ENDIF UNITVERSIONING}
Math,
JvQUIBMetaData;
type
PExceptionInfo = ^TExceptionInfo;
TExceptionInfo = record
ExepClass: EUIBExceptionClass;
ID: Integer;
end;
{ TJvUIBDataBase }
procedure TJvUIBDataBase.AddTransaction(Transaction: TJvUIBTransaction);
begin
if (FTransactions = nil) then FTransactions := TList.Create;
FTransactions.Add(Transaction);
end;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -