Consultor Eletrônico



Kbase P42894: How to create a database from 4GL
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   16/10/2008
Status: Unverified

GOAL:

How to create a database from 4GL

FIX:

Using CREATE DATABASE statement.  
The below example shows this. In order to be able to create a new database
from a source database you SHOULD NOT be already connected to the source
database.


DEFINE VARIABLE gcNewDb AS CHARACTER LABEL "New db: " FORMAT "x(65)".
DEFINE VARIABLE gcOriginalPath AS CHARACTER LABEL "Copy of:" FORMAT "x(65)".

/* Prompt the user for the name of a demo database to connect. */
SET gcNewDb HELP "Enter the path of your new database."
WITH FRAME dbname-frame SIDE-LABELS.

/* If the entered name does not have the .db suffix, add it.
This is necessary for the search function to work correctly. */
IF LENGTH(gcNewDb) ".db"
THEN gcNewDb = gcNewDb + ".db".

IF SEARCH(gcNewDb) ?
THEN DO:
MESSAGE "A database with this name already exist: " gcNewDb
VIEW-AS ALERT-BOX ERROR TITLE "Create Database failed".
RETURN.
END.

SET gcOriginalPath HELP "Enter the path of the existing database. Example: sports2000 or MyOldDb. Fill-in empty if you want to have a copy of the default empty database"
WITH FRAME dbname-frame SIDE-LABELS.

/* If the entered name does not have the .db suffix, add it.
This is necessary for the search function to work correctly. */
IF LENGTH(gcOriginalPath) ".db"
THEN gcOriginalPath = gcOriginalPath + ".db".


IF SEARCH(gcOriginalPath) = ?
THEN DO:
MESSAGE "The source database doesn't exist: " gcOriginalPath
VIEW-AS ALERT-BOX ERROR TITLE "Create Database failed".
RETURN.
END.


/*CHECK IF can CONNECT SINGLE USER TO the original DATABASE*/
CONNECT value( string(gcOriginalPath) + " -1 -ld 'OriginalDb'") NO-ERROR.
IF ERROR-STATUS:ERROR THEN DO:
MESSAGE "Could not connect to " gcOriginalPath ". Possible causes: ~n"
" - is already connected " SKIP
" - is in use by somebody else " SKIP
" - is not a valid database "
VIEW-AS ALERT-BOX ERROR.
RETURN ERROR.
END.

DISCONNECT "OriginalDb".

CREATE DATABASE gcNewDb FROM gcOriginalPath.

MESSAGE "New database created:" gcNewDb VIEW-AS ALERT-BOX