I'm try to use Oracle Object in ODAC. I'using 5.80.0.35 trial version for Builder 6.
I'm checking if I can use oracle object feature.
I have code like this:
pWWWIp->CreateObject(_q->Session->OCISvcCtx, "RISORSATYPE");
pAllegatiIp = dynamic_cast(pWWWIp->AttrAsObject["lista_allegati"]);
if (pAllegatiIp->AttrIsNull["lista_allegati"])
pAllegatiIp->CreateObject(_q>Session>OCISvcCtx, "TAB_OF_ALLEGATI");
Where RISORSATYPE have an attribute of type Table Of AllegatoType (TAB_OF_ALLEGATI).
whil (something true)
{
pElementoAllegatoIp = new TOraObject(NULL);
pElementoAllegatoIp->CreateObject(_q->Session->OCISvcCtx, "ALLEGATOTYPE");
pElementoAllegatoIp->AttrAsInteger["id_allegato"] = 0;
pElementoAllegatoIp->AttrAsString["path_file_allegato"] = (*begit).path_file_allegato;
indexItem = pAllegatiIp->AppendItem();
pAllegatiIp->ItemAsObject[indexItem] = pElementoAllegatoIp;
}
While exeuting "indexItem = pAllegatiIp->AppendItem();" at third step,
but sometime at first step, an access violation arises.
Could you tell me why?
Other ODAC Oracle Object features works ok.
thanks in advance
Francesco L.
AppendItem in TOraNestTable (TOraArray) fails!!!
-
francescolenardon
- Posts: 8
- Joined: Mon 04 Sep 2006 13:56
You should not use the AppendItem function to add new elements to nested table. Element is automatically added when you assign a value to the ItemAsObject[Index] property and an element with such index does not exist yet.
We have fixed the problem with the AppendItem function. The fix will be included in the next build of ODAC.
We have fixed the problem with the AppendItem function. The fix will be included in the next build of ODAC.
-
francescolenardon
- Posts: 8
- Joined: Mon 04 Sep 2006 13:56
I'm agree with you, but in code and scripts I sent to crlab support team, via email, and that I'm sending you again, I described more in detailed the problem. It's like we can't extend nested table, like there was a limit in extending nested table.
Not only while executing p1->AppendItem() about at 25th step the statement fails BUT ALSO while executing
p1->ItemAsObject[iLength + 1] = tempObject.
The code is below.
int main(int argc, char* argv[])
{
TOraSession* conCora9;
TOraSQL* querySP1;
//lettura dati
if (argc > 1)
{
if (AnsiString(argv[1]) == AnsiString("TabelleODAC"))
{
int iLength = 0;
TOraNestTable* p1;
TOraNestTable* p2;
conCora9 = new TOraSession(NULL);
conCora9->Username = "username";
conCora9->Password = "pwd";
conCora9->Server = "xe";
conCora9->HomeName = "XE";
conCora9->Connect();
p1 = new TOraNestTable(NULL);
p1->CreateObject(conCora9->OCISvcCtx, "TAB_OF_INTERCEPT");
for (iLength = 0; iLength CreateObject(conCora9->OCISvcCtx, "REC_OF_INTERCEPT");
tempObj->AttrAsInteger["id_bersaglio"] = 100;
tempObj->AttrAsInteger["progressivo"] = iLength + 1;
p1->ItemAsObject[iLength + 1] = tempObj;
//p1->AppendItem();
}
p2 = new TOraNestTable(NULL);
p2->CreateObject(conCora9->OCISvcCtx, "TAB_OF_INTERCEPT");
querySP1 = new TOraSQL(NULL);
querySP1->Connection = conCora9;
querySP1->SQL->Add("begin");
querySP1->SQL->Add("pkg_provearray.provepassaggio(:p1, :p2);");
querySP1->SQL->Add("end;");
querySP1->ParamByName("p1")->AsTable = p1;
querySP1->ParamByName("p2")->AsTable = p2;
querySP1->Execute();
int z = querySP1->ParamByName("p2")->AsTable->Size;
for (int k = 0; k ParamByName("p2")->AsTable->ItemAsObject[k]->AttrAsInteger["id_bersaglio"] ParamByName("p2")->AsTable->ItemAsObject[k]->AttrAsInteger["progressivo"] << std::endl;
}
}
}
}
Below there the scripts to create environment in database:
CREATE OR REPLACE
type rec_of_intercept as object
(
id_bersaglio integer,
progressivo integer
) not final;
/
CREATE OR REPLACE
type tab_of_intercept as table of rec_of_intercept;
/
CREATE OR REPLACE package pkg_provearray is
procedure provepassaggio(p1 in tab_of_intercept, p2 in out tab_of_intercept);
end pkg_provearray;
/
CREATE OR REPLACE package body pkg_provearray is
procedure provepassaggio(p1 in tab_of_intercept, p2 in out tab_of_intercept) is
begin
p2 := p1;
end;
end pkg_provearray;
/
Not only while executing p1->AppendItem() about at 25th step the statement fails BUT ALSO while executing
p1->ItemAsObject[iLength + 1] = tempObject.
The code is below.
int main(int argc, char* argv[])
{
TOraSession* conCora9;
TOraSQL* querySP1;
//lettura dati
if (argc > 1)
{
if (AnsiString(argv[1]) == AnsiString("TabelleODAC"))
{
int iLength = 0;
TOraNestTable* p1;
TOraNestTable* p2;
conCora9 = new TOraSession(NULL);
conCora9->Username = "username";
conCora9->Password = "pwd";
conCora9->Server = "xe";
conCora9->HomeName = "XE";
conCora9->Connect();
p1 = new TOraNestTable(NULL);
p1->CreateObject(conCora9->OCISvcCtx, "TAB_OF_INTERCEPT");
for (iLength = 0; iLength CreateObject(conCora9->OCISvcCtx, "REC_OF_INTERCEPT");
tempObj->AttrAsInteger["id_bersaglio"] = 100;
tempObj->AttrAsInteger["progressivo"] = iLength + 1;
p1->ItemAsObject[iLength + 1] = tempObj;
//p1->AppendItem();
}
p2 = new TOraNestTable(NULL);
p2->CreateObject(conCora9->OCISvcCtx, "TAB_OF_INTERCEPT");
querySP1 = new TOraSQL(NULL);
querySP1->Connection = conCora9;
querySP1->SQL->Add("begin");
querySP1->SQL->Add("pkg_provearray.provepassaggio(:p1, :p2);");
querySP1->SQL->Add("end;");
querySP1->ParamByName("p1")->AsTable = p1;
querySP1->ParamByName("p2")->AsTable = p2;
querySP1->Execute();
int z = querySP1->ParamByName("p2")->AsTable->Size;
for (int k = 0; k ParamByName("p2")->AsTable->ItemAsObject[k]->AttrAsInteger["id_bersaglio"] ParamByName("p2")->AsTable->ItemAsObject[k]->AttrAsInteger["progressivo"] << std::endl;
}
}
}
}
Below there the scripts to create environment in database:
CREATE OR REPLACE
type rec_of_intercept as object
(
id_bersaglio integer,
progressivo integer
) not final;
/
CREATE OR REPLACE
type tab_of_intercept as table of rec_of_intercept;
/
CREATE OR REPLACE package pkg_provearray is
procedure provepassaggio(p1 in tab_of_intercept, p2 in out tab_of_intercept);
end pkg_provearray;
/
CREATE OR REPLACE package body pkg_provearray is
procedure provepassaggio(p1 in tab_of_intercept, p2 in out tab_of_intercept) is
begin
p2 := p1;
end;
end pkg_provearray;
/