Kbase 15023: Code example using INSERT with the PROGRESS ESQL
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  10/05/1998 |
|
Code example using INSERT with the PROGRESS ESQL
Description:
-----------
The following example demonstrates the usage of the ESQL
INSERT command. Two conditional compilation statements can
be modified, which are included below as #define's. Minimal
error handling is included in this example. The example
uses sqllogin to connect to a PROGRESS database,
inserts a record, commits the transaction, and finally
perform a sqllogout.
Note:
----
Attached code must be run through the PROGRESS SQL
C-Preprocessor (sqlcpp) before compiling with an Ansi C
Compiler.
/* Beginning of ESQL Insert Example */
#include <errno.h>
#include <stdio>
#define RECORDNAME "smith" /* test parameter to be */
/* modified */
#define PARAMFILE "-pf smith.pf" /* client parameter */
/* file used for */
/* sqllogin
* this parameter file
*only included
* -db demo */
void InsertRecord()
{
char *msg;
long SQLCODE;
EXEC SQL BEGIN DECLARE SECTION;
char request[12];
EXEC SQL END DECLARE SECTION;
strcpy(request,RECORDNAME);
EXEC SQL INSERT INTO customer
(name)
VALUES(:request);
if (SQLCODE !=0)
{
while ((msg = (char *) sqlgetmsg())!= (char *)0)
fprintf(stdout,"%s\n",msg);
sqllogout(0);
}else
{
EXEC SQL COMMIT WORK;
printf("Waiting for 3 seconds\n");
sleep(3);
sqllogout(0);
fprintf(stdout,"Success, I have logged out and committed\n");
}
}
main(argc,argv)
int argc;
char *argv[1];
{
char *msg1;
char *recordname;
if (sqllogin(argc-1, &argv[1], PARAMFILE, "char (*)") == -1)
{
fprintf(stdout,"\n No login , ! later\n");
while ((msg1 = (char *) sqlgetmsg()) != (char *) 0)
fprintf(stdout,"%s\n",msg1);
sqllogout(0);
}else
{
InsertRecord();
}
}
Progress Software Technical Support Note # 15023