Consultor Eletrônico



Kbase 15059: Example of using SQL DELETE and SQL FETCH
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   10/05/1998
Example of using SQL DELETE and SQL FETCH

The following examples demonstrates the usage of the ESQL
DELETE and FETCH commands. 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 DEMO Dataase, fetch all the customer names and
numbers, display the names and numbers and perform a SQL DELETE on
customers whose cust-num's are GREATER than 53.

Note:
Attached code must be run through the PROGRESS SQL
C-PRE-PROCESSOR(sqlcpp) before compiling with an Ansi C Compiler.
#include <errno.h>
#include <stdio>
#define RECORDNAME "smith"
#define PARAMFILE "-pf smith.pf"


void RetrieveMeRecord()
{
char *msg;
long SQLCODE;
EXEC SQL BEGIN DECLARE SECTION;
char name[50];
int number;
EXEC SQL END DECLARE SECTION;
EXEC SQL DECLARE mecurse CURSOR FOR
SELECT name,cust\-num FROM customer;

EXEC SQL OPEN mecurse;
EXEC SQL WHENEVER NOT FOUND GOTO over;

fprintf(stdout," RetrieveMeRecord()\n");
while(1)
{
EXEC SQL FETCH mecurse INTO :name, :number;
fprintf(stdout,"Name is %-25s\tNumber is %d\n",name,number);

if (number == 1)
{
fprintf(stdout,"Customer number is 1\n");
}
if (number > 53)
{
EXEC SQL DELETE FROM customer WHERE CURRENT OF mecurse;
fprintf(stdout,"Deleted %d customer\n",number);
}
}
over:
EXEC SQL close mecurse;
EXEC SQL COMMIT WORK;
sleep(10);
fprintf(stdout,"over now.. over #2\n");
sqllogout(0);
fprintf(stdout,"I have logged out now...\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
{
RetrieveMeRecord();
}
}

Progress Software Technical Support Note # 15059