View previous topic :: View next topic |
Author |
Message |
Rama_Prayaga Beginner

Joined: 20 May 2003 Posts: 45 Topics: 15
|
Posted: Wed Feb 23, 2005 8:19 am Post subject: Sqlcode error -803 while insert |
|
|
Hello,
I have unique Index in a table, build in set of 7 coulumns.Primary key is not the part of the this unique index.
I have to insert a new row.
The the following is the steps I follow.
Code: | 1) read the table.if sqlcode is 0 then fetch the row.
2) if sqlcode is 100 , then insert a new row. |
But while insert I am facing a problem.There is also another similer online program which insert the rows in the same table.So I am getting Sqlcode of -803.
So I have to make the changes to my program such that
Code: | ---> i want to check whether -803 is caused because of duplicate Unique index or duplicate key.How can I check that.
---> if it is because of duplicate primary key then I will create a new key.
---> if the error is because of Duplication of unique index then I will read the table. |
kindly ,Please let me know how to proceed further
Regards,
Rama Krishna Prayaga |
|
Back to top |
|
 |
SureshKumar Intermediate
Joined: 23 Jan 2003 Posts: 211 Topics: 21
|
Posted: Wed Feb 23, 2005 8:40 am Post subject: |
|
|
Rama_Prayaga,
Why would you have two sets of 'Unique' index ? A table is normally associated with only one unique index 7 that may or may not be a primary key. A primary key in itself is unique. Though things can be manipulated technically, I would suggest a second look at the table structure - all index(s) and how they are defined. If still needed, check the SQLCA/SQLDA, the voilation on which index happened is also provided, you may interpret it know where the failure was. Thanks |
|
Back to top |
|
 |
Rama_Prayaga Beginner

Joined: 20 May 2003 Posts: 45 Topics: 15
|
Posted: Wed Feb 23, 2005 9:16 am Post subject: |
|
|
Hi Suresh,
Thanks for your reply,I think I should elobrate my requirement a bit.
See, Primary key is build in the program by giving Max rows + 1,Since this key is build in another online program as well in similar fashion. There can be a dupicate error.
Now if the problem is with the Primary-key, I can create a new key by giving Max rows +1 again and insert the row.
But if it is the duplicate problem with Unique index (its is created on a set of seven columns) , then I cannot insert that (i dont have to).
I hope i put my problem cleary this time
Regards |
|
Back to top |
|
 |
kolusu Site Admin

Joined: 26 Nov 2002 Posts: 12378 Topics: 75 Location: San Jose
|
Posted: Wed Feb 23, 2005 9:22 am Post subject: |
|
|
Rama_Prayaga,
The simplest way to handle such scenario's is to select before you insert a row.
1. select to see if it is a duplicate key
2. Select to see if it is the unique index defined on the seven columns.
Code: |
if sqlcode from 2nd select = 0
skip insert
else
increment the max key
insert the row
end-if
|
Hope this helps...
Cheers
kolusu _________________ Kolusu
www.linkedin.com/in/kolusu |
|
Back to top |
|
 |
Rama_Prayaga Beginner

Joined: 20 May 2003 Posts: 45 Topics: 15
|
Posted: Thu Feb 24, 2005 9:27 am Post subject: |
|
|
kolusu,
Thank you for your suggestion. I have adapted you suggestion in the program.
I was thinking if SQLSTATE could help me.But I was not sure of it.
What is use of SQLSTATE .I thought it will sub classify the the SQLCODE.Please correct me I am wrong
Rama |
|
Back to top |
|
 |
kolusu Site Admin

Joined: 26 Nov 2002 Posts: 12378 Topics: 75 Location: San Jose
|
|
Back to top |
|
 |
|
|