ProC precompiler questions
Date: Sun, 28 Apr 2002 10:15:13 -0400
Message-ID: <aah0c1$rl8$1_at_news.kodak.com>
Hi,
[Quoted] I am new to oracle, SQL, and databases in general, so I have a number of questions. I am trying to integrate database calls into a current C++ program running on windows 2000. My first basic question is whether the precompiler is a better method than the OCI? It seemed like it would be more straight forward, so I elected to initially go down that path. I wrote the following test program and it makes the connection OK, but then it crashes on the insert command. Any clues as to why? Also, I notice that in order to get the CPP file to compile, I need to cut the include files and paste them at the top of the generated file? Any ideas why?
Anyway, here is the code: (pardon the formatting, my cut and paste did not
work very well)
// testDatabase.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <string.h>
#include <iostream.h>
#include <stdlib.h>
#include <sqlca.h>
EXEC SQL BEGIN DECLARE SECTION;
#define UNAME_LEN 20
#define PWD_LEN 40
varchar password[PWD_LEN];
VARCHAR username[UNAME_LEN];
EXEC SQL END DECLARE SECTION; void sql_error(char *msg);
int main(int argc, char* argv[])
{
printf("Hello World!\n");
EXEC SQL BEGIN DECLARE SECTION; VARCHAR namev[UNAME_LEN];
long datav;
EXEC SQL END DECLARE SECTION; datav = 100;
strncpy((char *)namev.arr,"neil",UNAME_LEN);
namev.len = strlen(namev.arr);
/* Connect to ORACLE--
- Copy the username into the VARCHAR.
*/
strncpy((char *) username.arr, "j2k_admin", UNAME_LEN);
/* Set the length component of the VARCHAR. */
username.len = strlen((char *) username.arr);
/* Copy the password. */
strncpy((char *) password.arr, "adminj2k", PWD_LEN);
password.len = strlen((char *) password.arr);
/* Connect to ORACLE. Program will call sql_error()
- if an error occurs when connecting to the default database.
*/
EXEC SQL CONNECT :username IDENTIFIED BY :password;
printf("\nConnected to ORACLE as user: %s\n", username.arr);
EXEC SQL INSERT INTO neilTest (name,data)
VALUES (:namev,:datav);
return 0;
}
void sql_error(char *msg)
{
EXEC SQL WHENEVER SQLERROR CONTINUE; cout << endl << msg << endl;
cout << sqlca.sqlerrm.sqlerrmc << endl;
EXEC SQL ROLLBACK RELEASE; exit(1);
}
Thanks.
Neil Received on Sun Apr 28 2002 - 16:15:13 CEST