Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: How to read batches of SQL from a file in Perl

by mpeppler (Vicar)
on Aug 29, 2007 at 11:25 UTC ( [id://635770]=note: print w/replies, xml ) Need Help??


in reply to How to read batches of SQL from a file in Perl

You can also make the iterator a little simpler by changing the record separator:
local $/="\ngo\n"; while(<IN>) { chomp; # now the entire statement is in $_... ... execute the SQL statement, with error checking, etc. }
The disadvantage is that $/ can't be a regex, so you can't handle upper/lower case, for example.

Michael

Replies are listed 'Best First'.
Re^2: How to read batches of SQL from a file in Perl
by KurtSchwind (Chaplain) on Oct 25, 2007 at 02:05 UTC
    Wouldn't it be nicer and more flexible to allow people to specify the seperator? I like the idea of essentially slurping the files in and specifying the break as a NEWLINEgoNEWLINE as you did, but I think that a semi-colon is more common.

    I realize that the stated assumption was that the statements end with a 'go', but it would be such a minor change to make it so much more flexible.

      A similar module is SQL::Script, which seems like a good idea (and it has the separator :)

      The default for Sybase isql scripts is to end with "go", so it makes sense to do it this way.

      Other separators can of course be used - it all depends on what your purpose is.

      Michael

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://635770]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (2)
As of 2024-04-25 20:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found