Hey all,
I have a script I've been working on to export database tables to flat files.
Since one of the target DB's is Access, I've had to cobble some Win32::OLE code
together, using Win32::OLE::Const 'Microsoft ActiveX Data Objects';. Every-
thing seems to work, provided that none of the return fields go over 255 Chars.
What I get if they do is up to 255 chars of output data, appended by up to 20
chars of ENV data. Any ideas?

Thanks,
amonotod
amonotod@charter.net

Update -- code included
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"; }

In reply to Win32::OLE, cuts off at 255 Chars... by amonotod

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.