Page Index Toggle Pages: 1 [2]  Send Topic Send Topic Print Print
Hot Topic (More than 10 Replies) Needs help with xResultsetReparent ( ) command (Read 2516 times)
Bharat_Naik
Senior Member
Members
*****
Offline


Ever ready to learn and
share

Posts: 1202
Location: Chicago,  Illinois
Joined: Dec 16th, 2003
Re: Needs help with xResultsetReparent ( ) command
Reply #15 - Mar 6th, 2012 at 7:07pm
Print Post Print Post  
In that case, what can I do, so that @XResultSetReparent ( ) commands works in the given circumstances. In other words, how do I give the exclusive access of Child records to the parent record?
  
Back to top
 
IP Logged
 
Bharat_Naik
Senior Member
Members
*****
Offline


Ever ready to learn and
share

Posts: 1202
Location: Chicago,  Illinois
Joined: Dec 16th, 2003
Re: Needs help with xResultsetReparent ( ) command
Reply #16 - Mar 6th, 2012 at 8:25pm
Print Post Print Post  
Also, why @XResultSetReparent ( ) command will work (The same code) when activated from the form of different database?  I am just trying to understand the logic. In both the cases, the form with the subform is not open. Only the Resultset addresses the parent database and child database.
  
Back to top
 
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: Needs help with xResultsetReparent ( ) command
Reply #17 - Mar 6th, 2012 at 8:55pm
Print Post Print Post  
The answer has to do with natural linking. Natural linked records in Sesame, when not in a result set, store pointers to the records before and after them, and if they have children, they have a pointer to the first record in the child chain of records.

When they are in a result set, an array of pointers is declared. Each element in that array points at a single record. There is then a central pointer for the whole result set that indicates the current record. When that current record pointer advances through the array, if the old current record has child result sets, the records in those result sets are relinked to resolve their new order and status. They are then removed from the result set to be replaced by the child records of the new current parent.

If you reparent records that appear in more than one result set, and the parent record for either the SBasic bound result set, or the form's result set, causes a relinking, and that relinking does not correspond to the linking that either SBasic or the form is counting on, one or both are likely to become confused. Records could be orphaned, etc.

Records in a result set are not copies of the record, with separate natural linking information. So, I guess I would recommend that you take advantage of the "X" in "XResultSet" and do reparenting from some point other than one that contains the record you are affecting. This all a bit like trying to change the tires on a moving car from inside the car.
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
Bharat_Naik
Senior Member
Members
*****
Offline


Ever ready to learn and
share

Posts: 1202
Location: Chicago,  Illinois
Joined: Dec 16th, 2003
Re: Needs help with xResultsetReparent ( ) command
Reply #18 - Mar 6th, 2012 at 9:26pm
Print Post Print Post  
Mark, thanks for explanation. What I could do is make one boolean field in subrecord and check it if it is made from one of the form of the same database. Process these subrecords, child records, for re-parenting from different database form such as Menu using command button, even better activate it from one of the forms that I work with frequently during the course of the day using @ClientLocalValue ( ) to limit frequent unnecessary processing. Any better solution?
  
Back to top
 
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: Needs help with xResultsetReparent ( ) command
Reply #19 - Mar 6th, 2012 at 9:41pm
Print Post Print Post  
That sounds okay. You could work from the form you are on already, just make sure that it, nor its children are in the result sets you are reparenting. This is easy to accomplish in add mode, where your result set is entirely empty. Or, just as easily, from a form made just for the purpose of reparenting other records. I'd lean toward the latter, in that reparenting is a vey serious operation, and I wouldn't want to simply place it on a commonly used form.

  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
Bharat_Naik
Senior Member
Members
*****
Offline


Ever ready to learn and
share

