Home » Developer & Programmer » Precompilers, OCI & OCCI » How to get the value of varchar 2?
How to get the value of varchar 2? [message #293467] Sun, 13 January 2008 01:41 Go to next message
dinuka
Messages: 30
Registered: January 2008
Location: Sri Lanka
Member

Hi,

im trying to retrieve a varchar2 defined column value in the following manner;

Statement *stmt;
stmt = conn->createStatement();
stmt->setSQL("select * from orders");

ResultSet * res = stmt->executeQuery();

while(res->next()){

string val = res->getString(9);// the var char is the ninth column
cout <<< val<<endl;

}

but i get a core dump when i do this. Is there any special way to access varchar2 variables in occi? Im able to retrieve other values without any probs. only the varchar2 one gives problems. Any advice is greatly appreciated.

Thanks in advance

Dinuka
Re: How to get the value of varchar 2? [message #293472 is a reply to message #293467] Sun, 13 January 2008 01:56 Go to previous messageGo to next message
Michel Cadot
Messages: 64153
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Once again, you have to use try/catch blocks.
Are you sure of your 9th column?
Try to just select this column.

Regards
Michel

Re: How to get the value of varchar 2? [message #293476 is a reply to message #293467] Sun, 13 January 2008 02:34 Go to previous messageGo to next message
dinuka
Messages: 30
Registered: January 2008
Location: Sri Lanka
Member

yea im sure. i think im getting garbage values along with it. even when i try to get a char(4) value as string, i get a core dump. can you please tell me how i can avoid this situation? for others its working fine.
Re: How to get the value of varchar 2? [message #293480 is a reply to message #293476] Sun, 13 January 2008 02:46 Go to previous messageGo to next message
Michel Cadot
Messages: 64153
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Quote:

can you please tell me how i can avoid this situation?

By coding in the correct way.

Regards
Michel
Re: How to get the value of varchar 2? [message #293481 is a reply to message #293467] Sun, 13 January 2008 03:40 Go to previous messageGo to next message
dinuka
Messages: 30
Registered: January 2008
Location: Sri Lanka
Member

Hi Michael,

Sorry if im being a pain here. its just that im not that familiar with using occi. havent faced these probs before. The core dump occurs only when i try to read in two string values and display on screen. other than that i havnt had any probs. Im using gcc 4.0. is that a prob? i think the source is built using gcc 3.4. i googled on this prob and found out that others too have had problems getting values using the getString method. some had said that you have to modify the character setting in the database as well as in the Enviroment settings. But that didnt work out for me. Any help will be much appreciated.
Re: How to get the value of varchar 2? [message #293497 is a reply to message #293481] Sun, 13 January 2008 08:49 Go to previous messageGo to next message
Michel Cadot
Messages: 64153
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Did you what I said?

Regards
Michel
Re: How to get the value of varchar 2? [message #293498 is a reply to message #293467] Sun, 13 January 2008 09:05 Go to previous messageGo to next message
dinuka
Messages: 30
Registered: January 2008
Location: Sri Lanka
Member

i did. but nothing seems to work. im on a dead line and this is stalling me. i only have the data retriving part left to do and i cant get it done because of this problem. Is there any other way i could get the string value without using the getString method? Im clueless on what i should do. please help.
Re: How to get the value of varchar 2? [message #293503 is a reply to message #293498] Sun, 13 January 2008 10:35 Go to previous messageGo to next message
Michel Cadot
Messages: 64153
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Quote:

Im clueless on what i should do.

And you will still rest without help until you copy and paste your ACTUAL code.
Make sure you read OraFAQ Forum Guide, especially "How to format your post?" section.
Make sure that lines of code do not exceed 80 characters when you format. Use the "Preview Message" button.

Regards
Michel

[Updated on: Sun, 13 January 2008 10:35]

Report message to a moderator

Re: How to get the value of varchar 2? [message #293515 is a reply to message #293467] Sun, 13 January 2008 20:46 Go to previous messageGo to next message
dinuka
Messages: 30
Registered: January 2008
Location: Sri Lanka
Member

Hi Michael,

Below i have given the code that im trying out. Please point me in the right direction on how to solve this one if possible.
Environment *env = Environment::createEnvironment();
Connection *conn = conn = env->createConnection(user, password, url);
Statement * ordstmt;
ordstmt = conn->createStatement();
ordstmt->setSQL("select * from orders where event_time=to_date(sysdate)");

ResultSet * res = ordstmt->executeQuery();

while(rest->next){

//second, third. and fourth lines, it works fine. else i get a double free or corruption (!prev): 0x080b6600 error.

string comments = res->getString(9);//this is a varchar2 column
Timestamp t = res->getTimestamp(14);//this is a timestamp filed
string tstamp = t.toText("yyyy-mm-dd hh:mi:ss ",0);

string g = res->getString(10); // this is a char(1) value


}


ordstmt->closeResultSet(res);


please help.

thank you

Dinuka
Re: How to get the value of varchar 2? [message #293524 is a reply to message #293467] Sun, 13 January 2008 22:31 Go to previous messageGo to next message
dinuka
Messages: 30
Registered: January 2008
Location: Sri Lanka
Member

After working through, i found out that this only happens when you call the call the getString method twice. The character encoding of the databse is US7ASCII. Is this a problem? and i think the national character encoding is OCCIUTF16. c++ only supports utf-8 yea? Could this be the problem? If so how can i correct this?
Re: How to get the value of varchar 2? [message #293560 is a reply to message #293467] Mon, 14 January 2008 02:03 Go to previous messageGo to next message
vicenzo
Messages: 28
Registered: December 2007
Location: Paris
Junior Member
Have you tried the second getString() without the 2 following lines ?

Timestamp t = res->getTimestamp(14);//this is a timestamp filed
string tstamp = t.toText("yyyy-mm-dd hh:mi:ss ",0);

Is is working with just the 2 getString() ?

string comments = res->getString(9);//this is a varchar2 column
string g = res->getString(10); // this is a char(1) value

If you specify OCCI_STD_NAMESPACE::string is it working better ?

OCCI_STD_NAMESPACE::string comments = res->getString(9);
OCCI_STD_NAMESPACE::string g = res->getString(10);
Re: How to get the value of varchar 2? [message #293571 is a reply to message #293467] Mon, 14 January 2008 02:31 Go to previous messageGo to next message
dinuka
Messages: 30
Registered: January 2008
Location: Sri Lanka
Member

Hi,

No its not working either way. Getting a "munmap_chunk(): invalid pointer: 0x080c69f8 ***" error when i tried with the second way you had said. I have defined the Environment as Default. Do you have to set it to some other value? I can only retrieve one string value. if i try to use it for the second time, i get an error.
Re: How to get the value of varchar 2? [message #293573 is a reply to message #293467] Mon, 14 January 2008 02:32 Go to previous messageGo to next message
dinuka
Messages: 30
Registered: January 2008
Location: Sri Lanka
Member

btw it is printing the appropriate values and then only throw that error.
Re: How to get the value of varchar 2? [message #293575 is a reply to message #293467] Mon, 14 January 2008 02:39 Go to previous messageGo to next message
vicenzo
Messages: 28
Registered: December 2007
Location: Paris
Junior Member
so, post the code where it prints the value and crahes....
Re: How to get the value of varchar 2? [message #293665 is a reply to message #293467] Mon, 14 January 2008 08:26 Go to previous messageGo to next message
dinuka
Messages: 30
Registered: January 2008
Location: Sri Lanka
Member

the code above does it. if you commented out the timestamp related lines

Re: How to get the value of varchar 2? [message #294650 is a reply to message #293467] Fri, 18 January 2008 05:28 Go to previous messageGo to next message
dinuka
Messages: 30
Registered: January 2008
Location: Sri Lanka
Member

Hi guys,

i found the solution. Was going to post it earlier, but was too much drowned with work. You can make occi work with g++4.1.x . You just need to download the latest patch which can be found at http://www.oracle.com/technology/tech/oci/occi/occidownloads.html... copy that into the oracle client lib director and the getString problem wont be there.

Hope this helps
Re: How to get the value of varchar 2? [message #294673 is a reply to message #294650] Fri, 18 January 2008 07:05 Go to previous message
Michel Cadot
Messages: 64153
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Thanks for the feedback.

Regards
Michel
Previous Topic: tracing performance of a pro*C code
Next Topic: proc*c in windows xp
Goto Forum:
  


Current Time: Sun Dec 11 04:40:02 CST 2016

Total time taken to generate the page: 0.10529 seconds