Home » Developer & Programmer » Forms » Problem in Inserting a Record (10g)
Problem in Inserting a Record [message #524816] Tue, 27 September 2011 01:47 Go to next message
shanie
Messages: 118
Registered: January 2011
Senior Member
Dear All,

There is a problem in Inserting a Record.
I have a table with primary key as Student_id
I created a form based on this table.
When I insert the record through form it gives me error
'frm-40508 unable to insert a record'
When I remove primary key from table Then It is inserting TWO Records at a time with the same Student ID.
I checked Data types of form and table it is ok.

Dont know what's the problem.
Table name is GZBGSSP and Fields are below
GZBGSSP_STU_ID	VARCHAR2(9 BYTE)
GZBGSSP_PIDM	NUMBER(8,0)
GZBGSSP_DEG_PLAN_IND	VARCHAR2(15 BYTE)
GZBGSSP_DEG_PLAN_DATE	DATE
GZBGSSP_COM_EXAM_IND	VARCHAR2(15 BYTE)
GZBGSSP_COM_EXAM_DATE	DATE
GZBGSSP_FT_RESD_IND	VARCHAR2(15 BYTE)
GZBGSSP_FT_RESD_DATE	DATE

Written Code in key_commit Trigger
declare tGZBGSSP_STU_ID saturn.GZBGSSP.GZBGSSP_STU_ID%TYPE;
begin
select GZBGSSP_STU_ID into tGZBGSSP_STU_ID from saturn.GZBGSSP where GZBGSSP_STU_ID = :KEY_ID;
	if sql%found then
		message('This Student ID already exists!');
		clear_block(no_commit);
		go_block('dual');
		go_item('KEY_ID');
	end if;

EXCEPTION WHEN NO_DATA_FOUND THEN
Declare vspriden_pidm 	SPRIDEN.SPRIDEN_PIDM%TYPE;
BEGIN			
SELECT SPRIDEN_PIDM INTO vspriden_pidm FROM SPRIDEN WHERE SPRIDEN_ID = :DUAL.KEY_ID and spriden_change_ind is null;
	IF SQL%FOUND THEN
	begin
insert into saturn.GZBGSSP(GZBGSSP_STU_ID,GZBGSSP_PIDM,GZBGSSP_DEG_PLAN_IND,GZBGSSP_DEG_PLAN_DATE,GZBGSSP_COM_EXAM_IND,GZBGSSP_COM_EXAM_DATE,GZBGSSP_FT_RESD_IND,GZBGSSP_FT_RESD_DATE) 
values(:KEY_ID,vspriden_pidm,:GZBGSSP_DEG_PLAN_IND,:GZBGSSP_DEG_PLAN_DATE,:GZBGSSP_COM_EXAM_IND,:GZBGSSP_COM_EXAM_DATE,:GZBGSSP_FT_RESD_IND,:GZBGSSP_FT_RESD_DATE);
commit;	
end;
clear_form(no_commit);  
END IF;
EXCEPTION
WHEN NO_DATA_FOUND THEN
Message('Invalid Id');
END;
end;


Please Help!
Thanks & Regards,
Shanie
Re: Problem in Inserting a Record [message #524821 is a reply to message #524816] Tue, 27 September 2011 02:15 Go to previous messageGo to next message
Littlefoot
Messages: 21818
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
A block is based on a table. Imagine that there are no triggers at all - the same situation you'd have (I'd say you SHOULD have) if you used Data Block Wizard to create a form. Such a form is fully operational - it allows you to insert new records, update and delete existing ones.

What you did, was to create a KEY-COMMIT trigger. Among other things, it contains INSERT statement which, well, inserts records into a table.

See? You are inserting these records twice!
- once by default Forms processing
- second time with your INSERT statement

It works OK when there's no unique constraint, but when it is enforced, it is an expected behaviour - Oracle won't allow you to violate it.

Therefore: remove the KEY-COMMIT trigger (for this and other reasons - Cookiemonster often says that it can easily be bypassed so its code will never be executed). "Smart" piece of code is the one where you check whether a student with the same ID already exists in a table. Put it into the WHEN-VALIDATE-ITEM trigger on the KEY_ID item.

Recompile the form and run it; I hope that it'll work OK.
Re: Problem in Inserting a Record [message #524825 is a reply to message #524821] Tue, 27 September 2011 02:25 Go to previous messageGo to next message
shanie
Messages: 118
Registered: January 2011
Senior Member
Dear Sir,

Initially I didnt write this trigger and it works fine.
But I am extracting one value i.e PIDM(Not Present in FORM) from different table and inserting into present table based on student-ID.
How can I achieve this without key-commit trigger.

Regards,
Shanie
Re: Problem in Inserting a Record [message #524827 is a reply to message #524825] Tue, 27 September 2011 02:33 Go to previous messageGo to next message
shanie
Messages: 118
Registered: January 2011
Senior Member
Dear Sir,

I have found the solution.
FORMS_DDL('commit');
This will take only custom code.

Thanks For your Instant Help.
Shanie
Re: Problem in Inserting a Record [message #524833 is a reply to message #524827] Tue, 27 September 2011 02:42 Go to previous messageGo to next message
Littlefoot
Messages: 21818
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
Quote:
I am extracting one value i.e PIDM(Not Present in FORM) from different table and inserting into present table based on student-ID.

Do that in WHEN-VALIDATE-ITEM trigger (the one I suggested earlier) while in insert mode, and in POST-QUERY while fetching existing records.


Quote:
I have found the solution. FORMS_DDL('commit');

This is most probably not the solution. It sends the COMMIT command to the database, but nothing is done (committed) on the Forms side. In my opinion, what you did should not be done in this/your case.
Re: Problem in Inserting a Record [message #524846 is a reply to message #524833] Tue, 27 September 2011 03:53 Go to previous message
Baranor
Messages: 83
Registered: September 2011
Location: Netherlands
Member
Multiple options, WHEN-VALIDATE-ITEM being the best... you can also use the WHEN-NEW-RECORD trigger, but you'll run the risk of locking yourself into a record if accidentially clicking on it. PRE-UPDATE and PRE-INSERT also are options.
Previous Topic: Forms
Next Topic: How to avoid no list elements defined for the list item error
Goto Forum:
  


Current Time: Sat Sep 07 12:56:06 CDT 2024