Consultor Eletrônico



Kbase 299: Finding metaschema information _File using C, SQL, HLI
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   10/05/1998
Finding metaschema information _File using C, SQL, HLI

920604-elp01
INTRODUCTION:
=============
This Product Services Knowledgebase entry illustrates how to
use embedded SQL statements in a C program to retrieve metaschema
information.

WHY YOU NEED TO DO THIS:
========================
Your embedded SQL C program may need to access the metaschema
structures to provide the kind of point-and-shoot
choose pop-up windows that you see in the PROGRESS dictionary
without using PROGRESS SQL statements. This
functionality is useful to users who don't know the
design of the database they are accessing.

PROCEDURAL APPROACH:
====================
The following program uses PROGRESS 4GL to retrieve the names of
the fields for every file in the application schema.

FOR EACH _File WHERE _File._File-Number > 0:
DISPLAY _File-Name.
FOR EACH _Field WHERE _Field._File-Recid = RECID(_File):
DISPLAY _Field-Name.
END.
END.

The following C program provides the same functionality, without using
PROGRESS 4GL.

/*
Program using Embedded SQL in C with the Progress demo database
*/
main(argc,argv)
int argc;
char **argv;
{
long SQLCODE;
char *msg;
EXEC SQL BEGIN DECLARE SECTION;
char filename[30];
char fieldname[30];
EXEC SQL END DECLARE SECTION;
/* login to the progress database, passing command line arguments and
name the application 'hlidemo' */
printf(
"Embedded SQL Demo. Logging into the Progress Host Language Interface...\n"
);
if (sqllogin(argc-1,&argv[1],"","hlidemo") == -1)
{
printf("Failed to login to Progress HLI!\n");
while ((msg = (char *) sqlgetmsg()) != (char *) 0)
printf("%s\n",msg);
exit(2);
}
EXEC SQL declare x cursor for
select _field\-name, _file\-name
from _file, _field
where _file\-number > 0 and _field._file\-recid = recid(_file);
EXEC SQL OPEN x;
if (SQLCODE != 0)
{
while ((msg = (char *) sqlgetmsg()) != (char *) 0)
printf("%s\n",msg);
exit(2);
}
EXEC SQL WHENEVER NOT FOUND GOTO done1;
while (1) /* loop until last customer record read */
{
EXEC SQL fetch x into :fieldname, :filename;
printf("Field name %-30s File name %-30s\n",fieldname,filename);
}
done1:
EXEC SQL close x;
sqllogout(0);
}

This code will allow you to retrieve values based on RECID
using embedded SQL.

ON-LINE PROCEDURES OR UTILITIES:
===============================
See sample hlidemo procedures in the dlcload/uce/hlic subdirectory .

REFERENCES TO WRITTEN DOCUMENTATION:
====================================
See the 3GL Interface Guide and general C programming documentation.

Progress Software Technical Support Note # 299