Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to save cursors? How to access their names? 2

Status
Not open for further replies.

peteschulte

IS-IT--Management
Nov 21, 2008
41
US
First, THANKS TO Tek-Tips and OLAF DOSCHKE for getting me this far. [2thumbsup] Now,

Hello Fox Programmers,

In the For loop below, we want to store each cursor to a dbf, preferably with the name assigned to it being the same as the name in the xml. We see the names in the Data Session and down in the status bar as the program creates them.

What to use to name them? A separate For loop?
I don't know how to use COPY FILE or COPY TO or RENAME when 14 files are being created and their names parsed from xml along with them. Those commands require the name, but I don't know the name at the time the command could be done.

Code:
SET DEFAULT TO \\Gmc\d\Stmt\Monterey\TEST\UB_XML\testExport\VFP8
Local lcXML, loXMLAdapter, loXMLTable
Close Tables All

xmlfile="bpexport.xml"
xmlcontent = FILETOSTR(xmlfile)
lcXML = xmlcontent 

loXMLAdapter = CreateObject("XMLAdapter")

loXMLAdapter.LoadXML(lcXML,.F.,.T.)
&& XMLAdapter.LoadXML( cXMLDocument [, lFile [, lValidateOnParse ]] )

For Each loXMLTable in loXMLAdapter.Tables
   loXMLTable.ToCursor()
   SET STEP ON
ENDFOR


SET && Opens the Data Session window.

Thanks again!!
 
loXMLTable.TableAlias will give you the alias used for the cursor. You can use that as the table name when you copy. Just add a line like this, inside the loop, after the call to ToCursor():

Code:
cFileName = FORCEPATH(loXMLTable.TableAlias, <the path where you want it>)
COPY TO (m.cFileName)

Tamar
 
ALIAS() will tell you the name of a cursor. So where you have the SET STEP ON put instead

Code:
CD \\Gmc\d\Stmt\Monterey\TEST\UB_XML\testImport\VFP8
For Each loXMLTable in loXMLAdapter.Tables
   loXMLTable.ToCursor()
   COPY TO (loXMLTable.Alias+".dbf")
EndFor

or simply use ALIAS()
Code:
   COPY TO (ALIAS())

Bye, Olaf.
 
Super! Thanks again, Olaf! In a hurry now, but will contribute later this week or today.
 
Hi pete,

will contribute later this week or today

If you want to spend money again: It's a very fine move of you to donate to Tek-Tips. You don't need to do for every good answer you get. Tek-Tips is also "just" the platform, it's users helping users here.

Bye, Olaf.
 
Hi Tamor, long time since I've seen your name. Good to know that you are still in VFP land :)

Anyway ...

one item that I want to bring up is that when doing copying to a file name via a variable's value, you need to ensure that the command line will handle spaces in the value correctly.

also, I think it would be a good idea to add a USE after the COPY TO so that the cursor and area is ensured to be closed.

 
<< Hi Tamor, long time since I've seen your name. Good to know that you are still in VFP land smile >>

Not sure why you haven't seen me around. I've been answering questions on a lot of sites, writing articles and books, and speaking at conferences.


<< one item that I want to bring up is that when doing copying to a file name via a variable's value, you need to ensure that the command line will handle spaces in the value correctly. >>

That's why I put parens around the filename in my response. That takes care of the embedded space problem.

Tamar
 
Tamor,
You've been at lots of sites, I haven't :) . usually i just check in at vfug, have not really had the time to get more involved here or at e-e .

as for the file names, another option is to use 8.3 syntax, which can help if somehow a quote mark gets in the filename.
 
8.3 only works if you have total control over file names, and won't help with a path containing a space (like, say, "Program Files"). Not an issue for this particular question, but certainly something to be aware of. The parens are the way to go.

Tamar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top