Consultor Eletrônico



Kbase P129280: How to access SQL-92 sequences from an ESQL/C client
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   27/02/2008
Status: Unverified

GOAL:

How to access SQL-92 sequences from an ESQL/C client

GOAL:

Is it possible to access SQL sequences from an ESQL-92/C client

FACT(s) (Environment):

Progress 9.x
OpenEdge 10.x

FIX:

The SQL sequences can be accessed from an ESQL-92/C client by using dynamic SQL statement in the C application. The SQL server does all the SQL statement analysis and execution.

When using static SQL statement, the ESQL compiler does not understand the sequence reference.
The grammar for the static SQL which ESQL supports has not been changed to reflect various new features, because ESQL is considered a mature product.

See below an example of ESQL-92/C code accessing SQL-92 sequences:

#include <stdio.h>
#include <string.h>
#include <time.h>

void sqlquery(char *);

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:myDabatase",119);

EXEC SQL WHENEVER SQLERROR GOTO mainerr ;
EXEC SQL CONNECT TO :connect_string AS 'conn' ;

sqlquery("INSERT INTO pub.\"my-table\" (\"Cust-Num\", name, city) VALUES (pub.test.nextval,'Progress Software','Bedford')");

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 EXECUTE stmtid;
EXEC SQL COMMIT WORK ;
return;
sqlerr:
fprintf(stderr,"sqlquery: SQL Error (%ld) %s\n",sqlca.sqlcode, sqlca.sqlerrm);
exit(1);
}