Subject Isn't possible to create many triggers/procedures by a executeBatch?
Author edilista
Hi,

I have a Swing app that may be running in many places, with default or
not default installation of Firebird. Then, I don't know where it is
installed, and I can't use ISQL to run my scripts.

I made a gerenal code to run scripts, I think it is more complete than
code in this Jaybird page
<http://jaybirdwiki.firebirdsql.org/jaybird/doku.php?id=tip:script_suppo\
rt&s=set+term> because it accepts comments (/* ... */), changing
terminator character from default ";", checks size of buffer read when
comparing if the string starts with "SET TERM" and other things I didn't
find in the original link.

After solve my problem, I'd like to send my code to contrib with Jaybird
"Tips and Tricks".

But the problem is...

I have the following SQL script, with so many different commands:

<pre>
Drop Table tabestr;
Drop Index XPKtab;
Drop Index XAKtab;
Drop Trigger Novocodtab;
/*
Drop Procedure Novocodtab2;
Drop Generator codtab_Gen;
*/
Drop Table tab;

Create Table tab(
codtab int not null,
descr varchar(50),
primary key(codtab)
);

CREATE UNIQUE INDEX XPKtab ON tab
(
codtab
);

CREATE INDEX XAKtab ON tab
(
descr
);

Alter Table tab
add descr2 char(1);

Create Table tabestr(
codtabestr int not null,
descr varchar(50),
codtab int,
primary key(codtabestr)
);

/*
ALTER TABLE tabestr
ADD CONSTRAINT R_1000
FOREIGN KEY (codtab)
REFERENCES tab;
*/

Create Generator codtab_Gen;

/*
Set Term ^ ;

Create Trigger Novocodtab For tab
Before Insert As
Begin
if (New.codtab is null) then
begin
New.codtab = Gen_Id(codtab_Gen,1);
end
End ^

Create Procedure Novocodtab2
Returns (PCod integer)
As
Begin
Select Gen_Id(codtab_Gen, 1)
From rdb$database
Into PCod;
End ^

Set Term ; ^
*/

Alter Table tab
add descr3 char(1);
</pre>

The code commented for "foreign key" I think it doesn't have solution in
my case, because I don't know how to disconnected all other users of the
database to run it. Then, I'll try other way for it.

The main problem occurs with "SET TERM" command.
I need it to allow creation of triggers/procedures/etc.

But, when I uncomment the code between the two SET TERM's Jaybird
2.0.1/Firebird 1.5 arises this exception:
<pre>
java.sql.BatchUpdateException: Dynamic SQL Error
SQL error code = -104
Token unknown - line 1, char 5
TERM
at
org.firebirdsql.jdbc.AbstractStatement.executeBatch(AbstractStatement.ja\
va:982)
at SubMacroUtils.Versao.executarSQL(Versao.java:178)
at SubMacroUtils.Versao.atualizar(Versao.java:98)
</pre>

I think Jaybird doesn't understand "SET TERM" like a normal SQL command
to run into database.

Isn't possible to create a script like this to run by Jaybird?




[Non-text portions of this message have been removed]