Subject Re: [ib-support] Re: -- Comment
Author Claudio Valderrama C.
"Paul Reeves" <paul@...> wrote in message
news:<3BF4C75F.8E17DD41@...>...
>
> OK, try this:
>
> ====
>
> /*-- Create database*/
>
> CREATE DATABASE "x:\data\ods10\controller.gdb"
> USER 'SYSDBA' PASSWORD 'masterkey';
>
> CONNECT 'x:\data\ods10\Controller.gdb' USER 'SYSDBA' PASSWORD 'masterkey';
>
> --now drop it
> drop database;
>
> /* OK, Now let's really drop it.*/
> drop database;
>
> /* exit */
> exit;
>
> =====
>
> '--now drop it' is definitely not parsed as a comment. A confusing error
is
> thrown - it counts the line number from the start of the comment, not the
> start of the script.

This time I'm going to enjoy the answer... switching to pedant mode...
enabling system restore in case of a flame war so we can go back to the
previously known safe and peaceful state.
:-) :-) :-)

Paul, take with you the files dsql\parse.y and isql\isql.e

Now, try to find inside parse.y the line where the command
DROP DATABASE is defined. If you find it, I will purchase one year of
support from IBPhoenix.
:-)
You can't find it because the IB/FB syntax doesn't define the DROP DATABASE
command as a DSQL command. You should use the API directly. There's no other
way.

Now, going to to isql.e, we find this chunk:

else if (!strcmp (parms [0], "DROP"))
{
if (!strcmp (parms [1], "DATABASE") || !strcmp (parms [1], "SCHEMA"))
if (*parms [2])
ret = ERR;
else
ret = drop_db ();
else
ret = CONT;
}

You may guess what drop_db() does: it fails if the engine is older than v4,
otherwise it calls the isc_drop_database() API function.

What this means: I said that Mark wanted to fix isql to cope with this "--"
syntax. Mark didn't find time (I've heard that he resurrected yesterday in
our list after 2 months. <g>) Therefore, isql doesn't understand the single
line comment. I've demonstrated that DROP DATABASE is not a thing that's
understood by the engine but only to isql that translates this comment into
a direct API call to delete the db.

Since isql handles DROP DATABASE, the engine never sees a DSQL command. Isql
sends nothing. It calls the API directly. But since you did

--
drop database;

then isql didn't pick the command and sent it to the engine instead. The
engine saw the "--", swallowed it, got the CRLF, ate it and found DROP
DATABASE. It went to the section where the available DROP options are
defined and found drop_clause to accept EXCEPTION, INDEX, PROCEDURE, TABLE,
TRIGGER, VIEW, FILTER, DOMAIN, EXTERNAL FUNCTION, SHADOW, ROLE and
GENERATOR. Since there's no DROP DATABASE, syntax error and voila.

The morale is that unless we fix isql to understand single line comments,
any command that has sense only to isql will fail if you combine it with
"--" because isql can't recognize the command. I think a very easy example
is

--
exit;

This is a command that only isql understands. It will fail because "--" +
CRLF + EXIT is not parsed correctly so it's passed to the engine (under
normal circumsntances, it never gets passed to the engine) and the engine
doesn't understand EXIT in DML statements but only inside stored procedures.


> I've done some more tests on this and as far as I can tell the '--'
comment
> marker only works inside SPs.

Sorry to say that you are wrong. I filled myself a bug report against my
first implementation of the single line command. It seems the title was
"single line comment defeats lexer". If you are able to find the entry among
our closed bugs, you will find a really bizarre example that demonstrates
you can have things like

select
-- this is my first attempt
column_name
-- here goes the FROM in SQL
from
-- here goes the table
tbl_name;

and they work. Here you have a real example:

H:\ibdev\fbbuild\interbase\dsql>isql h:/proy/fbtest.gdb
Database: h:/proy/fbtest.gdb
SQL> select
CON> --this is my first attempt
CON> rdb$relation_id
CON> -- here goes the FROM in SQL
CON> from
CON> -- here goes the table
CON> rdb$database;

RDB$RELATION_ID
===============

222

SQL> ^Z


> Interesting explanation about the parser problems, btw. Do you mind if I
tidy
> it up for an RC1 FAQ I am writing?

Why don't you allow Doug to write that section?
:-) :-) :-)

C.
---------
Claudio Valderrama C.
Ingeniero en Informática - Consultor independiente
http://www.cvalde.com - http://www.firebirdSQL.org