From: dtb@otto (David Bath)
Newsgroups: comp.databases.oracle
Subject: C VARCHAR library and assorted Pro*C functions by David T. Bath
Summary: Code for a small Oracle utilities library for Pro*C and C programmers
Keywords: Pro*C VARCHAR UNIX C
Date: 1 Oct 92 06:38:08 GMT
Organization: RMIT Computer Centre
NNTP-Posting-Host: otto.bf.rmit.oz.au


This shar archive gives you functions to handle Oracle Pro*C VARCHAR
types in C.  Look in README for details.  It also gives a few other
functions you might like to use if you are primarily a C programmer.

If you like, please mail me short details on
	(1) your mail address
		If you gave an internet address, can you give me
		numeric as well as alpha machine name.
	(2) who you are and who you work for

Regards:
dtb@otto.bf.rmit.oz.au ( 131.170.40.10 )
========================================================================
David T. Bath
email: 	dtb@otto.bf.rmit.oz.au
Work: 	Global Technology Corporation, Carlton, Vic, AUSTRALIA  (03) 3477511
#include <disclaimer.h>
=======================================================================
========================================================================
David T. Bath
email: 	dtb@otto.bf.rmit.oz.au
Work: 	Global Technology Corporation, Carlton, Vic, OZ  (03) 3477511
#include <disclaimer.h>
=======================================================================
---------- cut this line and above ---------
#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of archive 1 (of 1)."
# Contents:  MANIFEST README commit.pc connect.pc execimm.pc isqlca.pc
#   ldb.h makefile orapcc.mk rcshdr.c release.pc rollback.pc
#   sel1str.pc selstrn.pc vch.c vch.h
# Wrapped by dtb@cheops on Thu Oct  1 15:58:43 1992
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'MANIFEST' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'MANIFEST'\"
else
echo shar: Extracting \"'MANIFEST'\" \(834 characters\)
sed "s/^X//" >'MANIFEST' <<'END_OF_FILE'
X   File Name		Archive #	Description
X-----------------------------------------------------------
X MANIFEST                   1	This shipping list
X README                     1	README
X commit.pc                  1	Do commits
X connect.pc                 1	Connect to the database
X execimm.pc                 1	Execute immediate
X isqlca.pc                  1	Include the isqlca
X ldb.h                      1	Function headers
X makefile                   1	Makefile
X orapcc.mk                  1	Alternate make
X rcshdr.c                   1	Skeleton
X release.pc                 1	Release resources
X rollback.pc                1	Rollback
X sel1str.pc                 1	Select 1 string
X selstrn.pc                 1	Select 1 string a number of times
X vch.c                      1	VARCHAR functions
X vch.h                      1	VARCHAR header
END_OF_FILE
if test 834 -ne `wc -c <'MANIFEST'`; then
    echo shar: \"'MANIFEST'\" unpacked with wrong size!
fi
# end of 'MANIFEST'
fi
if test -f 'README' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'README'\"
else
echo shar: Extracting \"'README'\" \(917 characters\)
sed "s/^X//" >'README' <<'END_OF_FILE'
XWell, here are some of my little functions for dealing with Oracle Pro*C,
Xincluding VARCHAR datatypes.
X
XAs you can see, my approach is to make tiny little objects so that Pro*C
Xdoes not screw up on the scoping and I can then do other stuff in C, which
XI CAN control, debug et al.
X
XPlease let me know of bugs - I lost my real copies of source recently
Xand had to pull old backup copies.
X
XNo responsibility accepted - although I might tidy these up a bit and
Xadd to them.
X
XIf you are using a dain bramaged architecture (not 32 bit) then you
Xmight have problems.
X
XTreat this stuff as if under a GNU-type licence.
X
XBest of luck folks
X
X=======================================================
XDavid T. Bath
XWork
X	Global Technology Corporation
X	179 Grattan Street, CARLTON, Victoria, 3053, AUSTRALIA
X	(03) 3477511
XEmail
X	dtb@otto.bf.rmit.oz.au
X#include <disclaimer.h>
X=======================================================
END_OF_FILE
if test 917 -ne `wc -c <'README'`; then
    echo shar: \"'README'\" unpacked with wrong size!
fi
# end of 'README'
fi
if test -f 'commit.pc' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'commit.pc'\"
else
echo shar: Extracting \"'commit.pc'\" \(1088 characters\)
sed "s/^X//" >'commit.pc' <<'END_OF_FILE'
X/***********************************************************************
X* $Source$
X* $Revision$
X* $Date$
X* $State$
X* $Locker$
X* $Author$
X************************************************************************
X* 
X* $Log$
X* 
X************************************************************************
X* Description
X*	C access to Oracle COMMIT
X***********************************************************************/
X
Xstatic char *RCS_Id = "$Header$" ;
X
X#include <stdio.h>
X#if defined BSD
X#include <strings.h>
X#else
X#include <string.h>
X#endif
X#include "vch.h"
X
X#define SQLCA_STORAGE_CLASS extern
XEXEC SQL INCLUDE SQLCA.H;
XEXEC SQL WHENEVER SQLERROR   GOTO sql_err;
XEXEC SQL WHENEVER SQLWARNING GOTO sql_warn;
X
Xint 	ldb_commit ()
X{
X	EXEC SQL BEGIN DECLARE SECTION;
X	EXEC SQL END DECLARE SECTION;
X
X		EXEC SQL COMMIT WORK ;
X	return (0);
Xsql_err:
X#if defined SQLDEBUG
X	fprintf(stderr, "Oracle error %d on commit\n", sqlca.sqlcode);
X#endif
X	return (sqlca.sqlcode);
Xsql_warn:
X#if defined SQLDEBUG
X	fprintf(stderr, "Oracle warning %d on commit\n", sqlca.sqlcode);
X#endif
X	return (sqlca.sqlcode);
X}
X
END_OF_FILE
if test 1088 -ne `wc -c <'commit.pc'`; then
    echo shar: \"'commit.pc'\" unpacked with wrong size!
