Consultor Eletrônico



Kbase P114484: How to create the same user in all the connected databases?
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   21/03/2006
Status: Unverified

GOAL:

How to create the same user in all the connected databases?

GOAL:

How to Synchronize the _User table in all the connected databases.

FIX:

The following solution loops through all the connected databases and creates a new record in the _User table of each of these databases unless the user already exists in that database. The solution consists of two procedures. The first procedure named SyncUserTables.p loops through the databases and the second procedure named CreateUserRecord.p checks whether the user record exists in the current database or not. If the user record does not exist it creates it:
/* 1. SyncUserTables.p */
DEFINE VARIABLE iNumDatabases AS INTEGER NO-UNDO.
DEFINE VARIABLE cCurrentDatabase AS CHARACTER NO-UNDO.
DO iNumDatabases = 1 TO NUM-DBS:
cCurrentDatabase = LDBNAME(iNumDatabases).
CREATE ALIAS "DICTDB" FOR DATABASE VALUE(cCurrentDatabase).
RUN something.p("llljj", "kaaakk").
DELETE ALIAS dictdb.
END.
/* 2. CreateUserRecord.p */
DEFINE INPUT PARAMETER cUserid AS CHAR.
DEFINE INPUT PARAMETER cPassword AS CHAR.
DO TRANSACTION:
FIND FIRST DICTDB._User NO-LOCK WHERE DICTDB._User._UserId = cUserid AND DICTDB._User._Password = ENCODE(cPassword) NO-ERROR.
IF NOT AVAILABLE DICTDB._User THEN DO:
CREATE DICTDB._User.
ASSIGN
DICTDB._User._UserId = cUserid
DICTDB._User._Password = ENCODE(cPassword).
END.
END.