Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7170241
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:10:17+00:00 2026-05-28T15:10:17+00:00

Over the years, I’ve noticed a few issues with SQL queries in Perl scripts:

  • 0

Over the years, I’ve noticed a few issues with SQL queries in Perl scripts:

  • They’re hard to read
  • Most developers aren’t really that good with SQL.

Let’s say I have the following tables:

PET          PET_TYPE     COLOR
========     ==========   ============
PET_ID       PET_TYPE     COLOR_ID
Name         Description  Description
Owner
PET_TYPE
COLOR_ID

And, I want to find all the red dogs, I’ll have to produce the following SQL query.

FIND PET_ID, Name, Owner
FROM PET, PET_TYPE, COLOR
WHERE COLOR_ID.Description = 'RED'
      AND PET_TYPE.Description = 'DOG'
      AND PET.COLOR_ID = COLOR.COLOR_ID
      AND PET.PET_TYPE = PET_TYPE.PET_TYPE

I would like a Perl module that would simplify producing the querying. Something that will allow me to create the database connection, then predefine how the tables are linked. Once that is done, all developer have to do is a simplified query.

I imagine an interface as something like this:

  #
  # Create a new Database Connection
  #

  my $db = Some:Module->new(\%options);

  #
  # Now describe how these tables relate to each other.
  # It should be possible to reuse this information for
  # multiple queries. Maybe even make this a subroutine
  # or company wide Perl module that will do this for
  # the developer.
  #
  $db->link_tables (
       PET   => "COLOR_ID",
       COLOR => "COLOR_ID
  );

  $db->link_tables (
      PET      => "PET_TYPE",
      PET_TYPE => "PET_TYPE",
  );

  #
  # Now that you've created a link to the database,
  # and you've describe how the tables relate to
  # each other, let's create a query. I'm not 100%
  # sure of the interface, but it'll be something
  # like this. There might be multiple `query`
  # statements.
  #

  my $query = $db->query (
     PET_TYPE => "Description = DOG",
     COLOR    => "Description = RED"
  );

  #
  # Now, execute this query
  # 
  $db->execute_query;

  while (%row = $db->fetch) {
     say "Dog's name is $row{Pet.Name}";
     say "The owner is $row{Pet.Owner}";
  }
  #
  # Let's find all cats named Wiskers.
  # We've already described the links,
  # so that doesn't have to be redone.
  #
  my $query = $db->query (
     PET_TYPE => "Description = CAT",
     PET      => "Name = Wiskers"
  );

I know my description is incomplete, and no matter how complete the module, there has to be some emergency escape hatch where you can do a raw SQL query. However, the idea is to concentrate the program on what you want (I want red dogs or cats named whiskers) instead of the various fields and spending most of the Where clause on describing the links between tables. That would make it easier to program and easier to understand the program.

If there is no such module that does this, I’ll produce one. However, before spending a few weeks on this endeavor, I want to make sure I’m not duplicating any work.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T15:10:18+00:00Added an answer on May 28, 2026 at 3:10 pm

    I think what you are looking for is an ORM, and there are plenty of those. While not exactly what you are describing, it comes pretty close in functional terms. Have a look at Class::DBI and DBIx::Class, or just google for perl ORMs.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Over the years most web developers will have built an arsenal of tools or
I've been a software developer for over twenty years, programming in C, Perl, SQL,
Over the years I have slowly developed a regular expression that validates most email
Over the years, I've discovered that green-programmers tend to read the comments rather than
Over the years I have noticed the 'wildcard' variable in various bits and pieces
Over the years I've often asked myself why game developers place many small images
Over the years I have had a few of the websites I have developed
Our clients use SQLServer/Oracle databases. Over the years, we've sent them many update scripts
I'm working on an MFC application, that got pretty messy over years and over
Over the years as I have gone through school and been working in the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.