Consultor Eletrônico



Kbase P72487: How to copy the data of a database to another database havin
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   17/03/2004
Status: Unverified

GOAL:

How to copy the data of a database to another database having the same schema?

FIX:

The following 4GL code copies the data of a Sourcedb into a Targetdb. This solution has the following assuptions:

1. The Targetdb has the same exact schema as the Sourcedb.
2. The Targetdb has no records at all in it.
3. The client running the code is 9.1D or higher.
4. The two databases are 9.1x or higher.
5. The two database are already connected.

DEFINE VARIABLE cSourcedbDatabaseName AS CHARACTER NO-UNDO.
DEFINE VARIABLE cTargetdbDatabaseName AS CHARACTER NO-UNDO.

ASSIGN
cSourcedbDatabaseName = "Sourcedb"
cTargetdbDatabaseName = "Targetdb".

FOR EACH Sourcedb._File NO-LOCK WHERE Sourcedb._File._Tbl-Type = "T":
RUN CopyCurrentTable (INPUT Sourcedb._File._File-Name) NO-ERROR.
END.

PROCEDURE CopyCurrentTable:
DEFINE INPUT PARAMETER ipcTableName AS CHARACTER.
DEFINE VARIABLE hSourcedbTableBuffer AS HANDLE NO-UNDO.
DEFINE VARIABLE hTargetdbTableBuffer AS HANDLE NO-UNDO.
DEFINE VARIABLE hSourcedbTableQuery AS HANDLE NO-UNDO.

CREATE BUFFER hSourcedbTableBuffer FOR TABLE cSourcedbDatabaseName + "." + ipcTableName.
CREATE BUFFER hTargetdbTableBuffer FOR TABLE cTargetdbDatabaseName + "." + ipcTableName.

hTargetdbTableBuffer:DISABLE-LOAD-TRIGGERS(NO).
hTargetdbTableBuffer:DISABLE-DUMP-TRIGGERS().

CREATE QUERY hSourcedbTableQuery.
hSourcedbTableQuery:SET-BUFFERS(hSourcedbTableBuffer).
hSourcedbTableQuery:QUERY-PREPARE("FOR EACH " + cSourcedbDatabaseName + "." + ipcTableName + " " + "NO-LOCK").
hSourcedbTableQuery:QUERY-OPEN().
REPEAT TRANSACTION:
hSourcedbTableQuery:GET-NEXT().
IF hSourcedbTableQuery:QUERY-OFF-END THEN LEAVE.
hTargetdbTableBuffer:BUFFER-CREATE.
hTargetdbTableBuffer:BUFFER-COPY(hSourcedbTableBuffer).
END.
END PROCEDURE.