You are on page 1of 7

IBXtras documentation Please report any errors in either the documentation or the

actual components to the InterBase express newsgroup


borland.public.delphi.database.interbaseexpress. These components have been
written over many years. The oldest was originally written 4 years ago so some of
the code may not be the prettiest to look at <g>. I am making these available
because I and others have found them useful in the past. I will also put up very
simple demos for the IBScript and IBConnectionBroker onto CodeCentral. Due to
anticipated interface changes IBXtras only comes as a design time package so the
components can only be statically linked into an Exe.
IBConnectionBroker This is a in process connection pooler. It allows you to setup a
minimum and maximum number of connections to have threads pool from. It hands out a
IBSatabase/IBTransaction pair. You do not have to use the transaction if youd like, but
on returning the transaction the pooler will only end the transaction that it owns.
While it does allow for request starvation, it currently does not reclaim connections that
are taken and never returned. This is a planned feature for later. Another planned
features is to pull back from the max if the load decreases over time back down to the
minimum number of active connections.
Procedures
function GetConnection: TIBDatabase - This is called to get a connection. If due
to all the connections being allocated GetConnection will return nil and it is up to
the caller to handle this situation. Usually this will just be recalling GetDatabase
until a database is finally returned.
constructor Create(aowner: tcomponent) Standard constructor. It will create and
connect the minimum number of connections. While designing Ive found that
setting the minimum connections to 1 starts things up faster until you are ready to
do more extensive testing.
destructor Destroy; - This cleans up the IBDatabases and IBTransactions. If a
thread has a connection and you destroy the pooler the connection will be
destroyed from underneath thread. You can check AllocatedConnections for non
zero to see if the pooler has any allocated connections still outstanding.
procedure ReleaseConnection(db: TIBDatabase); - Returns the connection to the
pool. If the transaction is active it closes the transaction.
Properties
public
property AllocatedConnections : Integer Read only. Returns the number of
currently given out connections.

property AvailableConnections : Integer Read only. Returns the number of


available databases (both already connected or disconnected).
published
property DatabaseName : string Same as for TIBDatabase.
property Params : TStrings Same as for TIBDatabase. There is a component
editor to help fill this and the DatabaseName. Right click on the component and
select Connection Broker Editor.
property MinConnections : Integer default 10 Minimum number of connections
to create on startup.
property MaxConnections : Integer default 20 Maximum number of conenctions
the pooler will create.
property TransactionIdleTimer : Cardinal The IdleTimer property for the given
out TIBTransaction.
property ExhustedDelay : Cardinal default 500 This is how long the pooler
should wait when the pool is currently exhusted. Timed in millseconds.
property OnLog : TIBConnectionBrokerLogEvent Log event to track what is
going on internally.
TIBConnectionBrokerLogEvent = procedure(Sender : TObject; LogMessage : String) of
object;
TIBDatabaseINI This fairly simple component was designed to solve the problem of
deployment when the database location is different than the design location. When
combined with IBDatabases AllowStreamedConnected (set to false) it makes it easy to
switch the connection information on the fly. During load time the component will
change the IBDatabases properties automatically.
Procedures
procedure SaveToINI Saves the current settings to the INI file.
procedure ReadFromINI Reads the current settings from the INI file.
procedure WriteToDatabase(ADatabase : TIBDatabase) Copies the current
settings to the IBDatabase component.
procedure ReadFromDatabase Pulls the settings from the IBDatabase
component.

function IniFileName : string Name of the INI file. Depending on the


UseAppPath setting will return the appropriate path.
Properties
Published
property Database : TIBDatabase Database whose properties will be updated.
property DatabaseName : String Corresponds to the IBDatabase DatabaseName.
property Username : String Username to set in the Database.
property Password : String Password to set in the Database.
property SQLRole : String Role to set in the Database.
property FileName : String INI file name.
property UseAppPath : TIniFilePathOpt Setups the different methods to locate
the INI file.
TIniFilePathOpt ipoPathNone No path options. Left up to the OS to determine.
ipoPathToServer prepends the path to the EXE for locating the INI file.
ipoPathRelative Setups a path relative to the current working directory.
property Section : String The section header for the INI file. This allows you to
reuse INI files to hold multiple settings.
IBSQLParser This is a component that takes a SQL script and will parse it into its
individual SQL statements. It supports all DML, DDL, CONNECT, CREATE, DROP
DATABASE, COMMIT, ROLLBACK, INPUT, and SET [TERM | SQL DIALECT |
STATISTICS] statements.
Procedures
procedure Parse Initiates the Parser to parse the Script.
property CurrentLine: Integer The current line of the script that is being parsed.
property CurrentTokens: TStrings Access to the current statements tokenized
form. The tokenizer is not interested in fully tokenizing the SLQ statement, only
tokenize it will enough to tell what type it really is. For instance Select
emp_no,dept_no from employee will result in 4 tokens SELECT,
EMP_NO,DEPT_NO, FROM, and EMPLOYEE.

