Kbase P53382: How to test ESQL/C-92 program?
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  26/11/2008 |
|
Status: Verified
GOAL:
How to test ESQL/C-92 program?
GOAL:
Is there a sample ESQL/C-92 program for testing?
FACT(s) (Environment):
All Supported Operating Systems
Progress 9.x
OpenEdge 10.x
FIX:
1) Copy following sample code to a file named, or example, test.pc. Make necessary modifications on the following line to suit your own configuration.
strncpy(connect_string, "progress:T:localhost:2500:sports2000", 119);
2) prodb sports2000 sports2000
proserve sports2000 -S 2500
3) esqlc test.pc
This will generate a binary called client.exe.
If you'd like to rename the executable, use:
esqlc -o myexe test.pc
4) Start the client
./myexe
============
#include <stdio.h>
#include <string.h>
#include <time.h>
void sqlquery(char *);
int etime(int);
struct sqlca sqlca;
dh_i32_t SQLCODE;
int main()
{
EXEC SQL BEGIN DECLARE SECTION ;
char connect_string[120];
EXEC SQL END DECLARE SECTION ;
strncpy(connect_string,
"progress:T:localhost:2500:sports2000",
119);
EXEC SQL WHENEVER SQLERROR GOTO mainerr ;
EXEC SQL CONNECT TO :connect_string AS 'conn' ;
sqlquery("select name from pub.customer");
EXEC SQL DISCONNECT 'conn';
exit(0);
mainerr:
fprintf(stderr,
"main: SQL Error (%ld) %s\n",
sqlca.sqlcode,
sqlca.sqlerrm);
exit(1);
}
void sqlquery(char * s)
{
EXEC SQL BEGIN DECLARE SECTION ;
char sql_stmt[256];
char field1[256];
EXEC SQL END DECLARE SECTION ;
strncpy(sql_stmt, s, 255);
EXEC SQL WHENEVER SQLERROR GOTO sqlerr ;
EXEC SQL PREPARE stmtid FROM :sql_stmt ;
EXEC SQL DECLARE x CURSOR FOR stmtid ;
EXEC SQL OPEN x ;
EXEC SQL WHENEVER NOT FOUND GOTO sqldone ;
etime(1);
while(1){
EXEC SQL FETCH x INTO :field1 ;
printf("%s\n", field1);
}
sqldone:
printf("Etime: %d secs\n", etime(0));
EXEC SQL CLOSE x ;
EXEC SQL COMMIT WORK ;
return;
sqlerr:
fprintf(stderr,
"sqlquery: SQL Error (%ld) %s\n",
sqlca.sqlcode, sqlca.sqlerrm);
exit(1);
}
int etime(int set)
{
static time_t t1 = 0;
int r;
r = time(0) - t1;
if (set) t1 = time(0);
return r;
}