• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 535
  • Last Modified:

Pervasive Looping through Variables

I'm questioning if there is a way in Pervasive to loop through a text file of a single record. Say for instance i have ID's in a txt file that i would like updated. I guess the best way to describe it is much like how you would loop through a txt file in a Windows Batch file.

Is there something like UPDATE table SET column = 'this' WHERE id = '@txt_file_here.txt';

It would then loop through how many records i have. I know i can inject it into a dummy database and run the update that way just trying to save a few steps.
0
GalaxiePete
Asked:
GalaxiePete
1 Solution
 
mirtheilCommented:
There's no way to do that directly in Pervasive.  You'd need to write (or use) a program that could read the text file and fill in the variable value.  
0
 
Bill BachPresidentCommented:
Pervasive is just a database, and the core tools, while powerfuyl, will not allow something like what you want.  However, you CAN still create a script, using the following method:

This assumes that the "ID" file is called IDFILE.TXT and that it contains ONLY the ID fields that you want to update, exactly one ID per line.
1) Go to www.goldstarsoftware.com/tools.asp and download the free MakeBat tool.
2) Run the following from a command prompt (on one line, of course):
MAKEBAT "UPDATE table SET column = 'this' WHERE id = '" "';" <IDFILE.TXT >IDUPDATE.SQL
3) Load the IDUPDATE.SQL file into the Pervasive Control Center and select "Execute all SQL statements".
4) Set back and watch your computer do your work for you!

The trick is in the MAKEBAT function, which prepends a prefix and appends a suffix onto each line from the input file (in this case, your ID file).  The result is then captured to the SQL file with the ">" redirection function of the command prompt.  This then gives you a single file script which you can load into Pervasive and run automatically.

If needed, massage the text in the double-quotes in the MAKEBAT command line to get the exact SQL statement you need to run.

The tool SQLExec (from the same site) can also automate the running of the SQL script, so that you can do all of this from a single batch file -- and never have to look at it again.

0
 
GalaxiePeteAuthor Commented:
This is great thanks, yeah MySQL has a command for loading direct text files in this same way. This is great, thanks so much.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now