Urgent Help - Coredump [message #94212] |
Mon, 17 May 2004 03:01 |
Ricardo
Messages: 7 Registered: November 1999
|
Junior Member |
|
|
Hello,
I'm running a small program and I having a core dump.
Can anybody help me, please?
definitions
EXEC SQL BEGIN DECLARE SECTION;
/*VARCHAR sFechaProceso[[9]]; */
char sFechaProceso[[9]]; EXEC SQL VAR sFechaProceso IS STRING(9);
EXEC SQL END DECLARE SECTION;
strcpy(sFechaProceso, argv[[5]]);
strcpy (ssql_sentencia,"SELECT distinct co_c1,
co_c2
FROM Table_name
WHERE cr_baja_reg != 'A'
AND TRUNC(fe_modi_reg) >= TO_DATE(:sFechaProceso,'YYYYMMDD')
ORDER BY co_c1,co_c2 ");
EXEC SQL PREPARE sCur FROM :ssql_sentencia;
EXEC SQL DECLARE Cur_csr CURSOR FOR sCur;
EXEC SQL OPEN Cur_csr;
I'm having a coredump before last sentence. If I do the same things, but with a literal instead of :sFechaProceso (for example, '20040302') and it works
I've tryed many things but none worked, Any help would be very valuable?
Thanks in advance.
|
|
|
Re: Urgent Help - Coredump [message #94242 is a reply to message #94212] |
Fri, 04 June 2004 17:06 |
Frank Scherie
Messages: 10 Registered: June 2004
|
Junior Member |
|
|
Hello,
checkout the following source based on your code -
will work :-)
Frank Scherie
Senior Support Engineer
SOURCE
~~~~~~~
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sqlda.h>
#include <sqlcpr.h>
#define UNAME_LEN 20
#define PWD_LEN 40
VARCHAR username[[UNAME_LEN]]; /* VARCHAR is an Oracle-supplied struct */
varchar password[[PWD_LEN]]; /* varchar can be in lower case also. */
#include <sqlca.h>
void sql_error(msg)
char *msg;
{
char err_msg[[128]];
size_t buf_len, msg_len;
EXEC SQL WHENEVER SQLERROR CONTINUE;
printf("n%sn", msg);
buf_len = sizeof (err_msg);
sqlglm(err_msg, &buf_len, &msg_len);
printf("%.*sn", msg_len, err_msg);
EXEC SQL ROLLBACK RELEASE;
exit(EXIT_FAILURE);
}
int main(int argc, char *argv[[]])
{
EXEC SQL BEGIN DECLARE SECTION;
int empno = 0;
char sFechaProceso[[9]];
EXEC SQL VAR sFechaProceso IS STRING(9);
EXEC SQL END DECLARE SECTION;
char ssql_sentencia[[120]];
strncpy((char *) username.arr, "SCOTT", UNAME_LEN);
username.len =
(unsigned short) strlen((char *) username.arr);
strncpy((char *) password.arr, "TIGER", PWD_LEN);
password.len =
(unsigned short) strlen((char *) password.arr);
EXEC SQL WHENEVER SQLERROR DO sql_error("ORACLE error--n");
EXEC SQL CONNECT :username IDENTIFIED BY :password;
printf("nConnected to ORACLE as user: %sn", username.arr);
strcpy(sFechaProceso, argv[[1]]);
printf("argv[[1]]: %sn",sFechaProceso);
strcpy(ssql_sentencia,
"SELECT EMPNO FROM EMP WHERE HIREDATE > TO_DATE(:sFechaProceso,'YYYYMMDD')")
;
EXEC SQL PREPARE sCur FROM :ssql_sentencia;
EXEC SQL DECLARE Cur_csr CURSOR FOR sCur;
EXEC SQL OPEN Cur_csr USING :sFechaProceso;
EXEC SQL FETCH Cur_csr INTO :empno;
printf("first EMPNO: %dn",empno);
EXEC SQL CLOSE Cur_csr;
printf("nG'day.nnn");
EXEC SQL ROLLBACK WORK RELEASE;
exit(EXIT_SUCCESS);
}
OUTPUT
~~~~~~
Connected to ORACLE as user: SCOTT
argv[[1]]: 19680426
first EMPNO: 7369
G'day.
|
|
|