Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.tools -> Re: How do I use Oracle from a UNIX C++ program (Pro C, OCI, etc)?
"Toby T." wrote:
>
> If you have the Oracle 7 Server SQL Reference book, look on page
> 4-147. Or look up in the V8 reference and look for the CONNECT
> clause. This should get you started. You need to do something
> like the following to connect
> to the db using Pro*C:
> EXEC SQL BEGIN DECLARE SECTION;
> varchar vUsername[NAME_LEN];
> varchar vPassword[NAME_LEN];
> varchar vDBname[NAME_LEN];
> EXEC SQL END DECLARE SECTION;
>
> // Set the character arrays to the username, password and db
> // i.e.
> strcpy(vUsername.arr,'scott');
> strcpy(vPassword.arr,'tiger');
> strcpy(vDBname.arr,'testdb');
> // then set the .len of each to the length of each array.
> vUsername.len = strlen((char *)vUsername.arr);
> vPassword.len ......
> vDBname.len .......
Why does everyone miss this? It seems that it is common to to the strcpy()/strlen() sequence. There is an easier way:
vUsername.len = snprintf((char *) vUsername.arr,sizeof(vUsername.arr) - 1,"%s","scott");
Not only does this get the job done with a single statement - it also ensures that there is never a buffer overrun. Received on Fri Apr 28 2000 - 00:00:00 CDT
![]() |
![]() |