.ad 8
.bm 8
.fm 4
.bt $Copyright (c) 2000-2005 SAP AG$$Page %$
.tm 12
.hm 6
.hs 3
.tt 1 $SQL$Project Distributed Database System$VPI30ORC$
.tt 2 $$$
.tt 3 $$C CPR_KIND_ORACLE library functions$1999-03-29$
***********************************************************
.nf

.nf

.nf

    ========== licence begin  GPL
    Copyright (c) 2000-2005 SAP AG

    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License
    as published by the Free Software Foundation; either version 2
    of the License, or (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
    ========== licence end
.fo


.fo


.fo
Module  :
=========
.sp
Purpose :
.CM *-END-* purpose -------------------------------------
Define  :
.CM *-END-* define --------------------------------------
Use     :
.CM *-END-* use -----------------------------------------
Synonym :
.CM *-END-* synonym -------------------------------------
.sp;.cp 3
Author  : 
.sp
.cp 3
Created : 1986-01-01
.sp
.cp 3
Version : 1992-02-21
.sp
.cp 3
Release :      Date : 1999-03-29
Specification:
.CM *-END-* specification -------------------------------
.sp 2
***********************************************************
.sp
.cp 10
.fo
.oc _/1
Description:
.CM *-END-* description ---------------------------------
.sp 2
***********************************************************
.sp
.cp 10
.nf
.oc _/1
Structure:
.CM *-END-* structure -----------------------------------
.sp 2
**********************************************************
.sp
.cp 10
.nf
.sp
.CM -lll-
Code    :
/*PRETTY*/
#define FCALL

&ifdef DEBUG
&else
#line 65 "vpi30orc"
&endif
 
#include <memory.h>
#include <string.h>
#if defined(__STDC__)
#include <sys/types.h>
#endif

/* ----------------------------------------------- */
/*                      CPR_KIND_ORACLE                     */
/*                library functions                */
/* ----------------------------------------------- */


#if defined(__STDC__)
struct SQLDA* sqlald (int max_vars, size_t max_name, size_t max_ind_name)
#else
struct SQLDA* sqlald (max_vars, max_name, max_ind_name)
/*	The function sqlald allocates a descriptor and buffers.
	N is set to max_vars.
	Buffers pointed to by V, L, T and I are allocated, if
	max_vars > 0.
	Buffers pointed to by S, M, and C are allocated, if
	max_vars > 0 and max_name > 0. Then max_vars character
	buffers of length max_name are allocated and their
	addresses assigned to S [0], ..., S [max_vars - 1].
	Buffers pointed to by X, Y, and Z are allocated, if
	max_vars > 0 and max_ind_name > 0. Then max_vars character
	buffers of length max_ind_name are allocated and their
	addresses assigned to X [0], ..., X [max_vars - 1].

	Pointers, for which no buffers are allocated, are set to 0.
*/
int max_vars, max_name, max_ind_name;
#endif
{
	struct SQLDA *p;
	long i;
	BOOLEAN ok;

	sqlallocat (sizeof (struct SQLDA), (tsp00_Uint1**)&p, &ok);
	if (!ok) 
		sqlabort();
	p->N = max_vars;
	p->F = 0;

	if (max_vars > 0)
	{
		sqlallocat (p->N * sizeof (char*), (tsp00_Uint1**)&p->V, &ok);
		if (!ok) 
			sqlabort();
		sqlallocat (p->N * sizeof (sqlint4), (tsp00_Uint1**)&p->L, &ok);
		if (!ok) 
			sqlabort();
		sqlallocat (p->N * sizeof (sqlint2), (tsp00_Uint1**)&p->T, &ok);
		if (!ok) 
			sqlabort();
		sqlallocat (p->N * sizeof (sqlint2*), (tsp00_Uint1**)&p->I, &ok);
		if (!ok) 
			sqlabort();

		for (i = 0; i < p->N; i++)
		{
			p->V [i] = (char*) 0;
			p->L [i] = 0;
			p->T [i] = 0;
			p->I [i] = (sqlint2*) 0;
		}
	}
	else
	{
		p->V = (char**) 0;
		p->L = (sqlint4*) 0;
		p->T = (sqlint2*) 0;
		p->I = (sqlint2**) 0;
	}
	if (max_vars > 0 && max_name > 0)
	{
		sqlallocat (p->N * sizeof (char*), (tsp00_Uint1**)&p->S, &ok);
		if (!ok) 
			sqlabort();
		sqlallocat (p->N * max_name, (tsp00_Uint1**)p->S, &ok);
		if (!ok) 
			sqlabort();
		sqlallocat (p->N * sizeof (sqlint2), (tsp00_Uint1**)&p->M, &ok);
		if (!ok) 
			sqlabort();
		sqlallocat (p->N * sizeof (sqlint2), (tsp00_Uint1**)&p->C, &ok);
		if (!ok) 
			sqlabort();

		for (i = 0; i < p->N; i++)
		{
			p->M [i] = (sqlint2) max_name;
			p->C [i] = 0;
		}
		for (i = 1; i < p->N; i++)
			p->S [i] = p->S [i-1] + max_name;
	}
	else
	{
		p->S = (char**) 0;
		p->M = (sqlint2*) 0;
		p->C = (sqlint2*) 0;
	}
	if (max_vars > 0 && max_ind_name > 0) 
	{
		sqlallocat (p->N * sizeof (char*), (tsp00_Uint1**)&p->X, &ok);
		if (!ok) 
			sqlabort();
		sqlallocat (p->N * max_ind_name, (tsp00_Uint1**)p->X, &ok);
		if (!ok) 
			sqlabort();
		sqlallocat (p->N * sizeof (sqlint2), (tsp00_Uint1**)&p->Y, &ok);
		if (!ok) 
			sqlabort();
		sqlallocat (p->N * sizeof (sqlint2), (tsp00_Uint1**)&p->Z, &ok);
		if (!ok) 
			sqlabort();

		for (i = 0; i < p->N; i++)
		{
			p->Y [i] = (sqlint2) max_ind_name;
			p->Z [i] = 0;
		}
		for (i = 1; i < p->N; i++)
			p->X [i] = p->X [i-1] + max_ind_name;
	}
	else
	{
		p->X = (char**) 0;
		p->Y = (sqlint2*) 0;
		p->Z = (sqlint2*) 0;
	}
	return p;
}

#if defined(__STDC__)
void sqlclu (struct SQLDA *sqldp)
#else
void sqlclu (sqldp)
/*	The function sqlclu deallocates a descriptor and its buffers,
	previously allocated by sqlald.
*/
struct SQLDA *sqldp;
#endif
{
	if (sqldp->V)
	{
		sqlfree ((tsp00_Uint1*)sqldp->V);
		sqlfree ((tsp00_Uint1*)sqldp->L);
		sqlfree ((tsp00_Uint1*)sqldp->T);
		sqlfree ((tsp00_Uint1*)sqldp->I);
	}
	if (sqldp->S)
	{
		sqlfree ((tsp00_Uint1*)sqldp->S);
		sqlfree ((tsp00_Uint1*)sqldp->M);
		sqlfree ((tsp00_Uint1*)sqldp->C);
	}
	if (sqldp->X)
 	{
		sqlfree ((tsp00_Uint1*)sqldp->X);
		sqlfree ((tsp00_Uint1*)sqldp->Y);
		sqlfree ((tsp00_Uint1*)sqldp->Z);
	}
	sqlfree ((tsp00_Uint1*)sqldp);
}

#if defined(__STDC__)
void sqlprc (long *length, int *precision, int *scale)
#else
void sqlprc (length, precision, scale)
/*	The function sqlprc exstracts precision and scale fields
	from length according to the CPR_KIND_ORACLE conventions for the
	NUMBER data type. All parameters are pointers to long,
	length is input, precision and scale are output.
	This implementation requires, that a long variable occupies
	four bytes.
*/
long *length;
int *precision, *scale;
#endif
{
	long m_scale = 0xFF; /* mask for scale extraction */
	long s_scale = 0x80; /* sign bit of scale field */
	unsigned long m_prec = 0xFFFFFF00; /* mask for precision extraction */
	long c_prec  = 0x00FFFFFF; /* clear mask for shifted precision */

	*scale = *length & m_scale; /* extract scale */
	if (*length & s_scale) *scale = *scale | m_prec; /* propagate sign */
	*precision = (*length & m_prec) >> 8 & c_prec; /* extract prec. */
	return;
}

#if defined(__STDC__)
void sqlnul (unsigned short *value_type, unsigned short *type_code,
	int *null_status)
#else
void sqlnul (value_type, type_code, null_status)
/* 	The function sqlnul returns the data type with the highest order bit
	cleared in *type_code. If NULLs are permitted, it returns 1, else 0
	in *null_status. The input *value_type must be a datatype code
	returned be DESCRIBE. The parameters value_type and type_code are
	pointers to short, null_status is a pointer to long.
	This implementation requires, that a long variable occupies
	four and a short variable two bytes.
*/
unsigned short *value_type, *type_code;
int *null_status;
#endif
{
	unsigned short c_high = 0x7FFF; /* clear mask */
	unsigned short t_high = 0x8000; /* high order bit */

	*type_code = *value_type & c_high; /* clear highest order bit */
	*null_status = ((*value_type & t_high) >> 15) & 1;
	/* return null status */
	return;
}

#if defined(__STDC__)
void sqlblnk (struct SQLDA *sqldp, int arrsiz)
#else
void sqlblnk (sqldp, arrsiz)
/*	The function sqlblnk "blanks out" 0-bytes from character buffers of
	a bind sqlda pointed to by sqldp. For each buffer pointed to by
	sqldp->v [i], all character positions starting from the first 0-byte
	up to position sqldp->L [i] - 1 are filled with the charater ' '
	from left to right. This process is repeated for arrsiz elements
	of size L [i].
*/
struct SQLDA *sqldp;
int arrsiz;
#endif
{
	unsigned short type_code;
	int null_status;
	int j;
	long i, k;
	char *v;

	for (i = 0; i < sqldp->F; i++)
	{
		sqlnul ((unsigned short*) &(sqldp->T [i]), &type_code,
			&null_status);

		if (type_code != 1) continue; /*  for non chars */

		v = sqldp->V [i];

		for (j = 0; j < arrsiz; j++)
		{
			if (j > 0) v += sqldp->L [i];

			for (k = 0; k < sqldp->L [i]; k++)
				if (v [k] == '\0') break;

			for (; k < sqldp->L [i]; k++)
				v [k] = ' ';
		}
	}
}

#if defined(__STDC__)
void sqlglm (unsigned char *msg, size_t *siz, size_t *len)
#else
void sqlglm (msg, siz, len)
/*	Dummy function sqlglm, returns a standard message text
*/
unsigned char *msg;
int *siz, *len;
#endif
{
	static char txt [] = "SQLGLM - MESSAGE NOT AVAILABLE";
	
	*len = (*siz >= sizeof (txt)) ? sizeof (txt) - 1 : *siz;
	memcpy (msg, txt, *len);
}
.CM *-END-* code ----------------------------------------
.SP 2 
***********************************************************
