Forum Post: How to use the CREATE ALIAS command to access system tables from within an OE...

Status
Not open for further replies.
R

romelwell

Guest
SETUP: I am having difficulty using the CREATE ALIAS command to create an alias in one class that can subsequently be utilized in a second class. I want to query the system table "_Field" for the connected DBs to find the value of the "_Format" field. I have two classes, 'AClass' and 'BClass'. AClass creates the DB Alias and BClass attempts to use the alias to query the system table. In Class 'AClass' , I have defined a method that creates an alias for a defined DB connection. METHOD PROTECTED CHAR GetFieldFormat (INPUT fieldName AS CHAR, INPUT tableName AS CHAR): DEF VAR oBClass AS CLASS BClass. DEF VAR tmpFormat AS CHAR INIT "". DEF VAR iCount AS INT INIT 1. oBClass = NEW BClass (). DO iCount = 1 TO NUM-DBS: CREATE ALIAS VSTAlias FOR DATABASE VALUE(LDBNAME(iCount)) NO-ERROR. tmpFormat = oBClass:GetFieldFormat(fieldName, tableName). /* this method is defined in class BClass, seen below */ IF tmpFormat "" THEN LEAVE. END. DELETE OBJECT oBClass. RETURN tmpFormat. END METHOD. In the class 'BClass' , I have created the method called from 'AClass', GetFieldFormat . METHOD PUBLIC CHAR GetFieldFormat (INPUT fieldName AS CHAR, INPUT tableName AS CHAR): FIND FIRST _File NO-LOCK WHERE _file-name = tableName NO-ERROR. FIND FIRST _Field OF _File NO-LOCK WHERE _Field-Name = fieldName NO-ERROR. IF AVAIL _Field THEN RETURN Field._Format. ELSE RETURN ?. END METHOD. QUESTION: The issue is that I need to use the alias VSTAlias in BClass to ensure I am querying the desired DB. I tried the syntax seen below however the compiler threw an error because it did not recognize the variable 'VSTAlias'. Thus, how can I use the CREATE ALIAS command to query multiple DB instances in an OE Class? Does the CREATE ALIAS command need to be in a separate .R file than the .R file that attempts to use it? FIND FIRST VSTAlias. _File NO-LOCK WHERE _file-name = tableName NO-ERROR. FIND FIRST VSTAlias._Field OF VSTAlias. _File NO-LOCK WHERE _Field-Name = fieldName NO-ERROR.

Continue reading...
 
Status
Not open for further replies.
Top