Home » Developer & Programmer » Precompilers, OCI & OCCI » Facing alot of problems, any help is greatly appreciated
Facing alot of problems, any help is greatly appreciated [message #293283] Fri, 11 January 2008 09:52 Go to next message
dinuka
Messages: 30
Registered: January 2008
Location: Sri Lanka
Member

Hi,
Im using OCCI to connect to oracle. There are a few probs im facing.

1. when i write a select statement indicating a table that is not in the database, the programme crashes with a segmentaion fault (core dump). even when if i try to insert a duplicate entry the same thing happen. cant i capture this as an error without allowing it to throw a segmentation fault? How can i avoid this ? why i want this is because i want to try an insert statement and if it fails i want to execute a update statement. i cant do it because always a segmentation fault gets thrown.

2. in a normal query you would write a timestamp as {ts 'yyy:mm:dd' }, but if i write the same in a insert statement, i get a segmentation fault again. but if i use the setSQL command and add a time stamp seperately no prob arises. is it possible to insert the time stamp in the former way?

any help is greatly appreciatesd.

Dinuka
Re: Facing alot of problems, any help is greatly appreciated [message #293293 is a reply to message #293283] Fri, 11 January 2008 11:03 Go to previous messageGo to next message
Michel Cadot
Messages: 64107
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
1. This is standard C program debugging

2. You don't write timestamp literal in this way.
See SQL Reference manual, Datetime Literals

Regards
Michel
Re: Facing alot of problems, any help is greatly appreciated [message #293308 is a reply to message #293283] Fri, 11 January 2008 11:40 Go to previous messageGo to next message
dinuka
Messages: 30
Registered: January 2008
Location: Sri Lanka
Member

I didnt get what you meant by saying standard C debugging. Could you please elaborate on this a little bit more. What am i doing wrong which is causing the program to throw a segmentation fault? Btw im doing this in C++. And thank you very much for taking the time to answer my question.

Re: Facing alot of problems, any help is greatly appreciated [message #293314 is a reply to message #293308] Fri, 11 January 2008 12:09 Go to previous messageGo to next message
Michel Cadot
Messages: 64107
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Quote:

I didnt get what you meant by saying standard C debugging

What do you do when you get a segmentation fault in a C or C++ program (even if it does not use OCCI)?
Most of the time segmentation fault is due to a wrong pointer, check all those you used or class you freed and later used or the like.

Regards
Michel
Re: Facing alot of problems, any help is greatly appreciated [message #293371 is a reply to message #293283] Fri, 11 January 2008 21:30 Go to previous messageGo to next message
dinuka
Messages: 30
Registered: January 2008
Location: Sri Lanka
Member

Following is my test code i wrote. The following table name is in the database so it works just fine. but if i put a table name that is not in the database then i get a segmentation fault. can you tell me what's wrong with the below code?


Enviroment* env = Enviroment::createEnviroment();

Connection* conn = env->createConnection(uname,pass,url);
Statement* stmt = conn->createStatement("SELECT * FROM orders"):

ResultSet* rs = stmt->executeQuery();

while(rs->next()){


int qty = rs->getInt(1);

cout << qty<<endl;

}

stmt->closeResultSet(rs);
conn->terminateStatement(stmt);
env->terminateConnection(conn);

Enviroment::terminateEnviroment(env);
Re: Facing alot of problems, any help is greatly appreciated [message #293392 is a reply to message #293371] Sat, 12 January 2008 00:53 Go to previous messageGo to next message
Michel Cadot
Messages: 64107
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
I don't use OCCI but I think rs is invalid (NULL) when the statement execution returns an error.
You have to catch exceptions.

Regards
Michel
Re: Facing alot of problems, any help is greatly appreciated [message #293399 is a reply to message #293283] Sat, 12 January 2008 03:01 Go to previous messageGo to next message
vicenzo
Messages: 28
Registered: December 2007
Location: Paris
Junior Member
Hi,

If the table does not exist, a c++ exeption should be thrown and your program must catch it.

As Michel said, with OCCI, you MUST use try/catch blocks.

Regards,

Vincent

[Edit: Remove link to a product, post it in Marketplace forum]

[Updated on: Sat, 12 January 2008 04:39]

Report message to a moderator

Re: Facing alot of problems, any help is greatly appreciated [message #293407 is a reply to message #293283] Sat, 12 January 2008 05:02 Go to previous messageGo to next message
dinuka
Messages: 30
Registered: January 2008
Location: Sri Lanka
Member

Hi,
Thanks again for all your responses. I understand that you should use try catch blocks. but the fact is from the line
ResultSet* rs = stmt->executeQuery();
a segmentation fault occurs. so i cant check anything to throw an exception. Cant i get the standard error codes displayed by sql in this situation if you ran the same query in sql plus? i was able to get error codes when i worked with the mysql C api. but with occi i just get segmentation fault. how can i first check if an sql statement i executed was successful and then proceed from there ? any small code sample of how to do this would be appreciated.

thank you

Dinuka
Re: Facing alot of problems, any help is greatly appreciated [message #293408 is a reply to message #293283] Sat, 12 January 2008 05:20 Go to previous messageGo to next message
vicenzo
Messages: 28
Registered: December 2007
Location: Paris
Junior Member
Have you checked stmt is not NULL ?

I haven't used OCCI for a while.

CreateStatement(), in my memories, should throw an exception on an invalid statement.

Maybe it doesn't and it returns a null pointer that you're trying to use....

Chechk out if stmt is not NULL or use a try/catch block

Vincent

[Updated on: Sat, 12 January 2008 05:21]

Report message to a moderator

Re: Facing alot of problems, any help is greatly appreciated [message #293433 is a reply to message #293283] Sat, 12 January 2008 11:48 Go to previous message
dinuka
Messages: 30
Registered: January 2008
Location: Sri Lanka
Member

Hi,

I did check if the stmt is NULL. But that didnt work. even tried putting it between try catch blocks. Im not really sure why it aint giving any error. just throwing segmentation fault. Im working around it at the moment by making sure that corret parameters are passed into the DB. Its jst a little bit of overhead. Thats why i wanted to find a way if i can get it to throw an exception or something of that sought. Thanks anyway everyone for taking your time to try yo help me out. I appreciate it.

Dinuka
Previous Topic: SQLCODE diffs. between Informix and Oracle
Next Topic: problem executing a procedure
Goto Forum:
  


Current Time: Mon Dec 05 04:38:01 CST 2016

Total time taken to generate the page: 0.08433 seconds