#ifdef RCSID
static char *RCSid =
"$Header: cdemodp.c 13-nov-2001.14:59:24 msakayed Exp $ ";
#endif /* RCSID */
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
/* Copyright (c) 1998, 2001, Oracle Corporation. All rights reserved. */
/* */
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
/*
** NAME:
** cdemodp.c - C Demo program for Direct Path api
**
**
** DESCRIPTION:
** - Direct Path Api driver program to demonstrate loading.
**
** NOTES:
** Demonstrates usage of the direct path API.
**
** -- cdemodp.c --
** This is one of two C files needed to create a demo that loads
** data through direct path api.
**
** To build and run the demo, please read directions located in
** the header section of the cdemdp*.c modules.
**
**
**
** MODIFIED (MM/DD/YY)
** msakayed 11/02/01 - Bug #2094292: add/set OCI_ATTR_DIRPATH_INPUT
** eegolf 03/04/01 - Updated for 9i
** cmlim 09/16/98 - Creation (abrumm 04/07/98)
*/
#include <sys/types.h>
#include <sys/stat.h>
#include <ctype.h>
#include <fcntl.h>
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <oratypes.h>
#include <oci.h>
#include <cdemodp0.h>
#include <cdemodp.h>
#ifndef bit
# define bit(x, y) ((x) & (y))
#endif
#ifndef OER
# define OER(x) (x)
#endif
struct loadctl
{
ub4 nrow_ctl; /* number of rows in column array */
ub2 ncol_ctl; /* number of columns in column array */
OCIEnv *envhp_ctl; /* environment handle */
OCIServer *srvhp_ctl; /* server handle */
OCIError *errhp_ctl; /* error handle */
OCIError *errhp2_ctl; /* yet another error handle */
OCISvcCtx *svchp_ctl; /* service context */
OCISession *authp_ctl; /* authentication context */
OCIParam *colLstDesc_ctl; /* column list parameter handle */
OCIDirPathCtx *dpctx_ctl; /* direct path context */
OCIDirPathColArray *dpca_ctl; /* direct path column array handle */
OCIDirPathColArray *dpobjca_ctl; /* dp column array handle for obj*/
OCIDirPathColArray *dpnestedobjca_ctl; /* dp col array hndl for nested obj*/
OCIDirPathStream *dpstr_ctl; /* direct path stream handle */
ub1 *buf_ctl; /* pre-alloc'd buffer for out-of-line data */
ub4 bufsz_ctl; /* size of buf_ctl in bytes */
ub4 bufoff_ctl; /* offset into buf_ctl */
ub4 *otor_ctl; /* Offset to Recnum mapping */
ub1 *inbuf_ctl; /* buffer for input records */
struct pctx pctx_ctl; /* partial field context */
boolean loadobjcol_ctl; /* load to obj col(s)? T/F */
};
/* Forward references: */
STATICF void field_flush(/*_ struct loadctl *ctlp, ub4 rowoff _*/);
STATICF sword field_set(/*_ struct loadctl *ctlp, struct tbl *tblp,
struct obj *objp, text *recp, ub4 rowoff, ub1 bufflg _*/);
STATICF void init_obj_load(/*_ struct loadctl *ctlp, struct tbl *tblp,
struct obj *objp _*/);
STATICF void alloc_obj_ca(/*_ struct loadctl *ctlp, struct tbl *tblp,
struct obj *objp _*/);
STATICF void init_load(/*_ struct loadctl *ctl, struct tbl *table,
struct sess *session _*/);
STATICF void simple_load(/*_ struct loadctl *ctlp, struct tbl *tblp,
struct sess *session, FILE *inputfp _*/);
STATICF void finish_load(/*_ struct loadctl *ctl _*/);
STATICF void errprint(/*_ dvoid *errhp, ub4 htype, sb4 *errcodep _*/);
STATICF void checkerr(/*_ dvoid *errhp, ub4 htype, sword status,
text *note, sb4 state, text *file, sb4 line _*/);
STATICF void cleanup(/*_ struct loadctl *ctlp, sb4 ex_status _*/);
STATICF sword do_convert(/*_ struct loadctl *ctlp, ub4 startoff, ub4 rowcnt,
ub4 *cvtCntp, ub2 *badcoffp _*/);
STATICF sword do_load(/*_ struct loadctl *ctlp, ub4 *loadCntp _*/);
STATICF int main(/*_ int argc, char *argv[] _*/);
STATICF void free_obj_hndls(struct loadctl *ctlp, struct obj *objp);
/* OCI_CHECK(errhp, ub4 errhptype, sb4 status, struct loadctl *ctlp,
* OCIfunction());
* errhp is typically a (OCIError *), and errhptype is OCI_HTYPE_ERROR.
* errhp in some cases may be an (OCIEnv *), and errhptype is OCI_HTYPE_ENV.
*/
#define OCI_CHECK(errhp, htype, status, ctlp, OCIfunc) \
if (OCI_SUCCESS != ((status) = (OCIfunc))) \
{ \
checkerr((dvoid *)(errhp), (ub4)(htype), (sword)(status), (text *)0, \
(sb4)0, (text *)__FILE__, (sb4)__LINE__); \
if ((status) != OCI_SUCCESS_WITH_INFO) \
cleanup((struct loadctl *)ctlp, (sb4)1); \
} else
#define CHECKERR(errhp, htype, status) \
checkerr((dvoid *)errhp, (ub4)(htype), (sword)(status), (text *)0, \
(sb4)0, (text *)__FILE__, (sb4)__LINE__);
#define FATAL(note, state) \
do \
{ \
checkerr((dvoid *)0, (ub4)OCI_HTYPE_ERROR, (sword)OCI_SUCCESS, \
(text *)(note), (sb4)(state), (text *)__FILE__, (sb4)__LINE__); \
cleanup((ctlp), (sb4)2); \
} while (0)
/* External references: */
externref struct tbl table;
externref struct sess session;
/* External definitions: */
externdef FILE *output_fp; /* for error msgs */
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
/* main */
/* */
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
int main(argc, argv)
int argc;
char *argv[];
{
sword ociret;
struct loadctl ctl;
struct loadctl *ctlp = &ctl;
output_fp = (session.outfn_sess) ? fopen((char *)session.outfn_sess, "w")
: stderr;
memset((dvoid *)ctlp, 0, sizeof(struct loadctl));
/* set up OCI environment and connect to the ORACLE server */
OCI_CHECK((dvoid *)0, (ub4)0, ociret, ctlp,
OCIInitialize((ub4) OCI_DEFAULT, (dvoid *)0,
(dvoid * (*)(dvoid *, size_t)) 0,
(dvoid * (*)(dvoid *, dvoid *, size_t))0,
(void (*)(dvoid *, dvoid *)) 0 ));
OCI_CHECK(ctlp->envhp_ctl, OCI_HTYPE_ENV, ociret, ctlp,
OCIEnvInit((OCIEnv **)&ctlp->envhp_ctl, OCI_DEFAULT, (size_t)0,
(dvoid **)0));
/* allocate error handles */
OCI_CHECK(ctlp->envhp_ctl, OCI_HTYPE_ENV, ociret, ctlp,
OCIHandleAlloc((dvoid *)ctlp->envhp_ctl,
(dvoid **)&ctlp->errhp_ctl, OCI_HTYPE_ERROR,
(size_t)0, (dvoid **)0));
OCI_CHECK(ctlp->envhp_ctl, OCI_HTYPE_ENV, ociret, ctlp,
OCIHandleAlloc((dvoid *)ctlp->envhp_ctl,
(dvoid **)&ctlp->errhp2_ctl, OCI_HTYPE_ERROR,
(size_t)0, (dvoid **)0));
/* server contexts */
OCI_CHECK(ctlp->envhp_ctl, OCI_HTYPE_ENV, ociret, ctlp,
OCIHandleAlloc((dvoid *)ctlp->envhp_ctl,
(dvoid **)&ctlp->srvhp_ctl, OCI_HTYPE_SERVER,
(size_t)0, (dvoid **)0));
OCI_CHECK(ctlp->envhp_ctl, OCI_HTYPE_ENV, ociret, ctlp,
OCIHandleAlloc((dvoid *)ctlp->envhp_ctl,
- 1
- 2
- 3
- 4
- 5
- 6
前往页