Re: pro-C host variable VARCHAR sizes
Date: 1996/01/06
Message-ID: <30ee3348.4273164_at_newshost.us.oracle.com>#1/1
On 5 Jan 1996 20:54:56 GMT, mprather_at_ix.netcom.com (Michael Prather ) wrote:
>I have a problem when declaring the host variables from within the
>'DECLARE SECTION' of embeded SQL. I have not yet been able to find a
>way to use a defined variable length when defining a VARCHAR or CHAR
>within this section. The only way that I have been able to get the
>declaration to work is to put hard-coded numbers within the statement.
>
>For example, I would like to use something like:
>
> #define VAR_LENGTH 10
> #define VAR2_LENGTH 20
> ...
> EXEC SQL BEGIN DECLARE SECTION;
> VARCHAR hostVariableName[VAR_LENGTH];
> CHAR hostVaribleName2[VAR2_LENGTH];
> EXEC SQL END DECLARE SECTION;
>
>I believe that it is not working because proc does not have a
>pre-processor to convert the #defines.
>
>I have also tried to use:
>
> unsigned int VAR_LENGTH = 10;
> unsigned int VAR2_LENGTH = 20;
> ...
> EXEC SQL BEGIN DECLARE SECTION;
> VARCHAR hostVariableName[VAR_LENGTH];
> CHAR hostVaribleName2[VAR2_LENGTH];
> EXEC SQL END DECLARE SECTION;
>
>
>The only thing that I have found that will work is exactally what I do
>not want to use -- hard-coded numbers:
>
> EXEC SQL BEGIN DECLARE SECTION;
> VARCHAR hostVariableName[10];
> CHAR hostVaribleName2[20];
> EXEC SQL END DECLARE SECTION;
>
>We have even tried to use 'const' in the C++ compiler and the same
>situation occurs.
>
>Does anyone know a way that either #defines or variables can be used
>for the array size versus using hard-coded numbers?
>
You were not specific as to what version of Oracle on what platform. However, what you are asking is supported in Pro*C 2.x, and C++ in 2.1x . Note also it is no longer mandatory to use the declare section. Below is some source from sample1.pc that you would find in $ORACLE_HOME/proc/demo.
/* * sample1.pc * * Prompts the user for an employee number, * then queries the emp table for the employee's * name, salary and commission. Uses indicator * variables (in an indicator struct) to determine * if the commission is NULL. * */
#include <stdio.h>
#include <string.h>
/* Define constants for VARCHAR lengths. */
#define UNAME_LEN 20 #define PWD_LEN 40
/* Declare variables. No declare section is
needed if MODE=ORACLE. */
VARCHAR username[UNAME_LEN]; /* VARCHAR is an Oracle-supplied
struct */
varchar password[PWD_LEN]; /* varchar can be in lower case
also. */
/* Define a host structure for the output values of
a SELECT statement. */
struct
{
VARCHAR emp_name[UNAME_LEN];
float salary; float commission;
} emprec;
/* Define an indicator struct to correspond
to the host output struct. */
struct
{
short emp_name_ind; short sal_ind; short comm_ind;
} emprec_ind;
Hope this helps. Received on Sat Jan 06 1996 - 00:00:00 CET