Mike Lewis
Programmer
I just came up against an interesting issue, and thought I'd share my findings.
If you call an XML Adapter's ToCursor() method, it doesn't necessarily create the cursors in the current data session. Rather, it creates them in the data session that was in force when the object was instantiated.
Consider this code:
The aim of this code is to encapsulate the XML management in its own class, and to return the results, in the form of one or more cursors, to the caller's data session.
As coded here, this will fail. The cursor's will be created in the class's own data session (because that's where the XML Adapter object was instantiated), and will be invisible to the caller.
It's easy to get round this. You can either instantiate the XML Adapter object after you do the data session switch. Or you can give the whole class a default data session. But you have to know about it -- and, as far as I know, this behaviour isn't documented, which is why I am posting it here.
Mike
__________________________________
Mike Lewis (Edinburgh, Scotland)
My Visual FoxPro site: www.ml-consult.co.uk
If you call an XML Adapter's ToCursor() method, it doesn't necessarily create the cursors in the current data session. Rather, it creates them in the data session that was in force when the object was instantiated.
Consider this code:
Code:
DEFINE CLASS XMLStuff AS SESSION
oXML = NULL
FUNCTION Init
THIS.oXML = CREATEOBJECT("XMLAdapter")
ENDFUNC
FUNCTION GetData
* Receives the caller's data session as a param,
* so that it can return the cursor to the caller
LPARAMETER tnSession
LOCAL lnOldSession
lnOldSession = SET("Datasession")
SET DATASESSION TO tnSession
* Do something here to get the XML (e.g. from
* a web service)
* Convert the XML to a cursor
WITH THIS.oXML
.Load(lcXML)
.Tables(1).ToCursor(.F., "SomeCursor")
ENDWITH
SET DATASESSION TO lnOldSession
ENDFUNC
ENDDEFINE
The aim of this code is to encapsulate the XML management in its own class, and to return the results, in the form of one or more cursors, to the caller's data session.
As coded here, this will fail. The cursor's will be created in the class's own data session (because that's where the XML Adapter object was instantiated), and will be invisible to the caller.
It's easy to get round this. You can either instantiate the XML Adapter object after you do the data session switch. Or you can give the whole class a default data session. But you have to know about it -- and, as far as I know, this behaviour isn't documented, which is why I am posting it here.
Mike
__________________________________
Mike Lewis (Edinburgh, Scotland)
My Visual FoxPro site: www.ml-consult.co.uk