Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> OCI 8 - Simple Question - New to Oracle OCI C++ Programming
Here is my problem:
I have a sequence I need to read from an table on an V8 server. I need to do this a lot (say up to 500 times). I am currently using the ODBC CRecordset class of MFC which was working, but now every now and then it pops up and says it can't read a memory location. Unfortunately, I trace it to MFC code so I'm stuck.
I started delving into OCI and simply want to get the next sequence number for starters. Here is what I have written so far having looked at the OCI manual and examples.
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <oci.h>
void checkerr(OCIError *errhp, sword status);
void main(void)
{
int status;
static text *username = (text*)"myUser"; static text *password = (text*)"myPass123"; static text *dbName = (text*)"myDB";
static OCIEnv *ociEnv;
static OCIError *ociError;
static OCISvcCtx *ociServer;
static OCIStmt *ociStatement;
static OCIDefine *ociDef;
sword pKey;
// Initialize the OCI system and set the environment handle
OCIInitialize(OCI_DEFAULT, NULL, NULL, NULL, NULL);
OCIEnvInit((OCIEnv**)&ociEnv, OCI_DEFAULT, NULL, NULL);
// Allocate the ERROR and SERVER handles
OCIHandleAlloc(ociEnv, (void**)&ociError, OCI_HTYPE_ERROR, NULL, NULL);
OCIHandleAlloc(ociEnv, (void**)&ociServer, OCI_HTYPE_SVCCTX, NULL, NULL);
// Allocate the STATEMENT handle
OCIHandleAlloc(ociEnv, (void**)&ociStatement, OCI_HTYPE_STMT, NULL, NULL);
// Logon to the server
status = OCILogon(ociEnv, ociError, (OCISvcCtx**)ociServer, username,
strlen((char*)username), password, strlen((char*)password), dbName,
strlen((char*)dbName));
// Prepare and execute an SQL statment
checkerr(ociError, (status = OCIStmtPrepare(ociStatement, ociError,
(unsigned char*)"SELECT BIL.ITRANDTLPKEY.NEXTVAL PKEY FROM DUAL", 46,
OCI_V8_SYNTAX, OCI_DEFAULT)));
checkerr(ociError, (status = OCIStmtExecute(ociServer, ociStatement,
ociError, 1, 0, NULL, NULL, OCI_DEFAULT)));
}
The OCIStmtExecute command returns a -2 which is OCI_INVALID_HANDLE.
Since all previous functions return 0 (no errors), I assume it is my
ociStatement handle.
What have I missed? I want to connect, query, return the result (and I
realize I need an OCIDefineByPos(..) call to map the PKEY column I aliased),
and print the number to the screen.
OCI Manual says I can define after the execute and still be ok. I've tried
defining before and after and always the OCIStmtExecute returns
OCI_INVALID_HANDLE.
Help please?!?! Are there better places to ask this question? Otherwise, I
need a nudge.
RDB
P.S. - I briefly perused the mailing list and found nothing of relevence.
Thank you in advance.
Received on Wed Sep 05 2001 - 17:56:34 CDT