I am trying to figure out how to dump some data files I have into a database and I have never tried to do this before. so if I am making a retarded mistake please take it easy on me.
so far i have read the data file into a hash, created a dsn and connected to my database using win32::odbc, I am not sure what I need to do next. I have several problems.
1) my data..(not quite what I wanted for some values, this is just a rough test so I am ok with not being 100% here)
2) order of the hash is reversed and I am not sure how to fix it.
$values, $key instead of the other way around.
and finally the sql, how do I insert using a hash?
here is my code so far..
use Win32::ODBC;
use DBI;
$DSN="Ptest";
$db = new Win32::ODBC("DSN=Ptest;UID=userid;PWD=password;");
if(!($db)){
print "Error connecting";
exit;
}
else
{
print "Hey you are connected \n";
}
my $file="data.txt";
my %hash=();
open(file,$file) or die;
{
local $/ = undef;
%hash = split /\,/,<file>;
$sqlstatement="Insert '$value->{0}' into dbo.Results";
while ( my ($key, $value) = each(%hash) ){
print "$value => $key\n";
if($db->SQL($sqlstatement)){
print "abysmal failure try again";
}
close file;
---Data---Sample of data--
1/5/2009 3:55:30 PM,Login,18.490683,SearchLoad,15.012853,SearchCount,0
+:0.392878,SearchResults,16.048765,SearchSave,6.629372,SearchDelete,9.
+614098,SearchDetails,4.587307,TaxLoad,5.215133,TaxResults,0:2.956125,
+TaxDetails,5.226226,ClientAdd,4.834234,CMALoad,1.841135,CMASave,12.44
+1073,CMADelete,0.218266,ClientDelete,0.268565,Logout,0.822440,1/5/200
+9 5:04:39 PM,Login,12.841120,SearchLoad,5.733201,SearchCount,0:0.1874
+62,SearchResults,6.998567,SearchSave,1.812129,SearchDelete,0.906065,S
+earchDetails,4.108532,TaxLoad,2.343270,TaxResults,0:2.765057,TaxDetai
+ls,2.468244,ClientAdd,1.593423,CMALoad,1.655911,CMASave,8.092093,CMAD
+elete,0.187461,ClientDelete,0.187461,Logout,0.781090
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.