Beefy Boxes and Bandwidth Generously Provided by pair Networks vroom
Syntactic Confectionary Delight
 
PerlMonks

Mixing Perl and SQL

by toma (Vicar)
 | Log in | Create a new user | The Monastery Gates | Super Search | 
 | Seekers of Perl Wisdom | Meditations | PerlMonks Discussion | 
 | Obfuscation | Reviews | Cool Uses For Perl | Perl News | Q&A | Tutorials | 
 | Poetry | Recent Threads | Newest Nodes | Donate | What's New | 

on Nov 04, 2009 at 04:38 UTC ( #804840=perlquestion: print w/ replies, xml ) Need Help??
toma has asked for the wisdom of the Perl Monks concerning the following question:

I have been doing more with SQL lately, and I have lots of SQL code to run from Perl using DBI. There is so much of it that lately I prefer to have the SQL code in a separate file from my Perl, because the vim editor highlights the SQL and Perl syntax correctly, based on the filename. However, I think this makes a module that uses the SQL file harder to deploy, because the Perl code has to find the SQL file based on where it was installed by the module.

I can think of several approaches to fixing this. One would be to fix my editor so that all 'here docs' are interpreted as SQL, or to learn some new trick about paths and module installation. Or likely there is an even a better approach that I haven't thought of.

Suggestions, perl lang vimrc patches, perl module tricks all welcome! Thanks.

It should work perfectly the first time! - toma

Comment on Mixing Perl and SQL
Re: Mixing Perl and SQL
by happy.barney (Sexton) on Nov 04, 2009 at 08:11 UTC
    look at %INC
    use Class::Date; print $INC{'Class/Date.pm'};
[reply]
[d/l]
      This works fine, thanks!

      If anyone else has other ideas, I will try those, also.

      It should work perfectly the first time! - toma
[reply]
Re: Mixing Perl and SQL
by metaperl (Deacon) on Nov 04, 2009 at 16:07 UTC
    Do you envision one SQL file per module?
[reply]
      Some modules use one file per module. It would be nice if it was possible to have more, unless there is some benefit to keeping it 1:1.

      If there is a reason to do so, please assume that I can split up my Perl modules so that there is at most one file per module.

      It should work perfectly the first time! - toma
[reply]
Re: Mixing Perl and SQL
by mje (Pilgrim) on Nov 04, 2009 at 17:11 UTC

    This does not strictly answer your question but it works well for us and you might find it useful. The ONLY SQL we have in our application is:

    begin synonym.proc_name(?, ? ....); end; begin ? := synonym.func_name(?, ?, ...); end;

    All the SQL is in procedures and functions in the database - including those that simply return a result-set. This allows us to keep all the logic in the database. Of course you can only do this if your DBD and database supports procedures and the returning of reference cursors which DBD::Oracle and Oracle does.

[reply]
[d/l]
      My code has to create the whole database from scratch, so I would need to include the SQL code that creates the stored procedures, and therefore I think I would be left with the same mixed-language issue.

      For example, one of my programs first uses modules to transform the input data from several formats into flat files. Then it uses modules that include the SQL to:

      1. Create an empty database with tables and views.
      2. Load the data from flat files.
      3. Transform the data into another set of tables that use a different indexing scheme.
      4. Query the data to generate a report.

      It should work perfectly the first time! - toma
[reply]

Back to Seekers of Perl Wisdom


Login:
Password
remember me
What's my password?
Create A New User

Node Status
node history
Node Type: perlquestion [id://804840]
Approved by wfsp
Front-paged by wfsp
help
Community Ads
Chatterbox
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users
Others lurking in the Monastery: (9)
Moriarty
atcroft
herveus
ctilmes
Eyck
Gangabass
AnomalousMonk
baxy77bax
gnosti
As of 2009-11-21 11:16 GMT
Sections
The Monastery Gates
Seekers of Perl Wisdom
Meditations
PerlMonks Discussion
Categorized Q&A
Tutorials
Obfuscated Code
Perl Poetry
Cool Uses for Perl
Perl News
Information
PerlMonks FAQ
Guide to the Monastery
What's New at PerlMonks
Voting/Experience System
Tutorials
Reviews
Library
Perl FAQs
Other Info Sources
Find Nodes
Nodes You Wrote
Super Search
List Nodes By Users
Newest Nodes
Recently Active Threads
Selected Best Nodes
Best Nodes
Worst Nodes
Saints in our Book
Leftovers
The St. Larry Wall Shrine
Offering Plate
Awards
Craft
Snippets Section
Code Catacombs
Quests
Editor Requests
Buy PerlMonks Gear
PerlMonks Merchandise
Planet Perl
Perlsphere
Use Perl
Perl.com
Perl 5 Wiki
Perl Jobs
Perl Mongers
Perl Directory
Perl documentation
CPAN
Random Node
Voting Booth

Future historians will find that the material characteristic of the current era is...

Aluminium
Plastic
Oil
Water
Carbon dioxide
Copper
Iron
Silicon
Salt
Uranium
Hydrogen
Other

Results (730 votes), past polls