aHTML> OpenROAD Default Database connection

OpenROAD Default Database connection

From: Elena Yatzeck 

At 09:24 PM 10/7/96 +0000, you wrote:
>Hi,
>
>I'm wondering whether there is a way to start an application,
>developed with OpenRoad without setting up a default connection to a
>database. As far as I know, every application build with OpenRoad
>performs a default connection to a database.
>
>After the application is loaded into memory, the application should
>connect to the specified database, perform the desired action and
>disconnect again.
>
>By doing this, it is possible to minimize the number of connections
>developers have to the database during the day.
>
>Greetings,
>Jan
>
>J. Leeuwerink - The Netherlands
>jleeuwer@pi.net

This is a property of the application.  On the "component catalog"
window for the application, choose "Properties" from the "Application"
menu.  You have three choices:  no database connection, use
current database, or connect to a named database.  I'm wondering
whether "use current database" establishes a new connection to
the same database or not--I don't know.  If not, perhaps that
would help you.  For your purposes, however, you should choose 
"no database connection."

To connect to a database from the application once it has started,
you will need to use a variable of type DBSessionObject to make
the database connection.  Sample code:

procedure connect_and_do_something (
  db_connect_name = varchar(20) not null ;
  db_connect_flags = varchar(100) not null ;
) = declare
  i = integer not null ;
  foo = DBSessionObject ;
enddeclare
begin

  i = foo.Connect(database=db_connect_name,flags=db_connect_flags);
  if( i != ER_OK ) then
    message( 'Sorry--I could not connect to database at this time.' ) ;
    exit ;
  else
    CurProcedure.DBSession = foo ;
    /* call the rest of the code which uses the db connection from here */
  endif ;
end ;

Note that everything you call from this procedure will inherit the
same database connection by default.  But please also note that the
frame, procedure, or method which CALLS connect_and_do_something
will NOT inherit the same connection.  

One last note.  You may find it convenient to pass in the database
name and connection flags to the application via the command
line.  If you are manually
making the connection in the way I've detailed above, then you can't
use the -d switch on the command line, since that switch controls
the default connection the application will make when it starts up.
OpenROAD provides a means for passing in command line switches which
was not documented at all in 3.0, and which is horribly documented
in 3.5.  To find what there is, look up "AppFlag" in the documentation.
The "AppFlag" object provides a highly complex interface which would
theoretically allow you to pass in whole arrays of information via
the command line.  For the simple purpose we have here, I can tell
you what we did:

command line attached to the icon via properties:

C:\INGRES\BIN\W4GLRUN.EXE c:\myapp -/appflags DBName=mynode::myname

inside the application's top frame:

initialize()=
declare
        status = integer not null ;
        DBName = varchar(100) not null ;
        DBFlags = varchar(100) not null ;
begin

    /* Find connect database name */
    status = CurSession.AppFlags.Find(attributename = 'Name', 
        value = 'DBName', rownumber = byref (rownum) ) ;
    if( status = ER_OK ) then
        DBName = CurSession.AppFlags[rownum].FlagValues[1].Value ;
    else
        DBName = 'mydefaultnode::mydefaultdb' ;
    endif ;

    /* Find connect flags */
    status = CurSession.AppFlags.Find(attributename = 'Name', 
        value = 'connect_flags', rownumber = byref (rownum) ) ;
    if( status = ER_OK ) then
        DBFlags = CurSession.AppFlags[rownum].FlagValues[1].Value ;
    else
        DBFlags = '' ;
    endif ;

    callproc connect_and_do_something( db_connect_name = DBName,
                db_connect_flags = DBFlags ) ;
end ;

Good luck!

Elena

--------
Elena M. Yatzeck, Lead Programmer
GSB Computing Services
University of Chicago
41* 46' 52" N x 87* 36' 18" W
Ingres Q & A
To William's Home Page

© William Yuan 2000

Email William