How to fetch array of strings in Pro*C?

From: Steve Tolkin <tolkin_at_ksr.com>
Date: 2 Jun 1994 15:52:17 GMT
Message-ID: <2skv7h$1cb_at_hopscotch.ksr.com>


Background: I am writing a Pro*C program that ought to be straightforward, but I am not sure the best way to go about it. The database table has two columns called name and value; both are of type varchar2. I want to fetch them into my Pro*C program, in order to build a kind of lookup table.
My basic goal is to have each of these be an array of plain old C strings. I believe I want to use array fetch, for performance reasons.
I need to have no trailing blanks. I am running Oracle 7.0.13.

I believe I want to use Pro*C data type varchar. It seems I must myself insert the null terminator in the C string. (I could use Pro*c data type char, but then I would need to scan the string backwards, replacing each trailing blank with a null byte.)

My questions:
1. How do I determine in advance the number of rows I will fetch? If I do a select count(*) first I am worried that the table might be changed change between that query and the one I am fetching from. Should I be prepared to malloc and realloc after fetching each batch.

2. Is there any standard way to create an array of char * from the array of varchar? This includes putting the null terminator in, and copying the address to the array.

I would approeciate seeing some existing code that does this. Neither the manual nor the demo/sample* programs ever use varchar with array fetch.

Thanks in advance
-- Steven Tolkin tolkin_at_ksr.com (617) 895-3540

  • Kendall Square Research 170 Tracer Lane Waltham MA 02154
  • A motto for anyone who works with binary encoded data:
  • "Double, double -- toil and trouble". (Any opinions are mine.)
--

-- Steven Tolkin tolkin_at_ksr.com (617) 895-3540
-- Kendall Square Research 170 Tracer Lane Waltham MA 02154
-- A motto for anyone who works with binary encoded data:
-- "Double, double -- toil and trouble". (Any opinions are mine.)
Received on Thu Jun 02 1994 - 17:52:17 CEST

Original text of this message