Home » Developer & Programmer » Forms » binding data problem (Oracle 10g)
binding data problem [message #545948] Sat, 03 March 2012 11:47 Go to next message
baliberde
Messages: 201
Registered: January 2012
Location: outer space
Senior Member
I've got a problem with binding my selected data from one data block to another. When I'd finished selecting my data(subjects in this case),
pls. see my screenshot:
http://i44.tinypic.com/dw2vp.png
and I clicked schedule button, my selected data were not bound into the textboxes in schedule datablock.
this what happened.
http://i42.tinypic.com/27x13q1.png

the code i used in when-checkbox-changed trigger:
BEGIN

IF :NEWSTUDENTS.cb_subj = 'N' THEN
		Clear_record;

ELSIF :NEWSTUDENTS.cb_subj = 'Y' THEN
	
	:SCHEDULE2.Subject := :newstudents.subject_code;

END IF;

END;


and in tree-node-activated trigger:

	MEssage('FOR LOOP - subj_code = ' || subj_rec.subject_code);
	:NEWSTUDENTS.subject_code := label_of_mynode;  
	:NEWSTUDENTS.subject_code:= subj_rec.subject_code;
	:NEWSTUDENTS.units:= subj_rec.units;
	MESSAGE('POSITION OF CURSOR ' || :SYSTEM.CURSOR_RECORD);

	NEXT_RECORD;
END LOOP;

END;
*/

DECLARE
	mytree ITEM;
  label_of_mynode VARCHAR2(100);
  
   CURSOR subj_cur IS
      SELECT subject_code,units
        FROM tblSubjectSection 
         	WHERE section = label_of_mynode
         			ORDER BY subject_code ASC;
         		
BEGIN
	
	
	    IF (:System.trigger_node_selected = 'TRUE') then
					-- Find out the tree
					mytree := Find_Item('tree_section.tree_subjects');
					-- Get the value of the node clicked on.
					-- value_of_mynode := Ftree.Get_Tree_Node_Property(mytree, :SYSTEM.TRIGGER_NODE, Ftree.NODE_VALUE);
					label_of_mynode := Ftree.Get_Tree_Node_Property(mytree, :SYSTEM.TRIGGER_NODE, Ftree.NODE_LABEL);   	
     	END IF;
GO_BLOCK('newstudents');
--CLEAR_BLOCK;
FOR subj_rec IN subj_cur
LOOP
	MEssage('FOR LOOP - subj_code = ' || subj_rec.subject_code);
--	:NEWSTUDENTS.subject_code := label_of_mynode;  
	:NEWSTUDENTS.subject_code:= subj_rec.subject_code;
	:NEWSTUDENTS.units:= subj_rec.units;
--	:NEWSTUDENTS.day := subj_rec.day;
--	:NEWSTUDENTS.time:= subj_rec.units;
	MESSAGE('POSITION OF CURSOR ' || :SYSTEM.CURSOR_RECORD);

	NEXT_RECORD;
END LOOP;
	
END;


Re: binding data problem [message #545958 is a reply to message #545948] Sat, 03 March 2012 13:33 Go to previous messageGo to next message
cookiemonster
Messages: 13925
Registered: September 2008
Location: Rainy Manchester
Senior Member
I would have thought that by now you would have realised that you need to tell us things like which block is which.
Screen shots are not a substitute for a clear explanation of what the code is supposed to do.

I suspect that once again the problem is that the cursor isn't where you think it is, and you're assigning values to a different record than the one you think you are.
Re: binding data problem [message #545992 is a reply to message #545958] Sun, 04 March 2012 08:39 Go to previous messageGo to next message
baliberde
Messages: 201
Registered: January 2012
Location: outer space
Senior Member
Ok, the first block is the newstudent. This block has h. tree in which the end user will choose what subjects to enroll.When the user is done selecting subjects(with the checkbox, I place my code in when-checkbox-changed), he may now choose his schedule. When he clicks on schedule button, he goes to schedule2 block wherein the subjects the user has selected should be in that schedule block. And since in my case, only the last subject is displayed twice.Pls. let me know where my faulty code is.
Re: binding data problem [message #546012 is a reply to message #545958] Sun, 04 March 2012 10:19 Go to previous messageGo to next message
cookiemonster
Messages: 13925
Registered: September 2008
Location: Rainy Manchester
Senior Member
cookiemonster wrote on Sat, 03 March 2012 19:33

I suspect that once again the problem is that the cursor isn't where you think it is, and you're assigning values to a different record than the one you think you are.

Specifically the code in the when-checkbox-changed.
Again - you need to debug it.
Add messages to check which record in schedule2 you are altering.

Re: binding data problem [message #546023 is a reply to message #546012] Sun, 04 March 2012 11:44 Go to previous messageGo to next message
baliberde
Messages: 201
Registered: January 2012
Location: outer space
Senior Member
ok i will add message to it.
Re: binding data problem [message #546025 is a reply to message #546023] Sun, 04 March 2012 11:56 Go to previous messageGo to next message
baliberde
Messages: 201
Registered: January 2012
Location: outer space
Senior Member
i did this one:
BEGIN

IF :NEWSTUDENTS.cb_subj = 'N' THEN
		Clear_record;

ELSIF :NEWSTUDENTS.cb_subj = 'Y' THEN
	Message('POSITION OF CURSOR ' || :SYSTEM.CURSOR_RECORD);
	:SCHEDULE2.Subject := :newstudents.subject_code;

END IF;

END;


it still does the same thing..
Re: binding data problem [message #546032 is a reply to message #546025] Sun, 04 March 2012 13:32 Go to previous messageGo to next message
cookiemonster
Messages: 13925
Registered: September 2008
Location: Rainy Manchester
Senior Member
You need to actually start thinking about what you do, or stop programming.
I've got you to debug code before, and you've added messages, used them to work out what the code is doing and then you fixed the code.
This time you add message and expect that to do something other than display a message - why?
If you don't want to think about what code does - quit programming. I'm serious, if you don't want to think about this then it is the wrong job for you.
I say that because you are perfectly capable of thinking about it, you've done so before, so there's no excuse for not doing it this time.

We can not and will not spoon feed you all the answers.
We cannot debug your code for you so you have to learn to do so yourself, it's a basic skill any programmer needs.

Finally - :system.cursor_record will give the record number of the block the cursor is in. The cursor will be in newstudents. You want to know the record you are altering in schedule2. You'll need to use get_block_property (look it up in form builder help) to get the correct value.
Re: binding data problem [message #546079 is a reply to message #546032] Mon, 05 March 2012 04:33 Go to previous messageGo to next message
baliberde
Messages: 201
Registered: January 2012
Location: outer space
Senior Member
are you saying that I need to use get_block_property in my schedule2 block? or will I put it in when-checkbox-changed?
Re: binding data problem [message #546090 is a reply to message #546079] Mon, 05 March 2012 04:59 Go to previous messageGo to next message
cookiemonster
Messages: 13925
Registered: September 2008
Location: Rainy Manchester
Senior Member
I'm saying you need to use get_block_property instead of system.cursor_record in the message to see which record in the schedule2 block you are actually modifying with the code in the WHEN-CHECKBOX-CHANGED trigger. It'll be same record each time, as once again you have written no code to change the record.
Personally I'd put all the code to populate the schedule2 block in the WHEN-BUTTON-PRESSED trigger of the schedule button. There's no point messing with the other block until you need it.
Re: binding data problem [message #546091 is a reply to message #546090] Mon, 05 March 2012 05:17 Go to previous messageGo to next message
baliberde
Messages: 201
Registered: January 2012
Location: outer space
Senior Member
This I tried:

Message('record ' || get_block_property('newstudents', CURRENT_RECORD));




So, you mean if you were in my shoes, you'd put this code:
BEGIN

IF :NEWSTUDENTS.cb_subj = 'N' THEN
		Clear_record;

ELSIF :NEWSTUDENTS.cb_subj = 'Y' THEN
	Message('POSITION OF CURSOR ' || :SYSTEM.CURSOR_RECORD);
	:SCHEDULE2.Subject := :newstudents.subject_code;

END IF;

END;


in my schedule button?

[Updated on: Mon, 05 March 2012 05:20]

Report message to a moderator

Re: binding data problem [message #546092 is a reply to message #546091] Mon, 05 March 2012 05:29 Go to previous messageGo to next message
cookiemonster
Messages: 13925
Registered: September 2008
Location: Rainy Manchester
Senior Member
Which record(s) in the newstudents block is that code going to check?
Which record(s) in the schedule2 block is that code going to modify?
Re: binding data problem [message #546102 is a reply to message #546092] Mon, 05 March 2012 06:12 Go to previous messageGo to next message
baliberde
Messages: 201
Registered: January 2012
Location: outer space
Senior Member
the only last record in my newstudents was checked by my get_block_property code.and again it displayed twice.
Re: binding data problem [message #546104 is a reply to message #546102] Mon, 05 March 2012 06:16 Go to previous messageGo to next message
cookiemonster
Messages: 13925
Registered: September 2008
Location: Rainy Manchester
Senior Member
Are you going to answer my questions?
Re: binding data problem [message #546107 is a reply to message #546104] Mon, 05 March 2012 06:31 Go to previous messageGo to next message
baliberde
Messages: 201
Registered: January 2012
Location: outer space
Senior Member
sorry, the record in the newstudents block that it's going to check is the current record, as for this, it just checks the last record(subject)
Re: binding data problem [message #546110 is a reply to message #546107] Mon, 05 March 2012 06:39 Go to previous messageGo to next message
cookiemonster
Messages: 13925
Registered: September 2008
Location: Rainy Manchester
Senior Member
So how do you expect to populate the schedule2 block with multiple records from the newstudents block if the code only ever looks at one record in each?
You need to loop over the newstudents block and populate the schedule2 block accordingly. You've done this before so I'm at a loss as to why you are struggling to do so now.
Re: binding data problem [message #546119 is a reply to message #546110] Mon, 05 March 2012 06:59 Go to previous messageGo to next message
baliberde
Messages: 201
Registered: January 2012
Location: outer space
Senior Member
so I'm going to put my loop in when-new-block-instance newstudents block?
Re: binding data problem [message #546130 is a reply to message #546119] Mon, 05 March 2012 07:23 Go to previous messageGo to next message
cookiemonster
Messages: 13925
Registered: September 2008
Location: Rainy Manchester
Senior Member
What's wrong with putting the loop in the button like I suggested?
Re: binding data problem [message #546133 is a reply to message #546130] Mon, 05 March 2012 07:31 Go to previous messageGo to next message
baliberde
Messages: 201
Registered: January 2012
Location: outer space
Senior Member
I followed you
this is what happened:
http://i44.tinypic.com/33ufxhd.png
Re: binding data problem [message #546134 is a reply to message #546133] Mon, 05 March 2012 07:32 Go to previous messageGo to next message
baliberde
Messages: 201
Registered: January 2012
Location: outer space
Senior Member
from button schedule:

DECLARE
	
	 CURSOR subj_cur IS
   SELECT subject_code, day
   FROM tblsubjectsection 
   WHERE subject_code = :newstudents.subject_code
   ORDER BY subject_code ASC;

BEGIN
	
	GO_BLOCK('SCHEDULE2');
	
	FOR subj_rec IN subj_cur
	LOOP

	Message('POsition of record ' || get_block_property('newstudents', CURRENT_RECORD));
	:SCHEDULE2.Subject := :newstudents.subject_code;
	NEXT_RECORD;
	Message('POsition of record ' || get_block_property('schedule2', CURRENT_RECORD));
END LOOP;


END;
Re: binding data problem [message #546137 is a reply to message #546134] Mon, 05 March 2012 07:40 Go to previous messageGo to next message
cookiemonster
Messages: 13925
Registered: September 2008
Location: Rainy Manchester
Senior Member
Records in the database are not the same as records in a datablock.
Records in the database are not the same as records in a datablock.
Records in the database are not the same as records in a datablock.
Records in the database are not the same as records in a datablock.
Records in the database are not the same as records in a datablock.

I've pointed that out to you before. It's a fundamental point of how forms works. You need to understand it or will never be able to sucessfully code a single form.
Think about that.

Then explain to me what the above code does, line by line.
Re: binding data problem [message #546138 is a reply to message #546137] Mon, 05 March 2012 07:48 Go to previous messageGo to next message
baliberde
Messages: 201
Registered: January 2012
Location: outer space
Senior Member
DECLARE
	
   CURSOR subj_cur IS
   SELECT subject_code, day
   FROM tblsubjectsection 
   WHERE subject_code = :newstudents.subject_code
   ORDER BY subject_code ASC;

BEGIN
	
	GO_BLOCK('SCHEDULE2'); [b] --- goes to schedule2 block[/b]
	
	FOR subj_rec IN subj_cur  [b]-- for every subj_rec it'll loop in subj_cur[/b]
	LOOP -- loop starts

	Message('POsition of record ' || get_block_property('newstudents', CURRENT_RECORD)); [b]-- displays the current record in the newstudents, oH! the last one... my bad[/b]
	:SCHEDULE2.Subject := :newstudents.subject_code;
[b]-- the record in :newstudents.subject_code will be bound to :schedul2.subject item..[/b]
	NEXT_RECORD;  [b]---- will go for next record[/b]
	Message('POsition of record ' || get_block_property('schedule2', CURRENT_RECORD)); [b]--will display for the current record in schedule2 block[/b]
END LOOP;  [b]-- loop ends[/b]


END;
Re: binding data problem [message #546141 is a reply to message #546138] Mon, 05 March 2012 08:04 Go to previous messageGo to next message
cookiemonster
Messages: 13925
Registered: September 2008
Location: Rainy Manchester
Senior Member
And which record in the newstudents block are you using in each iteration of the loop?
Re: binding data problem [message #546145 is a reply to message #546141] Mon, 05 March 2012 08:13 Go to previous messageGo to next message
baliberde
Messages: 201
Registered: January 2012
Location: outer space
Senior Member
is this one :SCHEDULE2.Subject := :newstudents.subject_code;?
Re: binding data problem [message #546152 is a reply to message #546145] Mon, 05 March 2012 08:27 Go to previous messageGo to next message
cookiemonster
Messages: 13925
Registered: September 2008
Location: Rainy Manchester
Senior Member
baliberde wrote on Mon, 05 March 2012 14:13
is this one :SCHEDULE2.Subject := :newstudents.subject_code;?

Do you think that line of code:
a) assigns multiple records at once
b) causes the form to change the record of the newstudents block it is currently using.

If you think neither of those answers then how do you think that line of code answers my question?
Re: binding data problem [message #546161 is a reply to message #546152] Mon, 05 March 2012 08:46 Go to previous messageGo to next message
baliberde
Messages: 201
Registered: January 2012
Location: outer space
Senior Member
Oh my bad, is it in the line of FOR LOOP? If I'm not mistaken, I used subj_rec there and didn't even use that for my :SCHEDULE2.Subject := :newstudents.subject_code;
Re: binding data problem [message #546167 is a reply to message #546161] Mon, 05 March 2012 09:17 Go to previous messageGo to next message
cookiemonster
Messages: 13925
Registered: September 2008
Location: Rainy Manchester
Senior Member
I know what the block of code does. I'm trying to work out what you think it does so I can correct the mistake in your thought process.
It obviously doesn't do what you expect.

You are not using any value selected from the cursor inside the loop.
So what effect do you think the loop has? Why have you put it there?
Do you think the loop will change the result of this line:
:SCHEDULE2.Subject := :newstudents.subject_code;
If so, why?
Re: binding data problem [message #546170 is a reply to message #546167] Mon, 05 March 2012 09:30 Go to previous messageGo to next message
baliberde
Messages: 201
Registered: January 2012
Location: outer space
Senior Member
I think, as the result was, it'd display the last record. And so i think the loop would change this :SCHEDULE2.Subject := :newstudents.subject_code;
Re: binding data problem [message #546172 is a reply to message #546170] Mon, 05 March 2012 09:36 Go to previous messageGo to next message
cookiemonster
Messages: 13925
Registered: September 2008
Location: Rainy Manchester
Senior Member
Why would the loop change it?
Why would looping over records in a table in the database cause forms to change which record in a datablock it is looking at?

Remember:
Records in the database are not the same as records in a datablock.
Re: binding data problem [message #546175 is a reply to message #546172] Mon, 05 March 2012 09:58 Go to previous messageGo to next message
baliberde
Messages: 201
Registered: January 2012
Location: outer space
Senior Member
Because the loop hasn't found any records that are the same in the database?
Re: binding data problem [message #546184 is a reply to message #546175] Mon, 05 March 2012 10:27 Go to previous messageGo to next message
cookiemonster
Messages: 13925
Registered: September 2008
Location: Rainy Manchester
Senior Member
Ok fine I'll spell it out.

Before pressing the button you have say 5 records in newstudents. The cursor is in the fifth record. So that's the current record for that block.
You press the button.

It goes to the schedule2 block.
It runs the cursor loop that selects x number of records from the DB. Lets say there are 4 records that the cursor returns.

Then for each row returned by the cursor you do:
:SCHEDULE2.Subject := :newstudents.subject_code;
NEXT_RECORD;

So that assigns :SCHEDULE2.Subject to the value of :newstudents.subject_code for the current record in the newstudents block (so that would be record number 5) in that block.
It then goes to the next record in the schedule2 block.
The current record of the newstudents block remains unchanged. So you use the exact same value from that block each time you go round the loop.

Repeat for each record in the loop.

Put it even simpler:
It creates x records in the schedule2 block, where x is the number of rows returned by the cursor query.
Each created row will have :SCHEDULE2.Subject set to the value of :newstudents.subject_code for the particular record in the newstudents block which you were last in.
It will not use value from any other record in the newstudents block.


Again you have written no code to change which record in the newstudents block you are using. So it uses the same one each time.

The data you want to assign to the schedule2 block is in the newstudents block. It's not in a database table. It's in the datablock.

So you need to loop over both blocks and use no cursors.
Something like this:
BEGIN

  --Make sure you start in the first record of each block.
  go_block('NEWSTUDENTS');
  first_record;
  GO_BLOCK('SCHEDULE2');
  first_record;

  LOOP
  
    :SCHEDULE2.Subject := :newstudents.subject_code;
    
    go_block('NEWSTUDENTS');
    IF :system.last_record != 'TRUE' THEN
      --More records to go so move to the next record in both blocks.
      next_record;
      go_block('SCHEDULE2');
      next_record;
    ELSE
      --Done all records, exit loop
      EXIT;
      
    END IF;
    
  END LOOP;
  
END;


The alternative is to apply the data you want to appear in the SCHEDULE2 block to the database and then populate the block using standard execute_query.


You keep mixing up data in the form with data in the DB.
If you want data from the DB use exexute_query - or if really must use cursor for loops, use the actual data selected from the cursor.
If you want data from a datablock then loop over the records in the datablock and don't try and query data from the database.

Don't loop over data from the database in a for loop and then use value from a datablock inside the for loop.
They're not directly related.
Re: binding data problem [message #546187 is a reply to message #546184] Mon, 05 March 2012 11:00 Go to previous message
baliberde
Messages: 201
Registered: January 2012
Location: outer space
Senior Member
thank you so much cookie! I now understand! If I'm just copying data from a block I don't have to use cursors but instead just loop over that block. And if I'm going to pull out records from my tables or in the DB itself, Forms has Execute_Query built-in. Now it's somewhat clearer to me now than before.
Previous Topic: Why the "Arabic comma" reverse the text.(4 Merged)
Next Topic: problem with finding a node in a tree
Goto Forum:
  


Current Time: Sat Jul 06 00:11:10 CDT 2024