Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
You may want to try and download DBI, simply because it's good. But I'll try and give you some pointers with what you're using.

For one thing, you build the @statements array but you never actually use it! Is this a test version that you have here, or what? The data won't get into the database without you actually calling the insert statements on the db. From quickly scanning the docs, it looks like you'd call the "Sql" method for each of your insert statements. So:

for my $sql (@statements) { $db->Sql($sql); }
Another thing: if you have a file with comma-delimited fields, why aren't you split-ing each line of the file somehow? I highly doubt that you actually want to insert the comma-separated string into the database verbatim... do you?

With that in mind, you'll have to create a table in the database that reflects the layout of your comma-delimited file, so that you can split the line, then insert each field into its appropriate field in the db.

Also, in your SQL statements:

push @statement, "INSERT INTO UserTestingE (ID) VALUES (\t$_\n)";
Why do you have the "\t" and "\n" values? Do you actually want those in your db fields? Also, you need to quote the value:
push @statement, "INSERT INTO UserTestingE (ID) VALUES ('\t$_\n')";
Else you'll get a SQL error, I think. W/r/t the quoting, you'd be better off using some built-in method to quote values (like built-in to Win32::ODBC), but I didn't see one when I looked at the docs.

In reply to RE: RE: Re: Reading from a file and writing the content into a database by btrott
in thread Reading from a file and writing the content into a database by Kiko

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (6)
As of 2024-04-19 10:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found