Re: Dynamic Sql Method 4

From: Scott Urman <surman_at_wwsun10.us.oracle.com>
Date: 25 Jul 1994 16:54:45 GMT
Message-ID: <310qol$t6j_at_dcsun4.us.oracle.com>


In article <30pq66$4ut_at_Tut.MsState.Edu>, msbaer_at_athena.NoSubdomain.NoDomain (Michael Baer) writes:
|>
|> I am using dynamic sql method 4 to write a program that will take sql*commands from the command line. I am then embedding this file in C*shell scripts. I (like a foolish newbie) wrote over my copy of sample10.pc, the pro*c program that shows an example |> of using dynmic sql method 4. I think I understand method 4, but I cannot get my output formatted. I know the output comes out wrong because the embedded sql does not null terminate strings. I could null terminate the strings by mallocing one extra spa|> ce and putting a null character in it, or I could use sprintf("%-*.*s ", (int)select_dp->L[i],(int)select_dp->L[i], select_dp->V[i]) to print the string into another string. But both of these still treat all data as string, which includes the spaces. I |> could then use sscanf to get data out of the strings, but there is know way to tell if the string will contain an integer, one word, or multiple words seperated by blanks.
|>
|> Does anyone have a program that already does this?
|> Is there a better way to do this without using method 4?
|> Does anyone know where I can get another copy of sample10.pc?
|>
|> If you can answer any of these questions please post or email to me.
|>
|> Mike
|>
|> msbaer_at_cast.msstate.edu
|>

First of all, sample10.pc is in the Pro*C supplement. There is also quite a detailed description of dynamic method 4 there as well. Basicly, you use the results of the DESCRIBE SELECT LIST command to determine the types which will come back from the query. This will fill in the T fields of the descriptor with the internal datatypes of the select list items. You then go through the array and change this to the external datatypes - 3 for integer, 4 for floating point, etc. For a string datatype, you might want to consider using external datatype 5 (STRING). You would need to malloc an extra space in the V[i] field for the null, and then the database will null-terminate the fetched data for you. V[i] is then just a regular C string.

And if you are on a unix system, check out sample9.pc. sample9.pc (the example of calling a stored procedure) was unfortunately left out of the shipping media (this has been fixed for the 7.1 RDBMS and 1.6/2.0 Pro*C releases, by the way) and sample10 was shipped as sample9. Received on Mon Jul 25 1994 - 18:54:45 CEST

Original text of this message