ocidate from external proc and AV?

koadam

Member²
Hi, we have doa 3.4.6.1.

We try to write external funcions for oracle 8.1.7.

My delphi func header looks like:
function TEST(Context: Pointer; dLo, dHi: TOciDate; i: integer): integer; cdecl;

I try to convert ocidate to delphi datetime with:

Session.ExtProcShare(Context);
d:=Session.OCIDateToDateTime(dLo);

The soecond line gives an AV. I guess there is something with the ocidate pointer type.

Please let me know what i am doing wrong.

Thanks in advance,
B.
 
Hi,
thanks for your answer.

The code snippets from the est dll code is:

Code:
var
  Func1Result: TOCINumber = nil;

function XXX_TEST2(Context: Pointer; ADateLo, ADateHi: TOciDate; ACards: PChar; AIntParam: TOciNumber): PChar; cdecl;
var
  dLo, dHi: TDateTime;
  i: integer;
begin
  Result:=nil;

  with DataModule do
  try
    DataModule.Session.ExtProcShare(Context);

    OutputDebugString('[ >>1 ]');
    If Func1Result = nil then Func1Result := Session.OCINumberCreate();
    Result:=Func1Result;
    OutputDebugString('[ >>2 ]');
    i:=Session.OCINumberToInt(AIntParam);
    //Session.OCINumberFromInt(Result, Session.OCINumberToInt(Result)+7);

    OutputDebugString('[ >>3 ]');
    dLo:=Session.OCIDateToDateTime(ADateLo);
    dHi:=Session.OCIDateToDateTime(ADateHi);

    OutputDebugString('[ >>4 ]');
    Result:=StrNew('test');
  except
    on E: EOracleError do DataModule.Session.ExtProcRaise(E.ErrorCode, E.Message);
    on E: Exception do DataModule.Session.ExtProcRaise(20000, 'Fatal error'+E.Message);
  end;

  OutputDebugString('[ >>5 ]');
end;
The oracle function looks like this:

Code:
create or replace library project1 as 'project1.dll'

CREATE OR REPLACE FUNCTION TestFunc2(dLo IN date, dHi IN date,                                   sCards IN varchar, I IN BINARY_INTEGER)
RETURN number AS LANGUAGE C NAME "XXX_TEST2" LIBRARY PROJECT1
WITH CONTEXT ;
select testfunc2(:dlo, :dhi, :s1, 12) as x from dual

gives an AV error on calls to session.ocinumberto...
and session.ocidateto...

Thanks,
B.
 
I notice 2 mismatches between the PL/SQL external function and the Delphi function:

1. The return type of the PL/SQL function is a number, whereas the return type of the Delphi function is a PChar.

2. The PL/SQL binary_integer parameter maps to a Delphi Integer by default, no to a TOCINumber.
 
ok, that was my mistake when I prepared the sample codes.
Correcting the mistakes, the ocidatefrom... still does not work. DOA 3.4.6 is ok for this feature?
B.
 
Can you show me the actual definitions? You can also send me a little test project, including the SQL to create the library and the function.
 
Hi,
I tried it with latest doa version, and it gives the same results (AV).
If I change type "tocidate" to "TDatetime" gives also errors (parameter stack overflow, or something like this).

Please help me to get this thing to work.
Thanks in advance,
Koadam
 
Your demo project includes references to a data module and other units that I do not have. Did you receive my request to send me a complete demo?
 
ok, i sent it again a few days before.
Did you receive it? What mail address should I use?

I sent to address "support@"

K.
 
I modified your demo project as follows and it works okay now:
Code:
library test01;
//
uses
  SysUtils,
  Classes,
  Oracle,
  Windows,
  udmdb in 'udmdb.pas' {dmDb: TDataModule};
//
{$R *.res}
//
var
  SaveExit: Pointer;              // The saved exit procedure
  DataModule: TdmDb = nil;        // The data module with a session and a query
  s: string;                      // Global string variable to hold return values
//
function XXX_TEST(Context: Pointer; ADateLo, ADateHi: TOCIDate; ACards: PChar): PChar; cdecl; var
  dLo, dHi: TDateTime;
begin
  Result:=nil;
  with DataModule do
  try
    DataModule.Session.ExtProcShare(Context);
    dLo := Session.OCIDateToDateTime(ADateLo);
    dHi := Session.OCIDateToDateTime(ADateHi);
    s := DateTimeToStr(dLo) + '...' + DateTimeToStr(dHi) + ' ';
    Result := PChar(s);
  except
    on E: EOracleError do DataModule.Session.ExtProcRaise(E.ErrorCode, E.Message);
    on E: Exception do DataModule.Session.ExtProcRaise(20000, 'Fatal error'+E.Message);
  end;
end;
//
// Free all preserved resources when the DLL is unloaded procedure LibExit; begin
  DataModule.Free;
  // Restore the exit procedure
  ExitProc := SaveExit;
end;
//
exports
  XXX_TEST name 'XXX_TEST'
  ;
//
begin
  DataModule := TdmDb.Create(nil);
  // Save and override the exit procedure
  SaveExit := ExitProc;
  ExitProc := @LibExit;
end.
I hope this helps.
 
Hi!

No, it doesn't work.
The error is the same: "invalid argument to date encode".
I think this is somehow connected with the OCI api, and
maybe the server's/client's nls settings.
My computer is configured in windows as "hungarian region".
My oracle's nls_lang is "AMERICAN_AMERICA.EE8MSWIN1250".
My oracle server and client version is 8.1.7.

What settings do you use when you got the demo project working?
Maybe do you use internally any date formatting strings in the OCI calls?

Koadam
 
Back
Top