Board index » delphi » Problem: Procedure that deletes table only if table exists doesn't work

Problem: Procedure that deletes table only if table exists doesn't work

Hi,
My stored procedure can't be compiled ("token unknown: DROP"). Is there an
error or I shoul use OTHER way to do this (procedure should delete table
only if the table exist).
Greetings,

SET TERM ^ ;

CREATE PROCEDURE DelTable(cTableName VARCHAR(15))
AS
declare variable nRecCount INTEGER;
BEGIN
   SELECT COUNT(*)
   FROM rdb$relations
   WHERE rdb$relation_name = :cTableName
   INTO :nRecCount;
   IF (:nRecCount > 0) THEN
      DROP TABLE :cTableName
END^

SET TERM ; ^

 

Re:Problem: Procedure that deletes table only if table exists doesn't work


IB6 documentation set, Language Reference on 'CREATE STORED PROCEDURE':

"Important: InterBase does not allow database changed that affect the
behaviour of an existing stored procedure (for example: DROP TABLE..."

In short: no DDL is allowed in procedures or triggers.

If you read the chapter on Stored Procedure and Trigger Language, you can
read what statements are accepted and what aren't.

--
Martijn Tonies
Upscene Productions

InterBase Workbench - The Developer Tool for InterBase
http://www.interbaseworkbench.com

"Experience is what you get when you didn't get what you wanted"

"Umberto" <umbe...@poland.com> schreef in bericht news:3c061243$1_2@dnews...

Quote
> Hi,
> My stored procedure can't be compiled ("token unknown: DROP"). Is there an
> error or I shoul use OTHER way to do this (procedure should delete table
> only if the table exist).
> Greetings,

> SET TERM ^ ;

> CREATE PROCEDURE DelTable(cTableName VARCHAR(15))
> AS
> declare variable nRecCount INTEGER;
> BEGIN
>    SELECT COUNT(*)
>    FROM rdb$relations
>    WHERE rdb$relation_name = :cTableName
>    INTO :nRecCount;
>    IF (:nRecCount > 0) THEN
>       DROP TABLE :cTableName
> END^

> SET TERM ; ^

Re:Problem: Procedure that deletes table only if table exists doesn't work


Quote
> In short: no DDL is allowed in procedures or triggers.

Thanks for answer. So there is not ANY possibility (other way) to delete
table ONLY if it exists ?

Re:Problem: Procedure that deletes table only if table exists doesn't work


Only if you code it inside your application or ignore the errors when
issueing the DROP TABLE statement.

--
Martijn Tonies
Upscene Productions

InterBase Workbench - The Developer Tool for InterBase
http://www.interbaseworkbench.com

"Experience is what you get when you didn't get what you wanted"

"Umberto" <umbe...@poland.com> schreef in bericht news:3c0615e5_2@dnews...

Quote
> > In short: no DDL is allowed in procedures or triggers.

> Thanks for answer. So there is not ANY possibility (other way) to delete
> table ONLY if it exists ?

Re:Problem: Procedure that deletes table only if table exists doesn't work


Quote
> Only if you code it inside your application or ignore the errors when
> issueing the DROP TABLE statement.

Thanks, you saved my time. Best greetings !

Other Threads