Properties
property Finished: Boolean True when there is nothing left to parse.
property Paused: Boolean Whether or not the parser is paused or not.
property Script: TStrings The script to parse.
property Terminator: string Current terminator for the script. Default to ;. The
Terminator remains the same as it was at the end of the previous parsing so if you
do a set term ^; and never set it back to ; the terminator remains ^ on the next
script parsing.
property OnParse: TIBSQLParseStmt Event that passes the SQL type and the
SQL statement out of the parser.
TIBSQLParseStmt = procedure(Sender: TObject; AKind: TIBParseKind;
SQLText: string) of object;
TIBParseKind
stmtDDL DDL statement.
stmtDML DML Statement.
stmtSET SET statement (note the SET is stripped).
stmtCONNECT Connect statement.
stmtDrop Drop Database statement.
stmtCREATE Create Database statement.
stmtINPUT Input from another file statement.
stmtUNK Unknown. The parser could not determine the
statement type.
stmtEMPTY Empty statement. (Never returned in a OnParse
event)
stmtTERM Set TERM statement. Only the terminator is passed.
stmtERR Error state. It is rare that the parser can continue after
this.
stmtCOMMIT Commit statement.
stmtROLLBACK Rollback statement.
property OnError: TIBSQLParseError Event fired when there is a parser error.
Continuation after an error is rare.
TIBSQLParseError = procedure(Sender: TObject; Error: string; SQLText: string;
LineIndex: Integer) of object;

IBScript This will run and execute a valid SQL script. It allows for retrieving of
parameters for parameterized SQL statements.
Procedures
function ValidateScript: Boolean Parses but does not execute the script. Returns
true if it parses without error, false otherwise.
procedure ExecuteScript Actually executes the script.
function ParamByName(Idx : String) : TIBXSQLVAR Allows for the setting of
parameters when the execution is paused to get parameters (see OnParamCheck
event).
Properties
Public
property Paused: Boolean Whether or not the Script is paused during its
execution.
property Params: TIBXSQLDA Retrieves the IBXSQLDA structure for setting
parameters.
property Stats : TIBScriptStats When stats are on (default) gets at the stats for
the most recently run script. Stats should be paused every time the Script is
paused.
Published
property AutoDDL: Boolean default true Whether or not DDL statements
should be commited automatically. When true DDL is executed in a separate
transaction than the DML statements.
property Dataset: TIBDataset When a Dataset is attached then the DML is run
through that Dataset. It allows for things like scripting multiple statemetns that
ends with a select statement and you have an open result set at the end.
property Database: TIBDatabase The database to use for the script.
property Transaction: TIBTransaction The transaction to use for DML and DDL
(Auto DDL false) statements.
property Terminator: string Current terminator for the Script. Defaults to ;, but
retains the last set terminator on multiple runs.
property Script: TStrings The actual script.

property Statistics: boolean default true Whether or not stats should be kept for
the executing script. Stats can be read from the public Stats property after
execution.
TIBScriptStats See IBDatabaseInfo for the meaning of the properties.
property Buffers
property Reads
property Writes
property SeqReads
property Fetches
property ReadIdx
property DeltaMem
property StartingMem
property OnParse: TIBSQLParseStmt Output of the most recently executed
Script statement (see IBSQLParser OnParseStmt).
property OnParseError: TIBSQLParseError Fires when there is a parsing
problem and the Scriptor cant figure out how to execute the statement. (see
IBSQLParser OnParseError)
property OnExecuteError: TIBSQLExecuteError Fires when there is an error
state returned from the server. Allows for continuation by setting ignore to true
9ignore defaults to false).
TIBSQLExecuteError = procedure(Sender: TObject; Error: string;
SQLText : string; LineIndex: Integer; var Ignore: Boolean) of object;
property OnParamCheck: TIBScriptParamCheck Fires when a DML statement
is determined to have parameters. Either set the param in the event or set Pause to
true and stop the execution at that point so you can setup the params and then set
Paused to false to continue execution (this feature has be tested the least). Access
the Params through ParamByName or the Params property.
TIBScriptParamCheck = procedure(Sender: TIBScript; var Pause:
Boolean) of object;
IBFilterDialog This allows you to have the end user modify (filter) the result set. Its
interface is similar to Woll2Wolls FilterDialog component (their code was not referenced
at all when this was first written over 4 years ago by me for Direct Oracle Access not
during the port to IBX). This is currently a VCL only component and can not be used in
Clx applications. This works by modifying the where clause and re executing the SQL so
be careful using this when in cached update mode due to the potential loss of cached data
when the SQL is re executed.

Procedures
procedure Execute Bring up the dialog for display.
procedure ReBuildSQL Rebuild the SQL based on the new params.
Properties
Public
property ModifiedSQL Returns the SQL generated based on the new input.
Published
property Caption : String Caption for the Dialog
property DataSet : TIBCustomDataset The Dataset to alter (IBDataset or
IBQuery acceptable).
property DefaultMatchType : TIBFilterMatchType default fdMatchStart The
default setting for how string filters should be done.
TIBFilterMatchType
fdMatchExact Does a straight = string
fdMatchStart Does a starting with string
fdMatchEnd Does a = %string
fdMatchAny Does a = %string%
fdMatchRange if only starting then >= value, if only ending then
<= value and if both then it has to be between the two.
fdMatchNone prepends with a not.
property Options : TIBOptions read FOptions write SetOptions default
[fdShowCaseSensitive, fdShowNonMatching];
TIBOptions = Set of TIBOption;
TIBOption =
fdCaseSensitive Leaves the string exactly as type when checked,
upper cases it when unchecked (default)
fdShowCaseSensitive whether or not the case sensitive check
box should be shown.
fdShowNonMatching Whether or not the Not Matching check
box should be shown.
property Fields : TStringList Allows you to restrict what fields will be shown in
the dialog.

You might also like