Consultor Eletrônico



Kbase P115900: How to delete a database table dynamically given its name and its database name when multiple databa
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   09/05/2006
Status: Unverified

GOAL:

How to delete a database table dynamically given its name and its database name when multiple databases are connected to the 4GL application?

FIX:

The following code demonstrates how to delete a table given its name and its database name. The following code assumes that the application is connected to multiple databases and that no other clients are connected to the database of the table that will be deleted:
DEFINE VARIABLE cDatabaseName AS CHARACTER NO-UNDO.
DEFINE VARIABLE cTableName AS CHARACTER NO-UNDO.
/* Initialize the names of the table and its database */
ASSIGN
cDatabaseName = "seconddb"
cTableName = "Employee".
CREATE ALIAS "DICTDB" FOR DATABASE VALUE(cDatabaseName) NO-ERROR.
FIND FIRST DICTDB._File WHERE _File-Name = cTableName NO-LOCK.
/* Delete All Index and Index Fields of the table */
FOR EACH _Index OF _File:
FOR EACH _Index-field OF _Index:
DELETE _Index-field.
END.
DELETE _Index.
END.
/* Delete All File Triggers of the table */
FOR EACH _File-trig OF _File:
DELETE _File-trig.
END.
/* Delete All Fields and Field Triggers of the table */
FOR EACH _Field OF _File:
FOR EACH _Field-trig OF _Field:
DELETE _Field-trig.
END.
DELETE _Field.
END.
/* Delete the table */
DELETE _File.
DELETE ALIAS DICTDB.