Created
December 3, 2015 04:05
-
-
Save jasonblewis/a9e9dbeaaf6849807d73 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use utf8; | |
use strict; | |
use warnings; | |
use DBI; | |
use Data::Dumper; | |
use Text::CSV; | |
use File::Slurper 'read_text'; | |
use RTF::TEXT::Converter; | |
use 5.22.0; | |
our $VERSION = '0.1'; | |
#my $dbh = DBI->connect("dbi:ODBC:act", {PrintError => 1}); | |
#my $dbh = DBI->connect("dbi:ODBC:DSN=act","ACTREADER","sirius",{PrintError => 0, RaiseError =>0}); | |
my $dbh = DBI->connect("dbi:ODBC:act","ACTREADER","sirius",{PrintError => 0, RaiseError =>0}); | |
#print "Out Connection String: ", $dbh->{odbc_out_connect_string}, "\n"; | |
my $dt; | |
unless ($dbh) { | |
die "Unable for connect to server $DBI::errstr"; | |
} | |
my $sth; | |
my $sth_dbname; | |
my $dat; | |
my $dbnames; | |
$sth = $dbh->prepare("select \@\@servername as name") or die "Can't prepare: $DBI::errstr\n"; | |
$sth->execute or die $sth->errstr; | |
$dat = $sth->fetchall_arrayref({}); | |
$sth->finish; | |
$dbh->do("use organictrader;") or die "Can't use organictrader $DBI::errstr\n"; | |
$sth_dbname = $dbh->prepare("select DB_NAME() as name;") or die "can't prepare\n"; | |
$sth_dbname->execute or die $sth_dbname->errstr; | |
$dbnames = $sth_dbname->fetchall_arrayref({}); | |
$sth_dbname->finish; | |
print Dumper($dbnames); | |
my $term_sql = read_text('/var/lib/u_drive/Users/jason/projects/suitecrm act exports/act suitecrm export/act suitecrm export/actnotes.sql','ASCII',1); | |
say "sql string length: ", length($term_sql); | |
#say "sql string: ", $term_sql; | |
$dbh->{LongReadLen} = 200000; | |
$dbh->{LongTruncOk} = 1; | |
say "LongReadLen is '", $dbh->{LongReadLen}, "'\n"; | |
say "LongTruncOk is ", $dbh->{LongTruncOk}, "\n"; | |
$sth = $dbh->prepare($term_sql) or die "can't prepare\n"; | |
$sth->execute | |
or die $sth->errstr; | |
my $fields = $sth->{NAME}; | |
my $csv_attributes = { | |
binary => 1, #recommneded | |
eol => $/, #recommended(I wonder why it's not $\ ?) | |
}; | |
#say 'before new'; | |
my $csv = Text::CSV_XS->new($csv_attributes); | |
#say 'after new'; | |
my $fname = 'actnotes.csv'; | |
open my $OUTFILE, ">", $fname | |
or die "Couldn't open $fname: $!"; | |
$csv->print($OUTFILE, $fields); | |
while (my $row = $sth->fetchrow_hashref) { | |
my $plainnotestr; | |
my $plainsubjectstr; | |
my $rtf_noteconverter = RTF::TEXT::Converter->new( output => \$plainnotestr); | |
my $rtf_subjectconverter = RTF::TEXT::Converter->new( output => \$plainsubjectstr); | |
# strip rtf from the subject field | |
$rtf_subjectconverter->parse_string(${$row}{'Subject'}) ; | |
$plainsubjectstr =~ s/(.{254}).*/$1/s; # trim string to n chars | |
#say "row: ", ${$row}{'rownumber'}, " plain subject string size: ", length($plainsubjectstr), " string: ", $plainsubjectstr; | |
${$row}{'Subject'} = $plainsubjectstr; | |
# strip rtf from the notes field | |
say "Note: ", ${$row}{'Note'}; | |
$rtf_noteconverter->parse_string(${$row}{'Note'}) ; | |
print "row: ", ${$row}{'rownumber'}, " plain note string size: "; | |
say length($plainnotestr); | |
${$row}{'Note'} = $plainnotestr; | |
$csv->print($OUTFILE, [ @$row{@$fields} ] ); | |
} | |
die $sth->errstr if $sth->err; | |
close $OUTFILE; | |
#my $creditors = $sth->fetchall_arrayref({}); | |
#print Dumper($fields); | |
#print Dumper($creditors); | |
$sth->finish; | |
$dbh->disconnect; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use of uninitialized value in say at actnotes.pl line 80.