fi
# end of 'commit.pc'
fi
if test -f 'connect.pc' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'connect.pc'\"
else
echo shar: Extracting \"'connect.pc'\" \(1297 characters\)
sed "s/^X//" >'connect.pc' <<'END_OF_FILE'
X/***********************************************************************
X* $Source$
X* $Revision$
X* $Date$
X* $State$
X* $Locker$
X* $Author$
X************************************************************************
X* 
X* $Log$
X* 
X************************************************************************
X* Description
X*	Connect to local Oracle database identified by ORACLE_SID
X***********************************************************************/
X
Xstatic char *RCS_Id = "$Header$" ;
X
X#include <stdio.h>
X#if defined BSD
X#include <strings.h>
X#else
X#include <string.h>
X#endif
X#include "vch.h"
X
X#define SQLCA_STORAGE_CLASS extern
XEXEC SQL INCLUDE SQLCA.H;
XEXEC SQL WHENEVER SQLERROR   GOTO sql_err;
XEXEC SQL WHENEVER SQLWARNING GOTO sql_warn;
X
Xint     ldb_connect (ounm, oupw)
Xchar    *ounm;
Xchar    *oupw;
X{
X	  EXEC SQL BEGIN DECLARE SECTION;
X			  VARCHAR up[62];
X	  EXEC SQL END DECLARE SECTION;
X
X	  up.len=0;
X	  vch_strcat (&up, ounm);
X	  vch_strcat (&up, "/");
X	  vch_strcat (&up, oupw);
X			  EXEC SQL CONNECT :up ;
X	  return (0);
Xsql_err:
X#if defined SQLDEBUG
X	  fprintf(stderr, "Oracle error %d on connect\n", sqlca.sqlcode);
X#endif
X	  return (sqlca.sqlcode);
Xsql_warn:
X#if defined SQLDEBUG
X	  fprintf(stderr, "Oracle warning %d on connect\n", sqlca.sqlcode);
X#endif
X	  return (sqlca.sqlcode);
X}
X
END_OF_FILE
if test 1297 -ne `wc -c <'connect.pc'`; then
    echo shar: \"'connect.pc'\" unpacked with wrong size!
fi
# end of 'connect.pc'
fi
if test -f 'execimm.pc' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'execimm.pc'\"
else
echo shar: Extracting \"'execimm.pc'\" \(874 characters\)
sed "s/^X//" >'execimm.pc' <<'END_OF_FILE'
X/***********************************************************************
X* $Source$
X* $Revision$
X* $Date$
X* $State$
X* $Locker$
X* $Author$
X************************************************************************
X* 
X* $Log$
X* 
X************************************************************************
X* Description
X*	C access to EXECUTE IMMEDIATE against database
X***********************************************************************/
X
Xstatic char *RCS_Id = "$Header$" ;
X
X#include <stdio.h>
X#if defined BSD
X#include <strings.h>
X#else
X#include <string.h>
X#endif
X#include "vch.h"
X
X#define SQLCA_STORAGE_CLASS extern
XEXEC SQL INCLUDE sqlca.h ;
X
Xint     ldb_execimm (s)
Xchar    *s;
X{
X        EXEC SQL BEGIN DECLARE SECTION;
X                char    *v;
X        EXEC SQL END DECLARE SECTION;
X
X        v = s;
X        EXEC SQL EXECUTE IMMEDIATE :v;
X        return (sqlca.sqlcode);
X}
END_OF_FILE
if test 874 -ne `wc -c <'execimm.pc'`; then
    echo shar: \"'execimm.pc'\" unpacked with wrong size!
fi
# end of 'execimm.pc'
fi
if test -f 'isqlca.pc' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'isqlca.pc'\"
else
echo shar: Extracting \"'isqlca.pc'\" \(526 characters\)
sed "s/^X//" >'isqlca.pc' <<'END_OF_FILE'
X/***********************************************************************
X* $Source$
X* $Revision$
X* $Date$
X* $State$
X* $Locker$
X* $Author$
X************************************************************************
X* 
X* $Log$
X* 
X************************************************************************
X* Description
X*	Allows the Oracle sqlca to be declared into the library.
X***********************************************************************/
X
Xstatic char *RCS_Id = "$Header$" ;
X
X#define SQLCA_INIT
XEXEC SQL INCLUDE SQLCA.H;
END_OF_FILE
if test 526 -ne `wc -c <'isqlca.pc'`; then
    echo shar: \"'isqlca.pc'\" unpacked with wrong size!
