Re: Embedded SQL in a DLL
Date: 1996/11/11
Message-ID: <3287ab26.28028032_at_newshost.us.oracle.com>#1/1
On 7 Nov 1996 21:58:59 GMT, Norwood Story <Norwood_S_at_shared.com> wrote:
>I am trying to convert a C program with embedded SQL into a DLL on NT.
>The program works as a DLL for Sybase and Informix. I have modified the
>code accordingly for Oracle, but it will not initialize properly. I am
>having trouble finding any documentation that helps. I have the sample
>programs that have the embedded SQL in them working fine.
>
>Any help would be greatly appreciated!
>
>Thanks!
>
Specifically what problems are you having and what are you calling the DLL function from. Here is a sample of some code to connect to the DB using Pro*C. The funtion definitions in the DLL can be done differently, but this was to be called from VB4.
#include <stdio.h> #include <string.h> #ifdef WIN_NT # include <string.h> # include <stdlib.h> # include "sqlproto.h" #endif /* WIN_NT */ #ifdef TRUE # undef TRUE
#endif
#define TRUE 1
/* Maximum number of select-list items or bind variables. */ #define MAX_ITEMS 40
/* Maximum lengths of the _names_ of the
select-list items or indicator variables. */
#define MAX_VNAME_LEN 30 #define MAX_INAME_LEN 30 #ifndef NULL
#define NULL 0
#endif
typedef char asciz;
char *dml_commands[] = {"SELECT", "select", "INSERT", "insert",
"UPDATE", "update", "DELETE", "delete"};
EXEC SQL BEGIN DECLARE SECTION;
EXEC SQL TYPE asciz IS STRING(30);
VARCHAR uid1[30];
VARCHAR pwd1[30];
VARCHAR con1[30];
VARCHAR sqlstmt[200];
VARCHAR cname[30];
asciz tname[10][30];
char sql_statement[1024];
char update_buf[1024];
int row_count;
EXEC SQL VAR sql_statement IS STRING(1024); EXEC SQL END DECLARE SECTION; EXEC SQL INCLUDE sqlca;
EXEC SQL INCLUDE sqlda;
SQLDA *bind_dp;
SQLDA *select_dp;
extern SQLDA *sqlald();
extern void sqlnul();
/* Define a buffer to hold longjmp state info. */ /*jmp_buf jmp_continue;*/
/* A global flag for the error routine. */
int parse_flag = 0;
/* A global flag for determining if call if for a VIEW or TABLE */
int vtflag =0;
/* A global for dump file record separator, could be done as a passed
pointer */
/* can't be bothered for now */
char spchr;
__declspec(dllexport) void ConnectDB(char *uid, char *pwd, char *con, char *err_code)
{
int i;
char msg_buf[100];
int buf_size=100;
int msg_len;
strcpy(uid1.arr, uid);
uid1.len=strlen(uid1.arr);
strcpy(pwd1.arr, pwd);
pwd1.len=strlen(pwd1.arr);
strcpy(con1.arr, con);
con1.len=strlen(con1.arr);
EXEC SQL CONNECT :uid1 IDENTIFIED BY :pwd1 USING
:con1;
if(sqlca.sqlcode != 0)
{
/* sqlglm(msg_buf, &buf_size, &msg_len);
msg_buf[msg_len] = '\0';
strcpy(err_code, msg_buf); */
sprintf(msg_buf, "%d", sqlca.sqlcode);
strcpy (err_code, msg_buf);
}
else
{
strcpy(msg_buf, "YES");
strcpy(err_code, msg_buf);
}
}
Hope this helps,
Jc.
Received on Mon Nov 11 1996 - 00:00:00 CET
