Subject Re: [firebird-support] Executing a block of statements in C++
Author Helen Borrie
At 01:00 AM 23/12/2004 +0000, you wrote:


>Hi all,
>
>I am fairly new with Firebird, although I have previously worked
>with many other database systems. I am evaluating Firebird for an
>embedded application database, and I have (hopefully a simple)
>question on executing a group of SQL DDL statements.
>
>I am using Microsoft Visual C++ (.NET 2003, but no .NET extensions,
>just raw C++), and the Interbase/Firebird API.
>
>My app can create the DB well enough (using
>isc_dsql_execute_immediate), but now I'm having problems executing
>what I think should be a pretty straightforward script. Essentially,
>I want to create (as an example) a set of generators... so I create
>a script as follows:
>
>create generator gen1;
>create generator gen2;
>create generator gen3;
>create generator gen4;
>create generator gen5;
>create generator gen6;
>
>Now I try to execute this, and I get an error as follows:
>Invalid token.
>Dynamic SQL Error.
>SQL error code = -104.
>Token unknown - line 2, char 1.
>create.

Yup. In DSQL you can execute only one statement at a time. Executing a
script is something you do through a tool, either of your own making or
using an existing one. For example, look at the Ops Guide to see how to
execute a script file from the command line via isql using the -input
switch. Or, otherwise, code your program so it iterates through some kind
of list of statements that you introduce as hard code or read from a file,
whatever you prefer.


>Am I able to execute this as one block, or do I have to separate
>them into separate commands? I would think that I should be able to
>submit this as a single script (for example, my DDL statements for
>creating my tables, views, stored procedures, triggers etc.) instead
>of a bunch of single statements over the wire.

If you're writing to the raw API, no, not if you don't write code to do it
by one fashion or another. If you are using a component interface that
provides a scripting capability then yes. There are things to watch out
for when executing scripts programmatically, since exceptions will occur if
you try to do stuff that depends on objects that your app code hasn't
committed.


>I'm not sure what I'm missing here :(

I can tell. :-) Maybe you should ask Santa for a copy of The Firebird Book.

./hb