Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 3 of 3 total
Thread Drop table by the script
Fri, Apr 15 2016 5:15 AMPermanent Link

宮腰 具明

SISAN SYSTEM RESEARCH. Co. Ltd.

Avatar

Hi there ...

I tried to go the execution of the following.

SCRIPT()
BEGIN
 IF EXIST DROP TABLE "DUST_Table"
END

It did not work.

> The IF EXISTS clause is no longer supported. ElevateDB uses catalog queries to determine
> if a table exists. Please see the System Information topic for more information.

mmm...
Then, I wrote the following script.

SCRIPT()
BEGIN
IF SELECT COUNT(*) FROM Information.Tables  WHERE NAME="DUST_Table" = 1 THEN
   EXECUTE IMMEDIATE 'DROP TABLE ""DUST_Table"';
END IF;
END

it did not work

Please tell me the way.
Fri, Apr 15 2016 6:07 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Tomoaki

>SCRIPT()
>BEGIN
> IF SELECT COUNT(*) FROM Information.Tables WHERE NAME="DUST_Table" = 1 THEN
> EXECUTE IMMEDIATE 'DROP TABLE ""DUST_Table"';
> END IF;
>END

Guessing from your comment about IF EXISTS you come from DBISAM. Scripts in ElevateDB are totally different and you can't just place a line of SQL and expect it to work.

You have a number of options:

1. SImplest

SCRIPT()
BEGIN
BEGIN
EXECUTE IMMEDIATE 'DROP TABLE DUST_Table';
EXCEPTION
END;
END



2. Like yours

SCRIPT()
BEGIN
DECLARE HowMany INTEGER;

EXECUTE IMMEDIATE 'SELECT COUNT(*) INTO ? FROM Information.Tables  WHERE NAME = ' +QUOTEDSTR('DUST_Table') USING HowMany;
IF HowMany = 1 THEN
   EXECUTE IMMEDIATE 'DROP TABLE ""DUST_Table"';
END IF;
END

3. Similar to the above but using internally declared cursors rather than an EXECUTE IMMEDIATE

SCRIPT
BEGIN
 DECLARE InfoCursor SENSITIVE CURSOR FOR InfoStmt;
 PREPARE InfoStmt FROM 'SELECT * FROM Information.Tables WHERE Name=?'

/* Drop the table if it exists */
 OPEN InfoCursor USING 'DUST_Table';
 IF (ROWCOUNT(InfoCursor) > 0) THEN
   EXECUTE IMMEDIATE 'DROP TABLE DUST_Table';
 END IF;
END


Roy Lambert
Sun, Apr 17 2016 7:54 PMPermanent Link

宮腰 具明

SISAN SYSTEM RESEARCH. Co. Ltd.

Avatar

Roy

Thank you. Rewrite the script in a way that use the "exepution".

Tomoaki Miyakoshi
Image