Home » Developer & Programmer » Precompilers, OCI & OCCI » segmentation fault from vector
segmentation fault from vector [message #194037] Wed, 20 September 2006 09:01
kjaka
Messages: 2
Registered: September 2006
Junior Member
#include <iostream>
#include <string>

#include <occi.h>

using namespace std;
using namespace oracle::occi;

int main()
{

Environment* env;
Connection* conn;
Statement *stmt;
ResultSet *rs;
vector<MetaData> vMD;

// cout << "starting..." << endl;

try
{
// cout << "creating env..." << endl;
//initialize in object mode since we are accessing VARRAY types
env = Environment::createEnvironment(Environment::OBJECT);

// cout << "creating conn..." << endl;
conn = env->createConnection("iris","tpstps", "iris9i");
// cout << "connection established" << endl;

// cout << "creating statement" << endl;
stmt = conn->createStatement();

// cout << "Statement text....." << endl;
stmt->setSQL("begin :1 := PKGNETWORK.spGetNetworkInfoByIP(:2, :3); end;");

// cout << "setting parameter 1" << endl;
stmt->registerOutParam(1, OCCIINT);
stmt->setString(2,"192.168.6.21");
stmt->setMaxParamSize(2,20);

// cout << "Cursor parameter" << endl;
stmt->registerOutParam(3,OCCICURSOR);

cout << "executing" << endl;
Statement::Status status = stmt->execute();

/* if (status != Statement::RESULT_SET_AVAILABLE) {
cout << "phadda - status: " << status << endl;
cout << "NEEDS_STREAM_DATA: " << Statement::NEEDS_STREAM_DATA << endl;
cout << "PREPARED: " << Statement::PREPARED << endl;
cout << "RESULT_SET_AVAILABLE: " << Statement::RESULT_SET_AVAILABLE << endl;
cout << "STREAM_DATA_AVAILABLE: " << Statement::STREAM_DATA_AVAILABLE << endl;
cout << "UNPREPARED : " << Statement::UNPREPARED << endl;
cout << "UPDATE_COUNT_AVAILABLE : " << Statement::UPDATE_COUNT_AVAILABLE << endl;
}*/

// cout << "executed ......" << endl;
int retVal = stmt->getInt(1);
cout << "Searched using keyword: " << stmt->getString(2) << endl;
cout << "return val: " << retVal << endl;
rs = stmt->getCursor(3);//use ResultSet to fetch rows
vMD = rs->getColumnListMetaData();
cout << "Attribute count : " << vMD[0].getAttributeCount() << endl;
int dataType=vMD[0].getInt(MetaData::ATTR_DATA_TYPE);
cout << "Attribute type : " << dataType << endl;
cout << "Attribute name : " << vMD[22].getString(MetaData::ATTR_NAME)<< endl;
cout << "Size : " << vMD.size() << endl;

cout << "loop staring.." << endl;
//we know cursor has 1 varchar column in Select, use getString()
while (rs->next())
{
cout << "next row";
cout << "NetID : " << rs->getString(3).c_str() << endl;
// cout << "column size : " << rs->getStream(1)* << endl;
}

cout << "closing result set" << endl;

// stmt->closeResultSet(rs);

cout << "terminating stmt" << endl;
conn->terminateStatement(stmt);

cout << "terminating conn..." << endl;
env->terminateConnection(conn);

cout << "terminating env..." << endl;
Environment::terminateEnvironment(env);

// vMD.clear();
cout << "Demo completed" << endl;
}
catch (SQLException &ex)
{//cleanup
cout << "Error, cleaning up..." << ex.getMessage() << endl;
//conn->terminateStatement(stmt);
// env->terminateConnection(conn);
cout << "terminating env" << endl;
//Environment::terminateEnvironment(env);
// throw;//will be caught by outer handler
}

cout << "exit" << endl;



return 0;
}
getting a segmentation fault at the end of the program till the cout of exit; every thing is running fine

platform
redhat AS 4
GCC 3.4.4
OCCI lib for gCC 3.4.3
oracle 10.2.0.1
Previous Topic: Pro C Data Type ISSUE !!!!!!!
Next Topic: How to unbind the definition by OCIDefineByPos?
Goto Forum:
  


Current Time: Fri Dec 09 05:37:02 CST 2016

Total time taken to generate the page: 0.16359 seconds