NewDBComponent Method
Creates a new OpenROAD component in an OpenROAD database (that is, a database that contains the OpenROAD system catalogs).
This method has the following syntax:
compsource = DBSessionObject.NewDBComponent
(
appname = varchar(32),
compname = varchar(32),
comptype = componentclass,
remark = varchar(60)
)
This method has the following parameters:
appname
Specifies the name of the application to which the new component belongs. The compname parameter is the name of the new component.
comptype
Specifies the component type. Its value must be one of the following:
remark
Specifies a short remark associated with the component
Autocommit should be off when using this method.
If the method succeeds, it returns the new CompSource; otherwise, it returns NULL.
The following example shows how to use the NewDBComponent method to create a component and the WriteDBComponent method to save it after making a change:
/*
** This procedure creates a simple new procedure
** named 'newproc' in the given application and
** database.
*/
procedure create_newproc
(
database = varchar(256) not null,
appname = varchar(32) not null
) =
declare
compsrc = CompSource default NULL;
dbsessobj = DBSessionObject;
rc = integer not null;
so = StringObject;
enddeclare
{
/*
** Connect to the database.
*/
rc = dbsessobj.Connect(database = database);
if (rc != ER_OK) then
return(ER_FAIL);
endif;
/*
** Create the Proc4GLSource.
*/
compsrc = dbsessobj.NewDBComponent
(
appname = appname,
compname = 'newproc',
comptype = proc4glsource,
remark = 'Sample procedure'
);
if (compsrc is null) then
dbsessobj.Disconnect();
return(ER_FAIL);
endif;
/*
** Create a script for the new procedure and
** attach it to the Proc4GLSource.
*/
so.value = 'procedure newproc() = ' + HC_NEWLINE +
'{' + HC_NEWLINE +
' message ' +
HC_QUOTE + 'Hello world.' +
HC_QUOTE +
';' + HC_NEWLINE +
'}' + HC_NEWLINE;
compsrc.script = so;
/*
** Write the procedure to the database.
*/
rc = dbsessobj.WriteDBComponent(component = compsrc);
dbsessobj.Disconnect();
return(rc);
}