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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Export simultaneously to sdf

Status
Not open for further replies.

ewqdascxz

IS-IT--Management
Aug 4, 2011
23
PH
In VFP, can i export tables simultaneously to a .sdf file type without browsing the table? If i will open a .dbc file containing at least 100 tables, can i simultaneously export them to .sdf?
 
* Get tables names into an array
OPEN DATABASE MyDatabase
lnCount = ADBOBJECTS(laTables, "TABLE")

* Loop through the array
FOR lnI = 1 TO lnCount
USE (laTables(lnI))

* Make the output filename the same as the table's,
* but with TXT instead of DBF
lcFile = FORCEEXT(laTables(lnI),"txt")

* Copy the table to SDF
COPY TO (lcFile) SDF
ENDFOR

from these codes.. do i need to change the "MyDatabase"? and where will i put the CD? thanks.. i really new to this
 
Yes, "MyDatabase" is just an example, we don't know the name and path to yourdatabase, you have to change that.
CD goes directly in the next line, again, we don't know the directory you want to specify.

Bye, Olaf.
 
OK, here's a version of the code you could use in general, it uses a dialog to determine the source database and then another dialog to determine the destination folder and afterwards processes all tables of the selected database to export to the choosen destination folder.

Create a new Program file, copy the code and then save as dbctosdf.prg and run it.

Code:
* open a database 
OPEN DATABASE (GetFile("dbc"))
* specify destination directory
Cd (GetDir("","Where do you want the SDF files?","Specify Destination Directory",0,.F.))

* Get tables names into an array
lnCount = ADBOBJECTS(laTables, "TABLE")

* Loop through the array
FOR lnI = 1 TO lnCount
  USE (laTables(lnI))

  * Make the output filename the same as the table's,
  * but with TXT instead of DBF
  lcFile = FORCEEXT(laTables(lnI),"txt")

  * Copy the table to SDF
  COPY TO (lcFile) SDF
ENDF

Bye, Olaf.
 
make it

Cd (GetDir("","Where do you want the SDF files?","Specify Destination Directory",1+64,.F.))

This way you can a) create a new folder within GetDir() dialog and you can't finish the dialog without choosing a folder.

Bye, Olaf.
 
...ENDFOR... ;D (I had the same copy error perhaps, than you had)

Bye, Olaf.
 
Good grief. I replied to the original question a few minutes after it was posted. I then checked my email, took some food out the freezer for my lunch, and stared at the rain for a few minutes. The next thing I saw was that there were now 26 replies. I know this is a busy forum, but even so ....

Anyhow, Ewqdascxz, I think you're pretty well there now, with Olaf's inestimable help. I acknowledge a minor error in my original code (leaving out the TXT extension), and I realise you want all the output in a single file. But I hope my code was a useful starting point.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
Hi Mike!

Yes, your code was also useful to me to complete it with little effort.

Nice how you tell your perspective of this thread here, I can imagine the surprise. Yes, this was rather working as a chat, than as a forum for the moment. I think - hopefully - we finally managed to satisfy another "customer"...

Bye, Olaf.
 
Hello ewqdascxz,

it would be nice to get a final response of you.

Just as an add-on: I took a look at what your development platform Magic eDeveloper offers and I see among databases supported there is a general support for any database with ODBC driver, and there is a Foxpro ODBC driver. The latest version of it supports all field types up to VFP6, that may not stop you from using this instead of migrating to SDF (or any other database).

I can point you to While MS writes the driver is no longer supported, that doesn't mean it's not working.

If eDEveloper would support OLEDB (I may have overseen that), you can also follow Microsofts recommendation to use the VFP OleDB Provider instead. Other options are the Advantage Database ODBC driver.

Bye, Olaf.
 
One more :)

Actually you might want a SQL Server database, which (in compact edition) uses the file extension SDF, too. But in general the SDF file extension has several meanings, see
We here, Mike and me, thought about the first mentioned "standard data file" format, which simply is an ascii text file with a constant length for each field, no field delimiter, one record per line, one table per file.

Exporting DBC to a Microsoft SQL Server database, you better do via the VFP Upsizing Wizard and then downsize from a MDF database to compact from there, if that's what you actually wanted.

Bye, Olaf.
 

What I mean is that for example.. a.dbf b.dbf c.dbf im going to migrate these tables to a.sdf b.sdf c.sdf without exporting it one by one



Thank you OlafDoschke and MikeLewis
 
OK, then what I finally gave you will do that, you just need to complete the last line ENDF to be ENDFOR.

Bye, Olaf.
 


about this part Cd (GetDir("","Where do you want the SDF files?","Specify Destination Directory",0,.F.)).. what's the difference between "Where do you want the SDF files?" and "Specify Destination Directory"?
 
what will i put at "Where do you want the SDF files?"? D:\abc something like that? and how about the "Specify Destination Directory"?
 
GetDir will display a dialog, in which you can navigate to the folder and even create a new one. Just run the code.

Bye, Olaf.
 
what will i put at "Where do you want the SDF files?"? D:\abc something like that? and how about the "Specify Destination Directory"?

The first question will appear near the top of the dialogue, above the list of directories. The second question will appear in the title bar of the dialogue.

Of course, they don't have to be questions; they can be any text that will help the user.

I think Olaf's point was that you could figure that out for yourself just by trying it.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
Yes, Mike.

I wasn't understanding he was thinking of replacing the questions with their answer in the code.

If I want somebody to add somehing to the code I use ... or <<specify something here>> or something alike, but in this case the texts are really part of the code and I simply wanted to shortcut the process of you asking detail questions in giving you code, that you can simply run, no matter where your DBC is and where you want your SDF. Simply run that and you will be asked for these infos at runtime with open file and open directory dialogs you should know from many other aaplications and windows itself.

Bye, Olaf.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top