Posts: 1202
Location: Chicago,  Illinois
Joined: Dec 16th, 2003
Re: Needs help with xResultsetReparent ( ) command
Reply #20 - Mar 6th, 2012 at 10:35pm
Print Post Print Post  
Thanks Mark and Ray. I will report after having successfully implemented. Now I have a little better understanding. Thanks again.  Smiley
  
Back to top
 
IP Logged
 
Bharat_Naik
Senior Member
Members
*****
Offline


Ever ready to learn and
share

Posts: 1202
Location: Chicago,  Illinois
Joined: Dec 16th, 2003
Re: Needs help with xResultsetReparent ( ) command
Reply #21 - Mar 7th, 2012 at 7:04am
Print Post Print Post  
Implemented the ReParent Routine from a form of other database and it works great. Also put certain error catching codes and safeguards.  The code is processed only if Flag with ClientLocalValue ( ) is created, thereby conserve resources.  It works along with the normal daily addition of records, so no other special  procedure needed to reparent the subrecord.  Special thanks to Ray and Mark for making the concept clear.
Following is the code:
Code
Select All
var vParentRSID as Int
var vChildRSID as Int
var vChart as String
var vChartString as String
var vRecordsFound as Int
var vFailureIndicator as Boolean = 0

var n as Int


// The Same code has been placed in DX2 of Physical File on Element Exit Event for New Records Only


If @ClientLocalValue ("ToBeReParented") = "Yes" then   //The value is set in Index or Recall DocManage to prevent Processing Unnecessary Processing code
	{

		vChildRSID = @XResultSetSearch(@FN, "Index!Documents", SEARCH_MODE_AND, SEARCH_SYNTAX_QA, "!Marker=" + 1)

			If vChildRSID > -1 then
				{
					vRecordsFound = @XResultSetTotal (vChildRSID)

					For n = 1 to vRecordsFound
						XResultSetCurrentPosition (vChildRSID, n)
						If vChartString = "" then
							{
								vChartString = @XResultSetValue (vChildRSID, "Chart")

							}
							Else
							{
								vChartString = vChartString + ";" + @XResultSetValue (vChildRSID, "Chart")

							}
					Next

					XResultSetClose (vChildRSID)

				}


		For n = 1 to @CountStringArray (vChartString)
			vChart = @AccessStringArray (vChartString, n)


				vParentRSID = @XResultSetSearch(@FN, "Index", SEARCH_MODE_AND, SEARCH_SYNTAX_QA, "!Chart=" + vChart)

					If vParentRSID > -1 then
						{
							vRecordsFound = @XResultSetTotal (vParentRSID)

							If vRecordsFound = 1 then
								{
									vChildRSID = @XResultSetSearch(@FN, "Index!Documents", SEARCH_MODE_AND, SEARCH_SYNTAX_QA, "!Chart=" + vChart)

									If vChildRSID > -1 then
										{

							                                xResultSetSort (vChildRSID, "DateAdded:1")
											xResultSetReparent (vParentRSID, "DocumentSubForm", vChildRSID)
											If @Error then
												{
													WriteLN ("Reparent Failed, Close the Record for the Patient with " + vChart + " number in Index Database Forms")
													VFailureIndicator = 1
												}
												Else
												{
													XResultSetValue (vChildRSID, "Marker", 0)

												}



											xResultSetClose (vChildRSID)
										}

								}

								Else if vRecordsFound = 0 then
								{
									WriteLN ("Chart " + vChart + " Does not exist in INDEX Database!!! Please Correct it" )
									vFailureIndicator = 1
								}
								Else if vRecordsFound > 1 then
								{

									WriteLN ("Chart " + vChart + " has Multiple Entries in INDEX Database!!! Please Correct it" )
									vFailureIndicator = 1
								}

							XResultSetClose (vParentRSID)


						}
		Next

		If vFailureIndicator = 0 then
			{

				ClientLocalValue ("ToBeReParented", "")    // Reset it so, the program will not run next time unless Index or Recall form process some document
			}
	}
 

  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1 [2] 
Send Topic Send Topic Print Print