fi
# end of 'isqlca.pc'
fi
if test -f 'ldb.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'ldb.h'\"
else
echo shar: Extracting \"'ldb.h'\" \(873 characters\)
sed "s/^X//" >'ldb.h' <<'END_OF_FILE'
X/***********************************************************************
X* $Source$
X* $Revision$
X* $Date$
X* $State$
X* $Locker$
X* $Author$
X************************************************************************
X* 
X* $Log$
X* 
X************************************************************************
X* Description
X*	Header for local database functions
X***********************************************************************/
X
X#ifndef DB_MAXLEN_SIMPLE_NM
X#define DB_MAXLEN_SIMPLE_NM 30
X#endif
X
X#ifndef DB_MAXLEN_USRNM
X#define DB_MAXLEN_USRNM DB_MAXLEN_SIMPLE_NM
X#endif 
X
X#ifndef DB_MAXLEN_PASSWD
X#define DB_MAXLEN_PASSWD DB_MAXLEN_SIMPLE_NM
X#endif
X
Xextern int 	ldb_connect ();
Xextern int 	ldb_release ();
Xextern int 	ldb_execimm ();
Xextern int 	ldb_commit ();
Xextern int 	ldb_rollback ();
Xextern int 	ldb_selstr_p ();
Xextern int 	ldb_selstr_f ();
Xextern int 	ldb_selstr_c ();
END_OF_FILE
if test 873 -ne `wc -c <'ldb.h'`; then
    echo shar: \"'ldb.h'\" unpacked with wrong size!
fi
# end of 'ldb.h'
fi
if test -f 'makefile' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'makefile'\"
else
echo shar: Extracting \"'makefile'\" \(1639 characters\)
sed "s/^X//" >'makefile' <<'END_OF_FILE'
X########################################################################
X# $Source$
X# $Revision$
X# $Date$
X# $State$
X# $Locker$
X# $Author$
X########################################################################
X# 
X# $Log$
X# 
X########################################################################
X# Description
X#	Makefile for Oracle Utility Functions
X########################################################################
X
XPCC = pcc
XPCC_INC_DIR = $(ORACLE_HOME)/c/lib
XPCCINC = $(ORACLE_HOME)/c/lib
XPCCFLAGS = include=$(PCCINC) \
X	ireclen=132 oreclen=132 \
X	select_error=no sqlcheck=full \
X	host=C userid=/ ltype=none
X
XSHELL=/bin/sh
X
XORAUTY_LIB_BASE = liboraut.a
X
XORAUTY_LIB_DIR = /ora/users/dse/lib
X
XORAUTY_HDR_DIR = /ora/users/dse/src/include
X
XORAUTY_OBJ = connect.o release.o isqlca.o execimm.o commit.o \
X	sel1str.o selstrn.o rollback.o vch.o
X
X$(ORAUTY_LIB_BASE) : $(ORAUTY_OBJ)
X	ar ruv $(ORAUTY_LIB_BASE) $(ORAUTY_OBJ)
X	ranlib $(ORAUTY_LIB_BASE)
X
X.SUFFIXES: .c .pc 
X
X.pc.c:
X	$(PCC) $(PCCFLAGS) iname=$*.pc oname=$*.c
X
Xconnect.o : connect.c vch.h
X
Xrelease.o : release.c vch.h
X
Xisqlca.o : isqlca.c vch.h
X
Xexecimm.o : execimm.c vch.h
X
Xcommit.o : commit.c vch.h
X
Xsel1str.o : sel1str.c vch.h
X
Xselstrn.o : selstrn.c vch.h
X
Xrollback.o : rollback.c vch.h
X
Xvch.o : vch.c vch.h
X
Xclean :
X	- rm *.o *.a *.lis
X	- ls *.pc | sed 's/^\(.*\)\.pc/rm \1.c/' | sh
X
Xinstall : $(ORAUTY_LIB_DIR)/$(ORAUTY_LIB_BASE) \
X	$(ORAUTY_HDR_DIR)/vch.h $(ORAUTY_HDR_DIR)/ldb.h
X
X$(ORAUTY_LIB_DIR)/$(ORAUTY_LIB_BASE) : $(ORAUTY_LIB_BASE)
X	cp $(ORAUTY_LIB_BASE) $(ORAUTY_LIB_DIR)
X
X$(ORAUTY_HDR_DIR)/vch.h : vch.h
X	cp vch.h $(ORAUTY_HDR_DIR)
X	cp ldb.h $(ORAUTY_HDR_DIR)
END_OF_FILE
if test 1639 -ne `wc -c <'makefile'`; then
    echo shar: \"'makefile'\" unpacked with wrong size!
