Re: C, C++ interface for Oracle

From: David Feldcamp <feldcamp_at_cs.ubc.ca>
Date: 28 Apr 1994 13:23:48 -0700
Message-ID: <2pp60k$39g_at_delphi.cs.ubc.ca>


In article <2pop8k$gun_at_zip.eecs.umich.edu>, Roland Telfeyan <telfeyan_at_eecs.umich.edu> wrote:
>Does Oracle have a C or C++ library which gives one the ability to say things
>like:
>
>int Age;
>char Name[80];
>
>connect();
>composeSQL("select name, age from people");
>execSQL();
>stringBind(Name, 1);
>intBind(Age, 2);
>while (nextRow()){
> printf("Name = %s, Age = %d\n", Name, Age);
>}
>
>I'm sure there is, but what is the library called, and where is the
>documentation located?

I don't know about any public domain code to do this. I have seen mention on the newgroup in the past of C++ versions of/wrappers for the OCI functions.

When I needed something like this I ended up writing it myself using a combination of macros and functions on top of OCI. The latest version is a bit more compact than what you describe and still uses OCI directly when the functionality is not a problem.

For example calling a stored procedure is done with:

        sql_exec("begin copy_ptype(%d, %d, '%s'); end;", src_mid, dest_mid, name);

and a query is done like

nData **db_get_ptype_data(int mid)
{

	char	*sql =
		"select name, weight, wparam, cflags, color, cconfig, "
				"(host*4 + pri*2 + antisoc), descr "
			"from ptype where (mid = %d) and (kind = 1) order by name";
			
	nData	td, **data = new_array(MAXROWS, nData*);
	int		i;
	
	clear(td);
	
	parse_sql(C0, sql, mid);
	
	db_bind_cols(C0, CHR, td.type, INT, &td.weight, 
			CHR, td.wparam, CHR, td.cflags, INT, &td.color, CHR, td.cconfig, 
			INT, &td.flags, CHR, td.desc, NULL);

	for (i=0; !ofetch(C0); i++)
		copy(&td, data[i], nData);
	
	return(realloc2(data, (i+1)*sizeof(nData*)));
}

Since the code isn't really all that complicated I would be willing to post or mail with all the standard caveats it if there is interest. Note, however, this is part of a research project in development and *not* commercial, production quality code.

David Feldcamp (feldcamp_at_cs.ubc.ca)

Parallel Computation Laboratory
Dept. of Computer Science
University of British Columbia Received on Thu Apr 28 1994 - 22:23:48 CEST

Original text of this message