Subject Re: [ib-support] API XSQLVAR struct ?
Author William L. Thomson Jr.
Raul,

On Tue, 2002-07-23 at 20:33, Raul Chirea wrote:
> Hi William,
>
> ""William L. Thomson Jr."" <support@...> wrote in message
>
> > Ok, let me see if I can make my question easier.
> > What type of var array should I create so I can get the output out of
> >
> > osqlda->sqlvar[i].sqldata = // <- Here
>
> It depends of "osqlda->sqlvar[i].sqltype" you use for that field.
> "osqlda->sqlvar[i].sqldata" is JUST A POINTER to a memory area in which
> server expects/places parameter/field data. For example if you bind, let's
> say, a double field you should do like this:
>
> double dblval;
> ...
> osqlda->sqlvar[i].sqltype = SQL_DOUBLE;
> osqlda->sqlvar[i].sqldata = (char *)malloc(sizeof(double));
> ...
> /* and after a fetch you can read the fetched value from that location */
>
> dblval = *((double *)(osqlda->sqlvar[i].sqldata));
>
> /* after that the "dblval" variable should contain the value of that field
> */

Above is what I was looking for. I figured I would have to use different
data type, and will do a switch case later to populate different types
of data, or data arrays.

I was just having problems due to the examples and going from there. The
above should help out allot.

> > It says it is a char * and returns the location of the data.
>
> Yes but in this case "char *" means just a pointer. Mabe it would be better
> to be "void *" !

That may have helped me to better understand how to use it. But as you
can see I have other problems due to me still learning C/C++. I willl
get there.

> > But if I pass a char * var to it I have problems. Now I have swapped to
> > SQL_TEXT instead of SQL_VARYING. But I will have to later on create an
> > switch case statement to retrieve the different types of data. Or is
> > that even needed, since any number can become a char */[], and I can
> > cast it back to a number from there?
>
> Yes, the server+API tries to cast the data as you request and if it can't
> returns an error.

I mostly got segmentation faults, but I get the point.

As always, thanks allot. I do appreciate your help.

--
Sincerely,
William L. Thomson Jr.
Support Group
Obsidian-Studios Inc.
439 Amber Way
Petaluma, Ca. 94952
Phone 707.766.9509
Fax 707.766.8989
http://www.obsidian-studios.com