fi
# end of 'makefile'
fi
if test -f 'orapcc.mk' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'orapcc.mk'\"
else
echo shar: Extracting \"'orapcc.mk'\" \(1918 characters\)
sed "s/^X//" >'orapcc.mk' <<'END_OF_FILE'
X########################################################################
X# $Source$
X# $Revision$
X# $Date$
X# $State$
X# $Locker$
X# $Author$
X########################################################################
X# 
X# $Log$
X# 
X########################################################################
X# Description
X#	Make include file for Oracle Pro*C Pre-compiler
X########################################################################
X
XPCC = pcc
XPCC_INC_DIR = $(ORACLE_HOME)/c/lib
XPCC_INC = include=$(PCC_INC_DIR)
XPCC_TXT_FLG = ireclen=132 oreclen=132 host=C ltype=none
XPCC_STD_FLG = $(PCC_TXT_FLG) $(PCC_INC)
X
X.SUFFIXES: .c .pc 
X
X.pc.c:
X	$(PCC) $(PCC_STD_FLG) iname=$*.pc oname=$*.c
X
Xclean_pc_intermed:
X	ls *.pc | sed -e 's/pc$/c' | xargs rm
X
XPCC = pcc
XPCC_INC_DIR = $(ORACLE_HOME)/c/lib
XPCCINC = $(ORACLE_HOME)/c/lib
XPCCFLAGS = include=$(PCCINC) \
X	select_error=no sqlcheck=full \
X	host=C userid=/ ltype=none
X
XORAUTY_LIB_BASE = liboraut.a
X
XORAUTY_LIB_DIR = /ora/users/dse/lib
X
XORAUTY_HDR_DIR = /ora/users/dse/src/include
X
XORAUTY_OBJ = connect.o release.o isqlca.o execimm.o commit.o \
X	sel1str.o selstrn.o rollback.o vch.o
X
X$(ORAUTY_LIB_BASE) : $(ORAUTY_OBJ)
X	ar ruv $(ORAUTY_LIB_BASE) $(ORAUTY_OBJ)
X	ranlib $(ORAUTY_LIB_BASE)
X
X.SUFFIXES: .c .pc 
X
X.pc.c:
X	$(PCC) $(PCC_STD_FLG) iname=$*.pc oname=$*.c
X
Xconnect.o : connect.c vch.h
X
Xrelease.o : release.c vch.h
X
Xisqlca.o : isqlca.c vch.h
X
Xexecimm.o : execimm.c vch.h
X
Xcommit.o : commit.c vch.h
X
Xsel1str.o : sel1str.c vch.h
X
Xselstrn.o : selstrn.c vch.h
X
Xrollback.o : rollback.c vch.h
X
Xvch.o : vch.c vch.h
X
Xclean :
X	- rm *.o *.a *.lis
X	- ls *.pc | sed 's/^\(.*\)\.pc/rm \1.c/' | sh
X
Xinstall : $(ORAUTY_LIB_DIR)/$(ORAUTY_LIB_BASE) \
X	$(ORAUTY_HDR_DIR)/vch.h $(ORAUTY_HDR_DIR)/ldb.h
X
X$(ORAUTY_LIB_DIR)/$(ORAUTY_LIB_BASE) : $(ORAUTY_LIB_BASE)
X	cp $(ORAUTY_LIB_BASE) $(ORAUTY_LIB_DIR)
X
X$(ORAUTY_HDR_DIR)/vch.h : vch.h
X	cp vch.h $(ORAUTY_HDR_DIR)
X	cp ldb.h $(ORAUTY_HDR_DIR)
END_OF_FILE
if test 1918 -ne `wc -c <'orapcc.mk'`; then
    echo shar: \"'orapcc.mk'\" unpacked with wrong size!
fi
# end of 'orapcc.mk'
fi
if test -f 'rcshdr.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'rcshdr.c'\"
else
echo shar: Extracting \"'rcshdr.c'\" \(422 characters\)
sed "s/^X//" >'rcshdr.c' <<'END_OF_FILE'
X/***********************************************************************
X* $Source$
X* $Revision$
X* $Date$
X* $State$
X* $Locker$
X* $Author$
X************************************************************************
X* 
X* $Log$
X* 
X************************************************************************
X* Description
X***********************************************************************/
X
Xstatic char *RCS_Id = "$Header$" ;
X
END_OF_FILE
if test 422 -ne `wc -c <'rcshdr.c'`; then
    echo shar: \"'rcshdr.c'\" unpacked with wrong size!
fi
# end of 'rcshdr.c'
fi
if test -f 'release.pc' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'release.pc'\"
else
echo shar: Extracting \"'release.pc'\" \(1167 characters\)
sed "s/^X//" >'release.pc' <<'END_OF_FILE'
X/***********************************************************************
X* $Source$
X* $Revision$
X* $Date$
X* $State$
X* $Locker$
X* $Author$
X************************************************************************
X* 
X* $Log$
X* 
X************************************************************************
X* Description
X*	C access to Oracle RELEASE
X***********************************************************************/
X
Xstatic char *RCS_Id = "$Header$" ;
X
X#include <stdio.h>
X#if defined BSD
X#include <strings.h>
X#else
X#include <string.h>
X#endif
X#include "vch.h"
X
X#define SQLCA_STORAGE_CLASS extern
XEXEC SQL INCLUDE SQLCA.H;
X 
XEXEC SQL WHENEVER SQLERROR   GOTO sql_err;
XEXEC SQL WHENEVER SQLWARNING GOTO sql_warn;
X
Xint     ldb_release ()
X{
X        EXEC SQL BEGIN DECLARE SECTION;
X        EXEC SQL END DECLARE SECTION;
X		EXEC SQL ROLLBACK WORK RELEASE ;
X        return (sqlca.sqlcode);
Xsql_err:
X#if defined SQLDEBUG
X        fprintf(stderr, "Oracle error %d on release\n", sqlca.sqlcode);
X#endif
X        return (sqlca.sqlcode);
Xsql_warn:
X#if defined SQLDEBUG
X        fprintf(stderr, "Oracle warning %d on release\n", sqlca.sqlcode);
X#endif
X        return (sqlca.sqlcode);
X}
X
END_OF_FILE
if test 1167 -ne `wc -c <'release.pc'`; then
    echo shar: \"'release.pc'\" unpacked with wrong size!
