Win32-OLE
view release on metacpan or search on metacpan
############################################################
print "Start ADO and update database\n";
use Win32::OLE::Const 'Microsoft ActiveX Data Objects';
my $Connection = Win32::OLE->new('ADODB.Connection');
my $Recordset = Win32::OLE->new('ADODB.Recordset');
$Connection->Open('T-Bonds');
# Open a recordset for table of this contract
{
local $Win32::OLE::Warn = 0;
$Recordset->Open($Contract, $Connection, adOpenKeyset,
adLockOptimistic, adCmdTable);
}
# Create table and index if it doesn't exist yet
if (Win32::OLE->LastError) {
$Connection->Execute(<<"SQL");
CREATE TABLE $Contract
(
Day DATETIME,
Open DOUBLE, High DOUBLE, Low DOUBLE, Close DOUBLE
)
SQL
$Connection->Execute(<<"SQL");
CREATE INDEX $Contract
ON $Contract (Day) WITH PRIMARY
SQL
$Recordset->Open($Contract, $Connection, adOpenKeyset,
adLockOptimistic, adCmdTable);
}
# Add new record to table
use Win32::OLE::Variant;
$Win32::OLE::Variant::LCID = $Win32::OLE::LCID;
my $Fields = [qw(Day Open High Low Close)];
my $Values = [Variant(VT_DATE, $Day),
$Open, $High, $Low, $Close];
{
local $Win32::OLE::Warn = 0;
$Recordset->AddNew($Fields, $Values);
}
# Replace existing record
if (Win32::OLE->LastError) {
$Recordset->CancelUpdate;
$Recordset->Close;
$Recordset->Open(<<"SQL", $Connection, adOpenDynamic);
SELECT * FROM $Contract
WHERE Day = #$Day#
SQL
$Recordset->Update($Fields, $Values);
}
$Recordset->Close;
$Connection->Close;
############################################################
print "Start Notes and send email\n";
sub EMBED_ATTACHMENT {1454;}
my $Notes = Win32::OLE->new('Notes.NotesSession');
my $Database = $Notes->GetDatabase('', '');
$Database->OpenMail;
my $Document = $Database->CreateDocument;
$Document->{Form} = 'Memo';
$Document->{SendTo} = ['Jon Orwant <orwant@media.mit.edu>',
'Jan Dubois <jan.dubois@ibm.net>'];
$Document->{Subject} = "US T-Bonds Chart for $Day";
my $Body = $Document->CreateRichtextItem('Body');
$Body->AppendText(<<"EOT");
I\'ve attached the latest US T-Bond data and chart for $Day.
The daily statistics were:
\tOpen\t$Open
\tHigh\t$High
\tLow\t$Low
\tClose\t$Close
Kind regards,
Mary
EOT
$Body->EmbedObject(EMBED_ATTACHMENT, '', $Filename);
#$Document->Send(0);
$Document->Save(0,0);
print "Done\n";
( run in 4.186 seconds using v1.01-cache-2.11-cpan-0b58ddf2af1 )