Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Re: C++ or C sample for OCI wanted
Just a note of caution on this method below. NO CHECKING is done on the validity of the date when you bind it for input. From the oci manual:
<quote>
When you input a date in binary format using the DATE external
datatype, the database does not do consistency or range checking. All
data in this format must be carefully validated before input.
Note: There is little need to use the Oracle external DATE
datatype in ordinary database operations. It is much more
convenient to convert DATEs in character format, because the
program usually displays (on a query) or inputs in a character
format, such as ‘DD–MON–YY’.
</quote>
In short, you can input total garbage into a date field using the method below. I recommend using CHARACTER strings and to_date() for all input/output operations on dates to prevent errors.
On Fri, 24 Oct 1997 15:25:01 -0400, "edwards@"@garland.dnr.state.sc.us wrote:
>Uwe Hildebrandt wrote:
>>
>> I started programming with C++ with OCI (on Windows NT and VC++ 5.0)
>> and I fight with the DATE type. I am not able to store data with the
>> obndnr C-function with the DATE type.
>>
>> Uwe
>
>Well, I dont know anything about VC++ or windows, but heres how I store
>DATE type data
>in ASNI C
>
>* Oracle stores dates in a 7 byte format
>which is easier to manipulate in a union
>
>typedef union _oradate{
> char oracle[7];
> struct _date date;
>};
>
>typedef struct _date{
> unsigned char century;
> unsigned char year;
> unsigned char month;
> unsigned char day;
> unsigned char hour;
> unsigned char minute;
> unsigned char second;
>};
>
>
>*So if you wanted to store a date of October 24,1997 21:00:00
>you would do this:
>
>oradate.date.century = 100+19 // you have to add 100
>oradate.date.year = 100+97; // you have to add 100
>oradate.date.month = 10;
>oradate.date.day = 24;
>oradate.date.hour = 1+21; // you have to add 1
>oradate.date.minute = 1+0; // you have to add 1
>oradate.date.second=1+0; // you have to add 1
>
>obndrv(&cda,(text *) ":OBSERVE_DATE",(sword) -1,(ub1 *)oradate->oracle,
> (sword)7,(sword) SQLT_DAT,(sword) -1,&indp,(text *) NULL,
> (sword) -1,(sword) -1));
>
>// SQLT_DAT is defined in 'ocidfn.h' as 12
>
>
>Hope this helps
>
>-Steve Edwards
>-SCDNR
Thomas Kyte
tkyte_at_us.oracle.com
Oracle Government
Bethesda MD
http://govt.us.oracle.com/ -- downloadable utilities
NOTICE: In order to cut down on the amount of time I spend applying silly logic to email addresses like "In order to cut down on spam, remove THIS from my email" or "In order to cut down on spam, reverse my email address", etc, I will simply hit delete when that mail bounces back to me, which is what I do with spam myself.
I haven't figured out whats more time consuming for me, deleting spam or resending emails after re-reading the whole thing to figure out the algorithm to apply. Received on Fri Oct 24 1997 - 00:00:00 CDT
![]() |
![]() |