|
Re: binding data problem [message #545958 is a reply to message #545948] |
Sat, 03 March 2012 13:33 ![Go to previous message Go to previous message](/forum/theme/orafaq/images/up.png) ![Go to next message Go to next message](/forum/theme/orafaq/images/down.png) |
cookiemonster
Messages: 13937 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 #546012 is a reply to message #545958] |
Sun, 04 March 2012 10:19 ![Go to previous message Go to previous message](/forum/theme/orafaq/images/up.png) ![Go to next message Go to next message](/forum/theme/orafaq/images/down.png) |
cookiemonster
Messages: 13937 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 #546032 is a reply to message #546025] |
Sun, 04 March 2012 13:32 ![Go to previous message Go to previous message](/forum/theme/orafaq/images/up.png) ![Go to next message Go to next message](/forum/theme/orafaq/images/down.png) |
cookiemonster
Messages: 13937 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 #546090 is a reply to message #546079] |
Mon, 05 March 2012 04:59 ![Go to previous message Go to previous message](/forum/theme/orafaq/images/up.png) ![Go to next message Go to next message](/forum/theme/orafaq/images/down.png) |
cookiemonster
Messages: 13937 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 message Go to previous message](/forum/theme/orafaq/images/up.png) ![Go to next message Go to next message](/forum/theme/orafaq/images/down.png) |
![](http://www.gravatar.com/avatar/9d3a737834daa8c057331fef1633aed5?s=64&d=mm&r=g) |
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 #546110 is a reply to message #546107] |
Mon, 05 March 2012 06:39 ![Go to previous message Go to previous message](/forum/theme/orafaq/images/up.png) ![Go to next message Go to next message](/forum/theme/orafaq/images/down.png) |
cookiemonster
Messages: 13937 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 #546137 is a reply to message #546134] |
Mon, 05 March 2012 07:40 ![Go to previous message Go to previous message](/forum/theme/orafaq/images/up.png) ![Go to next message Go to next message](/forum/theme/orafaq/images/down.png) |
cookiemonster
Messages: 13937 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 #546152 is a reply to message #546145] |
Mon, 05 March 2012 08:27 ![Go to previous message Go to previous message](/forum/theme/orafaq/images/up.png) ![Go to next message Go to next message](/forum/theme/orafaq/images/down.png) |
cookiemonster
Messages: 13937 Registered: September 2008 Location: Rainy Manchester
|
Senior Member |
|
|
baliberde wrote on Mon, 05 March 2012 14:13is 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 #546167 is a reply to message #546161] |
Mon, 05 March 2012 09:17 ![Go to previous message Go to previous message](/forum/theme/orafaq/images/up.png) ![Go to next message Go to next message](/forum/theme/orafaq/images/down.png) |
cookiemonster
Messages: 13937 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 #546172 is a reply to message #546170] |
Mon, 05 March 2012 09:36 ![Go to previous message Go to previous message](/forum/theme/orafaq/images/up.png) ![Go to next message Go to next message](/forum/theme/orafaq/images/down.png) |
cookiemonster
Messages: 13937 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 #546184 is a reply to message #546175] |
Mon, 05 March 2012 10:27 ![Go to previous message Go to previous message](/forum/theme/orafaq/images/up.png) ![Go to next message Go to next message](/forum/theme/orafaq/images/down.png) |
cookiemonster
Messages: 13937 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 Go to previous message](/forum/theme/orafaq/images/up.png) |
![](http://www.gravatar.com/avatar/9d3a737834daa8c057331fef1633aed5?s=64&d=mm&r=g) |
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.
|
|
|