CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Writing DB results to File

 



umpty
Novice

Feb 16, 2003, 9:24 AM

Post #1 of 7 (838 views)
Writing DB results to File Can't Post

The following code:

Code
use OLE; 
$conn = CreateObject OLE "ADODB.Connection" ||
die "CreateObject: $!";
$conn->Open ('OGCParse');
$sql = "SELECT * FROM Output";
$rs = $conn->Execute($sql);
while(!$rs->EOF()) {
$myFile = $rs->Fields('File')->Value;
$myHandle = $rs->Fields('Handle')->Value;
write;
$rs->MoveNext();
}
$rs->Close();
$conn->Close();


produces the following output:

1000.txt 833E14D1-621E-11D3-9741-00805FE246D4
8200.txt A6C0BD67P92A9P11D1P96F8P00805FE246D4
9000.txt 37ad22c5-5232-11d1-96ee-00805fe246d4

Question: How would I modify the script to produce a text file for each record in the DB where each field would be displayed on a separate line (using the first field as the name of the text file).

Thus, the format in each file would be in the following format:

File 1000.txt would look like this:
1000.txt
833E14D1-621E-11D3-9741-00805FE246D4

and File 8200.txt would look like this:
8200.txt
A6C0BD67P92A9P11D1P96F8P00805FE246D4

and so on and so forth...

Thanks.


umpty
Novice

Feb 17, 2003, 11:21 AM

Post #2 of 7 (828 views)
Re: [umpty] Writing DB results to File [In reply to] Can't Post

Looks like I answered my own request. The correct code is as follow:

use OLE;
$conn = CreateObject OLE "ADODB.Connection" ||
die "CreateObject: $!";
$conn->Open ('OGCParse');
$sql = "SELECT * FROM Output";
$rs = $conn->Execute($sql);
while(!$rs->EOF()) {
$myFile = $rs->Fields('File')->Value;
$myHandle = $rs->Fields('Handle')->Value;
@array = $myFile;
open FILE, ">C:/Search Express/$array[0]";
print FILE "$myFile\n$myHandle";
close (FILE);
$rs->MoveNext();
}
$rs->Close();
$conn->Close();


Paul
Enthusiast

Feb 17, 2003, 2:38 PM

Post #3 of 7 (823 views)
Re: [umpty] Writing DB results to File [In reply to] Can't Post

What purpose does this line serve?

>>
@array = $myFile;
<<


umpty
Novice

Feb 17, 2003, 4:02 PM

Post #4 of 7 (820 views)
Re: [Paul] Writing DB results to File [In reply to] Can't Post

Each record in the database has the name of a file. The array holds the current filename. It loops through each record and produces a text file with that name. The file has the desired data content in it that I desire.


Paul
Enthusiast

Feb 17, 2003, 4:34 PM

Post #5 of 7 (818 views)
Re: [umpty] Writing DB results to File [In reply to] Can't Post

>>
The array holds the current filename.
<<

Well so does $myFile so whats the point is using @array?


umpty
Novice

Feb 17, 2003, 8:16 PM

Post #6 of 7 (814 views)
Re: [Paul] Writing DB results to File [In reply to] Can't Post

I see what you mean. Your observation points out that you have been programming PERL for some time whereas I am just starting.

Much kudos to you.

Thanks, Dave


Paul
Enthusiast

Feb 18, 2003, 1:10 AM

Post #7 of 7 (812 views)
Re: [umpty] Writing DB results to File [In reply to] Can't Post

I'm simply asking for you to explain your reasons for using the code you were using. Oh well.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives