Subject RE: [IBO] Questions about TIB_Script
Author firebird@spence.users.panix.com
>
> -----Original Message-----
> From: IBObjects@yahoogroups.com [mailto:IBObjects@yahoogroups.com] On
Behalf Of Helen Borrie
> Sent: Thursday, July 13, 2006 11:50 PM
> To: IBObjects@yahoogroups.com
> Subject: RE: [IBO] Questions about TIB_Script
>
>
> At 12:48 PM 14/07/2006, Michael Spence wrote:
>
> >procedure TConverterForm.sysCreateScriptMacroSubstitute(Sender:
TComponent;
> > const ATextBlock: string; var ATextResult: string);
> >begin
> > ATextResult := '"' + newDB.Text + '"';
> >end;
> >
> >Here is the SQL statement from the TIB_Script object:
> >
> >CREATE DATABASE <<database>>
> > USER 'SYSDBA' PASSWORD 'masterkey';
> >
> ><< and >> are set as MacroBegin and MacroEnd.
> >
> >I tried
> >
> >CREATE DATABASE "<<database>>"
> > USER 'SYSDBA' PASSWORD 'masterkey';
> >
> >so I wouldn't have to provide the quotes, but then the parser didn't
> >see the macro.
>
> Don't call the "Sys..." procedures to write event handlers, use the
> appropriate "On..." event handler. (You'll find the templates for
> the event handlers on the Events tab of the Object Inspector,
> standard Delphi stuff!) Put the resolutions for all your macros in
> this procedure.

I'm not calling any sys procedures directly, that's the name that
was provided when I double-clicked on the OnMacroSubstitution property
in the OI (standard Delphi stuff), probably because the name of the
object is sysCreateScript, not IB_Script1 <g>.

>
> procedure TConverterForm.IB_Script1MacroSubstitute(Sender: TComponent;
> const ATextBlock: String; var ATextResult: String);
> begin
> if ATextBlock = 'database' then
> ATextResult := QuotedStr(newDB.Text)
> else
> if ATextBlock = 'auser' then .....
> end;
>
> I think you will find you'll get an exception from the server because
> of the illegal use of double quotes in the database path
> argument. Double quotes have one and only one use in SQL, as
> optional delimiters for database objects. Quotes for strings in SQL
> are apostrophes. Besides the above (e.g. if you are using CPPB) you do it
as:
>
> begin
> ATextResult := #39+newDB.Text+#39;
> end;

D'OH!. Well, that explains the exception, 'cause

ATextResult := ''''+newDB.Text+''''; // four apostrophes each

works perfectly. Thanks.

The fact that the database creation worked anyway was my fault (the
code was creating the database twice but it didn't show up because
the create in the script was failing).


>
> >Is there some documentation on how the macro substitution actually works?
>
> Sort of. But there's not much to it, as long as you have a basic
> understanding of the substitute logic and the way Delphi event
> handlers work. There are some examples of actual use in the help
> document for the IBO Replication components.
>
> BTW, make sure you put in some kind of checking to ensure that the
> path exists and will be a valid path for the OS that the database is
> being created on. For Windows, there's a filesystem function, sthg
> like PathExists. For Linux, you'd need to parse it out yourself.
>
> Helen
>