amonotod has asked for the wisdom of the Perl Monks concerning the following question:
my %tables; my $gettablelist = 'MDBTables.exe -d"'. $db_name .'"'; #external exe, gets table info from access my @tableslist = split("\n", `$gettablelist`); my $db_dir = substr($db_name, index($db_name, "\\", -1), index($db_n +ame, ".")) ."_export"; print "output dir is $db_dir\n"; mkdir $db_dir; foreach my $tableinfo (@tableslist) { my (@data, $tablename, $tablecols); @data = split('--', $tableinfo); my @columns = split(",", $data[1]); $tablename = $data[0]; my @orderedcols; foreach (@columns) { my ($col_name, $col_pos) = split(" ", $_); $orderedcols[$col_pos - 1] = $col_name; } my $selectstatement = "select ("; my $count = 0; foreach (@orderedcols) { $selectstatement = $selectstatement ." ". $_; if ($count < $#orderedcols) { $selectstatement = $selectstatement ." &'|'&"; } elsif ($count == $#orderedcols) { $selectstatement = $selectstatement ." &'|'"; } $count++; } $selectstatement = $selectstatement .") AS TextReturn from [$tablena +me];"; $tables{$tablename} = $selectstatement; print "$selectstatement\n"; } use Win32::OLE; use Win32::OLE::Const 'Microsoft ActiveX Data Objects'; my $DSN = "PROVIDER='Microsoft.Jet.OLEDB.4.0';User ID=Admin;Password +='';Data Source=$db_name;" ."Jet OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Wit +hout Replica Repair=False;Jet OLEDB:SFP=False;"; foreach my $table (sort keys %tables) { my $output_file = $db_dir ."\\". $table .".dat"; open (OUTFILE, "> $output_file"); my $SQL = $tables{$table}; print "$table\n"; my $Conn = Win32::OLE->new("ADODB.Connection"); $Conn->Open($DSN); my $RS = Win32::OLE->new("ADODB.Recordset"); $RS->Open($SQL, $Conn); until ($RS->EOF) { my $value = $RS->Fields("TextReturn")->value; print OUTFILE "$value\n"; $RS->MoveNext; } $RS->Close; $Conn->Close; close OUTFILE; print "Done with $table\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Win32::OLE, cuts off at 255 Chars...
by bmann (Priest) on Jan 30, 2004 at 22:31 UTC | |
by amonotod (Acolyte) on Jan 30, 2004 at 22:38 UTC | |
|
Re: Win32::OLE, cuts off at 255 Chars...
by BrowserUk (Patriarch) on Jan 31, 2004 at 00:51 UTC | |
by maa (Pilgrim) on Jan 31, 2004 at 19:42 UTC |