Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> SQLSQLDAAlloc() and sqlaldt()

SQLSQLDAAlloc() and sqlaldt()

From: Alex Vinokur <alexander.vinokur_at_telrad.co.il>
Date: Mon, 08 Nov 1999 05:51:47 GMT
Message-ID: <805odk$beo$1@nnrp1.deja.com>

Below is shown an information

        concerning the SQLSQLDAAlloc() function.

I have got several questions.

  1. How many parameters does SQLSQLDAAlloc() take : 4 or 3?

   <quote>
   Recall that you allocate storage space    for a descriptor with the
   SQLSQLDAAlloc() library function.
   The syntax, using ANSI C notation, is:

   SQLDA *SQLSQLDAAlloc(

                dvoid           *context,
                unsigned int    max_vars,
                unsigned int    max_name,
                unsigned int    max_ind_name
                );

   </quote>
   However, sometimes SQLSQLDAAlloc() takes 3 ones (see below).

2. What does SQL_SINGLE_RCTX (first parameter's value) mean?

   Can SQL_SINGLE_RCTX have another values of its first parameter?    When is it worth using another values?    When is it necessary to use another values?

3. Is SQLSQLDAAlloc () "cleverer" than sqlaldt()?

   Note. SQLSQLDAAlloc () takes 4 (?) parameters,

         sqlaldt() takes only 3 ones.

        Thanks,
        Alex


==========================================
==========================================
Pro*C/C++ Precompiler Programmer's Guide Release 8.0
A58233-01

<quote>

14
Using Dynamic SQL: Advanced Concepts

This chapter shows you how to implement dynamic SQL Method 4, which lets your program accept or build dynamic SQL statements that contain a varying
number of host variables. Subjects discussed include the following:

</quote>

<quote>

How is the SQLDA Referenced?

The bind and select descriptors are usually referenced by pointer. A dynamic
SQL program should declare a pointer to at least one bind descriptor, and a
pointer to at least one select descriptor, in the following way:

#include <sqlda.h>

...
SQLDA *bind_dp;
SQLDA *select_dp;

You can then use the SQLSQLDAAlloc() function to allocate the descriptor, as
follows:

bind_dp = SQLSQLDAAlloc(runtime_context, size, name_length, ind_name_length);

SQLSQLDAAlloc() was known as sqlaldt() before Oracle8.

The constant SQL_SINGLE_RCTX is defined as (dvoid*)0. Use it for runtime_context when your application is single-threaded.

</quote>

<quote>

Declaring a SQLDA

To declare a SQLDA, include the sqlda.h header file. The contents of the SQLDA are

struct SQLDA
{

    long    N;          /* Descriptor size in number of entries */
    char  **V;        Ptr to Arr of addresses of main variables */
    long   *L;              /* Ptr to Arr of lengths of buffers */
    short  *T;                /* Ptr to Arr of types of buffers */
    short **I;      * Ptr to Arr of addresses of indicator vars */
    long    F;         /* Number of variables found by DESCRIBE */
    char  **S;          /* Ptr to Arr of variable name pointers */
    short  *M;       /* Ptr to Arr of max lengths of var. names */
    short  *C;    * Ptr to Arr of current lengths of var. names */
    char  **X;         /* Ptr to Arr of ind. var. name pointers */
    short  *Y;  /* Ptr to Arr of max lengths of ind. var. names */
    short  *Z;  /* Ptr to Arr of cur lengths of ind. var. names */
};

Allocating a SQLDA

After declaring a SQLDA, you allocate storage space for it with the SQLSQLDAAlloc() library function (known as sqlaldt() before Oracle8), using
the syntax

descriptor_name = SQLSQLDAAlloc (runtime_context, max_vars, max_name, max_ind_name);

where:

 runtime_context pointer to runtime context

 max_vars         Is the maximum number of select-list items or
                  placeholders that the descriptor can describe.


 max_name         Is the maximum length of select-list or placeholder
                  names.


 max_ind_name     Is the maximum length of indicator variable names,
which
                  are optionally appended to placeholder names. This
                  parameter applies to bind descriptors only, so set it
to
                  zero when allocating a select descriptor.



Besides the descriptor, SQLSQLDAAlloc() allocates data buffers to which descriptor variables point.

</quote>

<quote>

Allocate Storage Space for the Descriptors

Recall that you allocate storage space for a descriptor with the SQLSQLDAAlloc() library function. The syntax, using ANSI C notation, is:

SQLDA *SQLSQLDAAlloc(dvoid *context, unsigned int max_vars, unsigned int max_name, unsigned int max_ind_name);

The SQLSQLDAAlloc() function allocates the descriptor structure and the arrays addressed by the pointer variables V, L, T, and I.

If max_name is non-zero, arrays addressed by the pointer variables S, M, and
C are allocated. If max_ind_name is non-zero, arrays addressed by the pointer variables X, Y, and Z are allocated. No space is allocated if max_name and max_ind_name are zero.

If SQLSQLDAAlloc() succeeds, it returns a pointer to the structure. If SQLSQLDAAlloc() fails, it returns a zero.

In our example, you allocate select and bind descriptors, as follows:

select_des = SQLSQLDAAlloc(SQL_SINGLE_RCTX, 3, (size_t) 5, (size_t) 0); bind_des = SQLSQLDAAlloc(SQL_SINGLE_RCTX, 3, (size_t) 5, (size_t) 4);

</quote>
In the complete program example below, three input host arrays are used to
INSERT rows into the EMP table. Note that EXECUTE can be used for Data Manipulation Language statements other than queries with Method 4.

#include <stdio.h>
#include <sqlca.h>
#include <sqlda.h>

[snip]

SQLDA *binda;

[snip]

extern SQLDA *SQLSQLDAAlloc();
main()
{

[snip]

/* Allocate the descriptors and set the N component.

   This must be done before the DESCRIBE. */     binda = SQLSQLDAAlloc(3, ARRAY_SIZE, 0);     binda->N = 3;

[snip]

}
</quote>

<quote>
This sample program only processes up to MAX_ITEMS bind variables and MAX_ITEMS select-list items. MAX_ITEMS is
#defined to be 40.

****************************************************************/


#include <stdio.h>
#include <string.h>
#include <setjmp.h>

[snip]

SQLDA *bind_dp;
SQLDA *select_dp;

extern SQLDA *SQLSQLDAAlloc();
extern void sqlnul();

[snip]

alloc_descriptors(size, max_vname_len, max_iname_len) int size;
int max_vname_len;
int max_iname_len;
{

    int i;

    /*
     * The first SQLSQLDAAlloc parameter determines the maximum number
     * of array elements in each variable in the descriptor. In
     * other words, it determines the maximum number of bind
     * variables or select-list items in the SQL statement.
     *
     * The second parameter determines the maximum length of
     * strings used to hold the names of select-list items
     * or placeholders.  The maximum length of column
     * names in ORACLE is 30, but you can allocate more or less
     * as needed.
     *
     * The third parameter determines the maximum length of
     * strings used to hold the names of any indicator
     * variables.  To follow ORACLE standards, the maximum
     * length of these should be 30.  But, you can allocate
     * more or less as needed.
     */

    if ((bind_dp =
            SQLSQLDAAlloc(SQL_SINGLE_RCTX, size,
                   max_vname_len, max_iname_len)) == (SQLDA *) 0)
    {
        fprintf(stderr,
            "Cannot allocate memory for bind descriptor.");
        return -1;  /* Have to exit in this case. */
    }

    if ((select_dp =

        SQLSQLDAAlloc (SQL_SINGLE_RCTX, size,
                max_vname_len, max_iname_len)) == (SQLDA *) 0)
    {
        fprintf(stderr,
            "Cannot allocate memory for select descriptor.");
        return -1;

    }

[snip]
</quote>


Sent via Deja.com http://www.deja.com/
Before you buy. Received on Sun Nov 07 1999 - 23:51:47 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US