Kbase P126880: ESQL/C-92: How to specify the user name and password in an ESQL/C connection string?
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  12/11/2007 |
|
Status: Unverified
GOAL:
ESQL/C-92: How to specify the user name and password in an ESQL/C connection string?
FACT(s) (Environment):
All Supported Operating Systems
Progress 9.x
OpenEdge 10.x
FIX:
The highlighted statements in the following C code demonstrate the correct syntax of specifying the user name and password in the EXEC SQL CONNECT statement. Notice that both the user name and the password are specified as a parameter reference in the EXEC SQL CONNECT statement:
#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];
char myuser[20];
char mypass[20];
EXEC SQL END DECLARE SECTION ;
strncpy(myuser,"yshanshi",19);
strncpy(mypass,"yshanshi",19);
strncpy(connect_string,"progress:T:localhost:23456:sports2000",119);
EXEC SQL WHENEVER SQLERROR GOTO mainerr ;
EXEC SQL CONNECT TO :connect_string AS 'conn' USER :myuser USING :mypass;
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;
}