fi
# end of 'release.pc'
fi
if test -f 'rollback.pc' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'rollback.pc'\"
else
echo shar: Extracting \"'rollback.pc'\" \(1098 characters\)
sed "s/^X//" >'rollback.pc' <<'END_OF_FILE'
X/***********************************************************************
X* $Source$
X* $Revision$
X* $Date$
X* $State$
X* $Locker$
X* $Author$
X************************************************************************
X* 
X* $Log$
X* 
X************************************************************************
X* Description
X*	C access to Oracle ROLLBACK
X***********************************************************************/
X
Xstatic char *RCS_Id = "$Header$" ;
X
X#include <stdio.h>
X#if defined BSD
X#include <strings.h>
X#else
X#include <string.h>
X#endif
X#include "vch.h"
X
X#define SQLCA_STORAGE_CLASS extern
XEXEC SQL INCLUDE SQLCA.H;
XEXEC SQL WHENEVER SQLERROR   GOTO sql_err;
XEXEC SQL WHENEVER SQLWARNING GOTO sql_warn;
X
Xint 	ldb_rollback ()
X{
X	EXEC SQL BEGIN DECLARE SECTION;
X	EXEC SQL END DECLARE SECTION;
X
X		EXEC SQL ROLLBACK WORK ;
X	return (0);
Xsql_err:
X#if defined SQLDEBUG
X	fprintf(stderr, "Oracle error %d on rollback\n", sqlca.sqlcode);
X#endif
X	return (sqlca.sqlcode);
Xsql_warn:
X#if defined SQLDEBUG
X	fprintf(stderr, "Oracle warning %d on rollback\n", sqlca.sqlcode);
X#endif
X	return (sqlca.sqlcode);
X}
X
END_OF_FILE
if test 1098 -ne `wc -c <'rollback.pc'`; then
    echo shar: \"'rollback.pc'\" unpacked with wrong size!
fi
# end of 'rollback.pc'
fi
if test -f 'sel1str.pc' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'sel1str.pc'\"
else
echo shar: Extracting \"'sel1str.pc'\" \(1214 characters\)
sed "s/^X//" >'sel1str.pc' <<'END_OF_FILE'
X/***********************************************************************
X* $Source$
X* $Revision$
X* $Date$
X* $State$
X* $Locker$
X* $Author$
X************************************************************************
X* 
X* $Log$
X* 
X************************************************************************
X* Description
X*	Select a single string from the database into a C string
X***********************************************************************/
X
Xstatic char *RCS_Id = "$Header$" ;
X
X#include <stdio.h>
X#include <string.h>
X#include <limits.h>
X#include "vch.h"
X
XEXEC SQL INCLUDE SQLCA.H ;
XEXEC SQL WHENEVER SQLERROR GOTO sql_err;
XEXEC SQL WHENEVER SQLWARNING GOTO sql_warn;
X
X#define MAXSTRSIZE 5120
X
Xint 	ldb_sel1str (tgt, stmt)
Xchar 	*tgt;
Xchar 	*stmt;
X{
X	EXEC SQL BEGIN DECLARE SECTION;
X		VARCHAR 	t[5121];
X		char 	*s;
X	EXEC SQL END DECLARE SECTION;
X
X	s = stmt;
X	EXEC SQL PREPARE S1 FROM :s;
X	EXEC SQL DECLARE C1 CURSOR FOR S1;
X	EXEC SQL OPEN C1;
X	EXEC SQL FETCH C1 into :t;
X	str_vchcpy (tgt, &t);
X	EXEC SQL CLOSE C1;
X	return (sqlca.sqlcode);
Xsql_err:
X	fprintf(stderr, "SQLERROR %d\n", sqlca.sqlcode);
X	return (sqlca.sqlcode);
Xsql_warn:
X	fprintf(stderr, "SQLWARNING %d\n", sqlca.sqlcode);
X	return (sqlca.sqlcode);
X}
END_OF_FILE
if test 1214 -ne `wc -c <'sel1str.pc'`; then
    echo shar: \"'sel1str.pc'\" unpacked with wrong size!
fi
# end of 'sel1str.pc'
fi
if test -f 'selstrn.pc' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'selstrn.pc'\"
else
echo shar: Extracting \"'selstrn.pc'\" \(1217 characters\)
sed "s/^X//" >'selstrn.pc' <<'END_OF_FILE'
X/***********************************************************************
X* $Source$
X* $Revision$
X* $Date$
X* $State$
X* $Locker$
X* $Author$
X************************************************************************
X* 
X* $Log$
X* 
X************************************************************************
X* Description
X*	C access to select many rows of a single string from Oracle.
X*	There are 3 related calls.
X*	ldb_selstr_p ()	- Prepare a statement
X*	ldb_selstr_f () - Fetch a row
X*	ldb_selstr_c () - Close the cursor
X***********************************************************************/
X
Xstatic char *RCS_Id = "$Header$" ;
X
X#include <stdio.h>
X#ifdef BSD
X#include <strings.h>
X#else
X#include <string.h>
X#endif
X#include <limits.h>
X#include "vch.h"
X
X
XEXEC SQL INCLUDE SQLCA.H ;
XEXEC SQL BEGIN DECLARE SECTION;
X	VARCHAR 	t[5120];
X	char 	*s;
XEXEC SQL END DECLARE SECTION;
X
Xint 	ldb_selstr_p (stmt)
Xchar 	*stmt;
X{
X	s = stmt;
X	EXEC SQL PREPARE S1 FROM :s;
X	EXEC SQL DECLARE C1 CURSOR FOR S1;
X	EXEC SQL OPEN C1;
X	return (sqlca.sqlcode);
X}
X
Xint 	ldb_selstr_f (tgt)
Xchar 	*tgt;
X{
X	EXEC SQL FETCH C1 into :t;
X	str_vchcpy (tgt, &t);
X	return (sqlca.sqlcode);
X}
X
Xint 	ldb_selstr_c ()
X{
X	EXEC SQL CLOSE C1;
X	return (sqlca.sqlcode);
X}
END_OF_FILE
if test 1217 -ne `wc -c <'selstrn.pc'`; then
    echo shar: \"'selstrn.pc'\" unpacked with wrong size!
