I want to create a script that displays all tables per database with the following line:
proutil <databasename> -C dump <tablename> /data/data
I have the following code so far:
DEF VAR a AS CHAR.
DEF VAR i AS INTEGER.
DO i = 1 TO NUM-DBS:
a = LDBNAME (i).
CREATE ALIAS "DICTDB" FOR DATABASE VALUE (a).
DISPLAY a LABEL "Database name: ". PAUSE.
FOR EACH DICTDB._file NO-LOCK WHERE DICTDB._file._Tbl-Type = "T":
PUT 'proutil ' a ' -C dump ' DICTDB._file._file-name FORMAT 'x(20)' ' /data/data' SKIP.
END.
DELETE ALIAS DICTDB.
END.
This isn't working correctly. All the databases will pass, but for all the databases the lines were created with the tables from the first database.
F.E. first database = DB1
proutil DB1 -C dump akk /data/data
proutil DB1 -C dump akm /data/data
proutil DB1 -C dump art /data/data
second database = DB2
proutil DB2 -C dump akk /data/data
proutil DB2 -C dump akm /data/data
proutil DB2 -C dump art /data/data
So for database DB2 also the tables from DB1 are displayed and not the tables from DB2.
I think it has something to do with the connection to the database.
What is wrong within the code? Can you help me?
Regards,
Michiel
michieltimmermans wrote:
I want to create a script that displays all tables per database with the following line:
proutil -C dump /data/data
I have the following code so far:
DEF VAR a AS CHAR.
DEF VAR i AS INTEGER.DO i = 1 TO NUM-DBS:
a = LDBNAME (i).
CREATE ALIAS "DICTDB" FOR DATABASE VALUE (a).
DISPLAY a LABEL "Database name: ". PAUSE.
FOR EACH DICTDB._file NO-LOCK WHERE DICTDB._file._Tbl-Type = "T":
PUT 'proutil ' a ' -C dump ' DICTDB._file._file-name FORMAT 'x(20)' ' /data/data' SKIP.
END.
DELETE ALIAS DICTDB.
END.This isn't working correctly. All the databases will pass, but for all the databases the lines were created with the tables from the first database.
This is because the created alias does not affect current running code. The alias must be defined before a procedure that uses the alias is called (or class is instantiated).
Move the 'for each' block to a separate procedure that you call after you have created the alias.
Move the 'for each' block to a separate procedure that you call after you have created the alias.
Just to be clear, it needs to be a separate external procedure, not an internal procedure.
You may also be able to do it in the same procedure, using dynamic queries.
DEF VAR qh AS HANDLE.
DEF VAR bh AS HANDLE.
CREATE QUERY qh.
DO z = 1 TO NUM-DBS:
CREATE BUFFER bh FOR TABLE LDBNAME(z) + '._file' NO-ERROR.
qh:SET-BUFFERS(bh).
qh:QUERY-PREPARE('FOR EACH _file').
qh:QUERY-OPEN.
qh:QUERY-CLOSE.
DELETE OBJECT bh.
END.
DELETE OBJECT qh.
(or similar)