DB2 V8.1 on AIX V5.2
I have a .cpp application using ODBC for database interaction.
I create the temp table thus :
"DECLARE GLOBAL TEMPORARY table x_tab (x_col VARGRAPHIC(10)) ON COMMIT PRESERVE ROWS NOT LOGGED"
The index thus :
"CREATE unique index SESSION.x_ind on SESSION.x_tab(x_col)"
I then execute an insert statement :
"insert into SESSION.x_tab (x_col) values (G'x')"
I then execute a count statement :
"select count(*) from SESSION.x_tab"
- This produces 1 - correct.
I then execute another insert statement that will fail due to a duplicate record:
"insert into SESSION.x_tab (x_col) values (G'x')"
- Correctly fails with the below error :
547, <[IBM][CLI Driver][DB2/LINUX] SQL0803N One or more values in the INSERT statement, UPDATE statement, or foreign key update caused by a DELETE statement are not valid because the primary key, unique constraint or unique index identified by "1" constrains table "SESSION.X_TAB" from having duplicate rows for those columns. SQLSTATE=23505
I then execute a second count statement against the temporary table:
"select count(*) from SESSION.x_tab"
- This produces 0 - INCORRECT.
It seems that the 547 error removes all data in the temporary table ???
Anyone come across this ?
We have hundreds of programs that contain temporary tables!.
To get around this I am going to have to dynamically create a select statement against the tamporary tables primary key using the values to be inserted.
I would much rather one of you have a simpler solution for me...
Thanks in advance for any help on this.
Andy.