fi
# end of 'selstrn.pc'
fi
if test -f 'vch.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'vch.c'\"
else
echo shar: Extracting \"'vch.c'\" \(10040 characters\)
sed "s/^X//" >'vch.c' <<'END_OF_FILE'
X/***********************************************************************
X* $Source$
X* $Revision$
X* $Date$
X* $State$
X* $Locker$
X* $Author$
X************************************************************************
X* 
X* $Log$
X* 
X************************************************************************
X* Description
X*	Provides a number of C functions to manipulate the Oracle VARCHAR
X*	type in a manner similar to the string handling library of C and
X*	with a number of functions converting between VARCHARS and strings.
X***********************************************************************/
X
Xstatic char *RCS_Id = "$Header$" ;
X
X#include <stdio.h>
X#if defined BSD
X#include <strings.h>
X#else
X#include <string.h>
X#endif
X#include <memory.h>
X#include "vch.h"
X
X
X/***********************************************************************
X** NAME
X** 	str_vchcat()
X** PURPOSE
X** 	Add varchar to end of string
X** SYNOPSIS
X** 	str_vchcat (s, v)
X** 	char 	*s;
X** 	struct vch_min *v;
X** DESCRIPTION
X** 	This function copies the data from a varchar to its length (or to
X** 	a null, whichever is first) onto the end of a standard C string and 
X**  returns a pointer to the result.
X***********************************************************************/
Xchar 	*str_vchcat (s, v)
Xchar 	*s;
Xstruct vch_min *v;
X{
X	return (strncat (s, v->arr, v->len));
X}
X
X
X
X/***********************************************************************
X** NAME
X** 	str_vchcpy()
X** PURPOSE
X** 	Copy the string from a varchar into standard C string
X** SYNOPSIS
X** 	str_vchcpy (s, v)
X** 	char 	*s;
X** 	struct vch_min *v;
X** DESCRIPTION
X** 	This function copies the data from a varchar to the length (or to
X** 	a null, whichever is first) into a standard C string and returns
X** 	the pointer to the result.
X***********************************************************************/
Xchar 	*str_vchcpy (s, v)
Xchar 	*s;
Xstruct vch_min *v;
X{
X	strncpy (s, v->arr, v->len);
X	*(s+(v->len)) = '\0';
X	return (s);
X}
X
X
X
X
X/***********************************************************************
X** NAME
X** 	str_vchncat()
X** PURPOSE
X** 	Add varchar to end of string
X** SYNOPSIS
X** 	str_vchncat (s, v, n)
X** 	char 	*s;
X** 	struct vch_min *v;
X** 	unsigned int n;
X** DESCRIPTION
X** 	This function copies the data from a varchar to its length (or to
X** 	a null, whichever is first) onto the end of a standard C string and 
X**  returns a pointer to the result.
X***********************************************************************/
Xchar 	*str_vchncat (s, v, n)
Xchar 	*s;
Xstruct vch_min *v;
Xunsigned int n;
X{
X	if (n > v->len)
X		n = v->len;
X	return (strncat (s, v->arr, n));
X}
X
X
X
X/***********************************************************************
X** NAME
X** 	str_vchncpy()
X** PURPOSE
X** 	Copy the string from a varchar into standard C string length limited
X** SYNOPSIS
X** 	str_vchncpy (s, v, n)
X** 	char 	*s;
X** 	struct vch_min *v;
X** 	unsigned int n;
X** DESCRIPTION
X** 	This function copies the data from a varchar to the length (or to
X** 	a null, whichever is first) into a standard C string to a maximum
X** 	length n and returns a pointer to the result.
X*/
Xchar 	*str_vchncpy (s, v, n)
Xchar 	*s;
Xstruct vch_min *v;
Xunsigned int n;
X{
X	if (v->len < n)
X		n = v->len;
X	strncpy (s, v->arr, n);
X	*(s+n)='\0';
X	return (s);
X}
X
X
X
X/***********************************************************************
X** NAME
X** 	str_vchdup()
X** PURPOSE
X** 	Duplicate varchar as string
X** SYNOPSIS
X** 	vch_vchdup (v)
X** 	struct vch_min *v;
X** DESCRIPTION
X** 	Allocates and copies a varchar
X************************************************************************/
Xchar 	*str_vchdup (v)
Xstruct vch_min *v;
X{
X	char 	*d = NULL;
X
X	if (v != NULL) {
X		if ((d = (char *)malloc (v->len + 1)) != (char *)NULL) {
X			memcpy (d, v->arr, v->len);
X			*(d+(v->len)) = '\0';
X		}
X	}
X	return (d);
X}
X
X
X/***********************************************************************
X** NAME
X** 	vch_alloc()
X** PURPOSE
X** 	Allocate storage for a varchar
X** SYNOPSIS
X** 	struct vch_min *vch_alloc(n)
X** 	VCH_LEN_TYPE 	n;
X** DESCRIPTION
X** 	Allocates storage for a varchar with data length n.  Actually,
X** 	the storage requirement will be rounded up to a multiple of 2
X** 	to be "neat".
X***********************************************************************/
Xstruct vch_min 	*vch_alloc (n)
XVCH_LEN_TYPE 	n;
X{
X	int 	size_req;
X	size_req = sizeof (struct vch_min) + n - VCH_MIN_ARR_LEN ;
X	size_req += size_req % 2;
X	return ( (struct vch_min *) malloc (size_req) );
X}
X
X
X/***********************************************************************
X** NAME
X** 	vch_len()
X** PURPOSE
X** 	Return length of a varchar type
X** SYNOPSIS
X** 	r = vch_len (v)
X** 	int 	r;
X** 	struct vch_min 	*v;
X** DESCRIPTION
X** 	Passed the pointer to a varchar type, the length is evaluated using
X** 	the len element (rather than strlen() the arr element).  Although the
X** 	type of the len element is typically an unsigned short, a signed integer
X** 	is returned to allow for error codes.
X** DIAGNOSTICS
X** 	A value of -1 is returned on error, such as a null pointer.
X** AUTHOR
X** 	David T. Bath, CSSC, Telecom Australia
X***********************************************************************/
Xint 	vch_len (v)
Xstruct vch_min *v;
X{
X	return ( v == NULL ? -1 : v->len);
X}
X
X
X
X
X/***********************************************************************
X** NAME
X** 	vch_strcat()
X** PURPOSE
X** 	Copy the string into a varchar 
X** SYNOPSIS
X** 	vch_strcat (v, s)
X** 	char 	*s;
X** 	struct vch_min *v;
X** DESCRIPTION
X** 	Copies the string (including the null) into a varchar
X** 	and sets the length of the varchar to the string length.
X************************************************************************/
Xstruct vch_min 	*vch_strcat (v, s)
Xstruct vch_min *v;
Xchar 	*s;
X{
X	strcpy (v->arr+v->len, s);
X	v->len += strlen (s);
X	return (v);
X}
X
X
X
X/***********************************************************************
X** NAME
X** 	vch_strcpy()
X** PURPOSE
X** 	Copy the string into a varchar 
X** SYNOPSIS
X** 	vch_strcpy (v, s)
X** 	char 	*s;
X** 	struct vch_min *v;
X** DESCRIPTION
X** 	Copies the string (including the null) into a varchar
X** 	and sets the length of the varchar to the string length.
X************************************************************************/
Xstruct vch_min 	*vch_strcpy (v, s)
Xstruct vch_min *v;
Xchar 	*s;
X{
X	strcpy (v->arr, s);
X	v->len = strlen (v->arr);
X	return (v);
X}
X
X
X
X/***********************************************************************
X** NAME
X** 	vch_strncat()
X** PURPOSE
X** 	Concatenates the string onto end of a varchar (length limited)
X** SYNOPSIS
X** 	vch_strncat (v, s, n)
X** 	char 	*s;
X** 	struct vch_min *v;
X** 	unsigned int n;
X** DESCRIPTION
X** 	Concatenates the string (including the null) into a varchar
X** 	and sets the length of the varchar to the string length.
X************************************************************************/
Xstruct vch_min 	*vch_strncat (v, s, n)
Xstruct vch_min *v;
Xchar 	*s;
Xunsigned int n;
X{
X	if (n > strlen(s))
X		n = strlen(s);
X	strncpy (v->arr+v->len, s, n);
X	v->len += n;
X	return (v);
X}
X
X
X
X/***********************************************************************
X** NAME
X** 	vch_strncpy()
X** PURPOSE
X** 	Copy the string into a varchar (length limited)
X** SYNOPSIS
X** 	struct vch_min *vch_strncpy (v, s, n)
X** 	char 	*s;
X** 	struct vch_min *v;
X** 	unsigned int n;
X** DESCRIPTION
X** 	Copies the string (including the null) into a varchar
X** 	and sets the length of the varchar to the string length, up to
X** 	a maximum of length n and returns a pointer to the result.
X************************************************************************/
Xstruct vch_min 	*vch_strncpy (v, s, n)
Xstruct vch_min *v;
Xchar 	*s;
Xunsigned int 	n;
X{
X	strncpy (v->arr, s, n);
X	v->len = strlen (v->arr);
X	return (v);
X}
X
X
X
X
X/***********************************************************************
X** NAME
X** 	vch_vchcat()
X** PURPOSE
X** 	Concatenate varchar to another varchar
X** SYNOPSIS
X** 	vch_vchcat (v1, v2)
X** 	struct vch_min *v1, *v2;
X** DESCRIPTION
X** 	Concatenate varchar v2 onto end of varchar v1
X************************************************************************/
Xstruct vch_min 	*vch_vchcat (v1, v2)
Xstruct vch_min *v1;
Xstruct vch_min *v2;
X{
X	if ((v1 != NULL) && (v2 != NULL)) {
X		memcpy (v1->arr + v1->len, v2->arr, v2->len);
X		v1->len += v2->len;
X	}
X	return (v1);
X}
X
X
X
X/***********************************************************************
X** NAME
X** 	vch_vchcpy()
X** PURPOSE
X** 	Copy varchar to another varchar
X** SYNOPSIS
X** 	vch_vchcpy (v1, v2)
X** 	struct vch_min *v1, *v2;
X** DESCRIPTION
X** 	Copies varchar v2 into varchar v1
X************************************************************************/
Xstruct vch_min 	*vch_vchcpy (v1, v2)
Xstruct vch_min *v1;
Xstruct vch_min *v2;
X{
X	memcpy (v1->arr, v2->arr, v1->len=v2->len);
X	return (v1);
X}
X
X
X
X/***********************************************************************
X** NAME
X** 	vch_vchncat()
X** PURPOSE
X** 	Concatenate varchar to another varchar (length limited)
X** SYNOPSIS
X** 	vch_vchncat (v1, v2, n)
X** 	struct vch_min *v1, *v2;
X** 	VCH_LEN_TYPE 	n;
X** DESCRIPTION
X** 	Concatenate varchar v2 onto end of varchar v1 adding max on n bytes
X************************************************************************/
Xstruct vch_min 	*vch_vchncat (v1, v2, n)
Xstruct vch_min *v1;
Xstruct vch_min *v2;
XVCH_LEN_TYPE n;
X{
X	if ((v1 != NULL) && (v2 != NULL)) {
X		if (n > v2->len)
X			n = v2->len;
X		memcpy (v1->arr + v1->len, v2->arr, n);
X		v1->len += n;
X	}
X	return (v1);
X}
X
X
X
X/***********************************************************************
X** NAME
X** 	vch_vchncpy()
X** PURPOSE
X** 	Copy varchar to another varchar (length limited)
X** SYNOPSIS
X** 	vch_vchncpy (v1, v2, n)
X** 	struct vch_min *v1, *v2;
X** 	VCH_LEN_TYPE 	n;
X** DESCRIPTION
X** 	Copies varchar v2 into varchar v1 (length limited)
X***********************************************************************/
Xstruct vch_min 	*vch_vchncpy (v1, v2, n)
Xstruct vch_min *v1;
Xstruct vch_min *v2;
XVCH_LEN_TYPE 	n;
X{
X	memcpy (v1->arr, v2->arr, v1->len = ((v2->len < n) ? v2->len : n ));
X	return (v1);
X}
X
END_OF_FILE
if test 10040 -ne `wc -c <'vch.c'`; then
    echo shar: \"'vch.c'\" unpacked with wrong size!
