Hi all
For past three days am trying to figure out the cause of error. I am using
shared_array, allocating it memory equal to size of data am populating it
with and then storing the data in the "shared_array". but when shared_ptr
goes out of scope and is internally deallocated, error is thrown....
I am populating my shared_array type data with data fetched from
database....
here's part of my code
*******************************************************************************************************************************************************************************
// ***********Main function***************
#include
#include
#include <iostream>
#include
#include "RtShDataDao.hpp" //My own class with function
declarations including rtGetRepositoryData(RtRepositoryDataVo &
r_repositoryData,const RtU32T id,const RtU32T aliasOrPublic, const RtC8T *
p_serviceIndication)
//RtU32T is unsigned int of size 32 bytes, RtC8t is
Signed Char
#include <string>
#include <exception>
using namespace std;
using namespace oracle::occi;
int main()
{
void get_RepositoryData();
get_RepositoryData();
}
void get_RepositoryData()
{
RtShDataDao shDataDaoObj;
RtU32T id = 8;
RtU32T aliasOrPublic = 1;
RtRepositoryDataVo repositoryData;// = new RtRepositoryDataVo(); //
RtRepositoryDataVo is class containing variables m_seq and mp_data
repositoryData.m_seq = 0;
RtC8T serviceIndication[50] = "service indication 8";
printf("\nAddress in shared ptr is %p\n",repositoryData.mp_data.get());
try
{
shDataDaoObj.rtGetRepositoryData(repositoryData,id,aliasOrPublic,serviceIndication);
}
catch (RtExceptionUD &eud)
{
cout<<"Error---------------------"<
#include "RtExceptionUD.hpp"
#include <iostream>
using namespace std;
using namespace oracle::occi;
extern StatelessConnectionPool *g_scp;
#include "RtShDataDao.hpp"
void RtShDataDao::rtGetRepositoryData(RtRepositoryDataVo &
r_repositoryData,const RtU32T id,const RtU32T aliasOrPublic, const RtC8T *
p_serviceIndication) throw (RtExceptionUD &, exception &,SQLException &)
{
if(p_serviceIndication == NULL)
{
throw RtExceptionUD(" p_serviceIndication initialized with NULL");
}
if( aliasOrPublic < 0 )
{
throw RtExceptionUD(" aliasOrPublic initialized with unexpected
value ");
}
if( id <= 0 )
{
throw RtExceptionUD(" id initialized with unexpected value ");
}
Connection *l_conn = g_scp->getConnection();
Statement *l_stmt = l_conn->createStatement();
ResultSet * l_rs;
int l_countRow = 0;
ub2 rc = 0, rc1 = 0;
sb2 ind = 0, ind1 = 0;
switch (aliasOrPublic)
{
case 0:
{
Clob l_repData;
l_stmt->setSQL(GET_REPOSITORY_DATA_PUBLIC);
ub2 l_lenInt = sizeof(int);
l_stmt->setDataBuffer(1,(void *)&id,OCCIINT,l_lenInt,&l_lenInt);
ub2 l_lenString = strlen (p_serviceIndication)+1;
l_stmt->setDataBuffer(2,(dvoid
*)p_serviceIndication,OCCI_SQLT_STR, l_lenString, &l_lenString);
l_rs = l_stmt->executeQuery();
l_rs->setDataBuffer(1,(void
*)&r_repositoryData.m_seq,OCCIINT,l_lenInt,&l_lenInt, &ind, &rc);
ub2 l_lenClob;
l_repData.setEmpty(l_conn);
l_rs->setDataBuffer(2,&l_repData,OCCI_SQLT_CLOB, l_lenClob,
&l_lenClob, &ind1, &rc1);
while (l_rs->next())
{
if(!ind1)
{
unsigned int l_offset = 1;
r_repositoryData.mp_data = RtSpChar (new
RtU8T(l_repData.length()+1));
l_repData.read(l_repData.length(),(unsigned
char*)(r_repositoryData.mp_data.get()),l_repData.length(),l_offset);
r_repositoryData.mp_data[l_repData.length()] = '\0';
printf("address of the mp_data %p
/n",r_repositoryData.mp_data.get());
getchar();
}
++l_countRow;
}
break;
}
case 1:
{
Clob l_repData;
l_stmt->setSQL(GET_REPOSITORY_DATA_ALIAS);
ub2 l_lenInt = sizeof(int);
l_stmt->setDataBuffer(1,(void *)&id,OCCIINT,l_lenInt,&l_lenInt);
ub2 l_lenString = strlen (p_serviceIndication)+1;
l_stmt->setDataBuffer(2,(dvoid
*)p_serviceIndication,OCCI_SQLT_STR, l_lenString, &l_lenString);
l_rs = l_stmt->executeQuery();
l_rs->setDataBuffer(1,(void
*)&r_repositoryData.m_seq,OCCIINT,l_lenInt,&l_lenInt, &ind, &rc);
ub2 l_lenClob;
l_repData.setEmpty(l_conn);
l_rs->setDataBuffer(2,&l_repData,OCCI_SQLT_CLOB, l_lenClob,
&l_lenClob, &ind1, &rc1);
while (l_rs->next())
{
if(!ind1)
{
unsigned int l_offset = 1;
r_repositoryData.mp_data = RtSpChar (new
RtU8T(l_repData.length()+1));
l_repData.read(l_repData.length(),(unsigned
char*)(r_repositoryData.mp_data.get()),l_repData.length(),l_offset);
r_repositoryData.mp_data[l_repData.length()] = '\0';
printf("address of the mp_data %p
/n",r_repositoryData.mp_data.get());
getchar();
}
// unsigned int l_offset = 1;
// r_repositoryData.mp_data = RtSpChar(new
RtU8T(l_repData.length()));
// l_repData.read(l_repData.length(),(unsigned char
*)r_repositoryData.mp_data.get(),l_repData.length(),l_offset);
++l_countRow;
}
break;
}
}
l_stmt->closeResultSet(l_rs);
l_conn->terminateStatement(l_stmt);
g_scp->releaseConnection(l_conn);
if(l_countRow == 0)
throw RtExceptionUD("RtShDataDao::getRepositoryData::No data fetched
....");
}
// This class contains definitions for variable m_seq and mp_data
#ifndef _RTREPOSITORYDATAVO_H
#define _RTREPOSITORYDATAVO_H
#include "RtDataType.h"
#include "RtShared_ptr.hpp"
using namespace boost;
// This class is a value object that shall have the repository data
corresponding to the public identity id or alias grp id.
class RtRepositoryDataVo {
public:
// It is identity used for a set of service related transparent data.
RtC8T mp_serviceInd[30];
// The seqn is the sequence number which is used in order to maintain a
uniformity in data shared AS and HSS.
RtU32T m_seq;
// The data is the transparent data.
RtSpChar mp_data;
//shared_ptr<RtU8T> mp_data;
// ~RtRepositoryDataVo(){cout<<"Destruc Use count is
"<