fi
# end of 'vch.c'
fi
if test -f 'vch.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'vch.h'\"
else
echo shar: Extracting \"'vch.h'\" \(1532 characters\)
sed "s/^X//" >'vch.h' <<'END_OF_FILE'
X/***********************************************************************
X* $Source$
X* $Revision$
X* $Date$
X* $State$
X* $Locker$
X* $Author$
X************************************************************************
X* 
X* $Log$
X* 
X************************************************************************
X* Description
X*	Header for Oracle VARCHAR interface functions
X***********************************************************************/
X
X/* static char *RCS_Id = "$Header$" ; */
X
X#if ! defined VCH_HDR_INCL
X#define VCH_HDR_INCL
X
X#if ! defined VCH_LEN_TYPE
X#define VCH_LEN_TYPE unsigned short
X#endif
X#if ! defined VCH_LEN_TYPE
X#define VCH_LEN_TYPE unsigned short
X#endif
X#if ! defined VCH_ARR_TYPE_PREFIX
X#define VCH_ARR_TYPE_PREFIX unsigned char
X#endif
X#if ! defined VCH_MIN_ARR_TYPE_SUFFIX
X#define VCH_MIN_ARR_LEN 	2
X#endif
X
Xstruct vch_min { 
X	VCH_LEN_TYPE len;
X	VCH_ARR_TYPE_PREFIX 	arr [ VCH_MIN_ARR_LEN ] ;
X} ;
X
X#define VCH_DECL(a,b) \
X	struct { VCH_LEN_TYPE len; VCH_ARR_TYPE_PREFIX arr [ b ]; } a
X
X#endif
X
Xextern char 	*str_vchcat ();
Xextern char 	*str_vchcpy ();
Xextern char 	*str_vchdup ();
Xextern char 	*str_vchncat ();
Xextern char 	*str_vchncpy ();
Xextern int 	vch_len();
Xextern struct vch_min 	*vch_alloc ();
Xextern struct vch_min 	*vch_strcat ();
Xextern struct vch_min 	*vch_strcpy ();
Xextern struct vch_min 	*vch_strncat ();
Xextern struct vch_min 	*vch_strncpy ();
Xextern struct vch_min 	*vch_vchcat ();
Xextern struct vch_min 	*vch_vchcpy ();
Xextern struct vch_min 	*vch_vchncat ();
Xextern struct vch_min 	*vch_vchncpy ();
X
END_OF_FILE
if test 1532 -ne `wc -c <'vch.h'`; then
    echo shar: \"'vch.h'\" unpacked with wrong size!
fi
# end of 'vch.h'
fi
echo shar: End of archive 1 \(of 1\).
cp /dev/null ark1isdone
MISSING=""
for I in 1 ; do
    if test ! -f ark${I}isdone ; then
	MISSING="${MISSING} ${I}"
    fi
done
if test "${MISSING}" = "" ; then
    echo You have the archive.
    rm -f ark[1-9]isdone
else
    echo You still need to unpack the following archives:
    echo "        " ${MISSING}
fi
##  End of shell archive.
exit 0
-- 
========================================================================
David T. Bath
email: 	dtb@otto.bf.rmit.oz.au
Work: 	Global Technology Corporation, Carlton, Vic, OZ  (03) 3477511