[RFC] SQL::QueryManager

From: Michael B (mbarn_at_cidr.jhmi.edu)
Date: 11/13/04

  • Next message: http://tinyurl.com/6r9ez: "Re: any useful information leading to the arrest of matt parker will be rewarded"
    Date: 12 Nov 2004 16:20:22 -0800
    
    

    This is an RFC for the proposed module SQL::QueryManager

    NAME

    SQL::QueryManager - An Object-Oriented DBM::Deep based SQL Query
    Manager

    SYNOPSIS

    use SQL::QueryManager;

    $qm = SQL::QueryManager->new(
        -v => 1,
        -sql_query_file => '/path/to/file.db'
    );

    # Add a query
    $qm->add_query( 'name_query',
        qq[
          SELECT firstname, lastname
          FROM names
          WHERE lastname = 'XXX'
         ]);

    # Get a query
    $query = $qm->get_query( 'query_name' );

    # Get query and set bind variable(s)...
    foreach $last_name (@last_names) {
        $query = prepare_dynamic_query( 'name_query', 'XXX', $last_name );
    }

    # 'Inline' query retrieval and database call using DBI
    foreach $last_name (@last_names) {
        $sth = $dbh->prepare(
            $qm->prepare_dynamic_query('name_query', 'XXX', $last_name)
        );
        $sth->execute();
        while ( @array = $sth->fetchrow_array() ) {
            #...do something
        }
    }

    DESCRIPTION

    This module is designed to allow for storage and retrieval of SQL
    queries in a central repository. It uses an implementation of Joseph
    Huckaby's DBM::Deep, a pure Perl multi-level hash/array DBM to store
    and retrieve SQL queries. This allows for easy programmatic retrieval
    of common queries without having to cut and paste or (worst of all)
    re-code the queries every time you need them. Support is also provided
    for dynamic queries where bind variable(s) in the 'WHERE' clause
    is/are unknown. This module is useful for grouping database queries
    by project and/or function. It is most useful in large projects with
    somewhat complex queries. It is designed so that no limitations apply
    on what databases it can interact with. If there is a DBD::(database)
    module, this software will work with it, as the SQL is supplied by the
    user. It was
    written to be a container to help manage SQL queries in a central
    location, eliminating the need to hunt for the particular .sql file
    needed, which can become unruly in a project with hundreds or
    thousands of separate queries. Of
    course, one still needs to keep track of the query names, but this is
    easily accomplished with a central population script that contains all
    of the project's queries inside of the $qm->add_query('name','query')
    calls.

    I wrote it to fill the niche between full-blown SQL Query-Generation
    modules and
    managing thousands of .sql files by hand. The former was too complex
    for my
    needs and the latter was a frightening prospect.

    Michael Barnhart mbarn_at_cidr_dot_jhmi_dot_edu

    CIDR, JHU SOM
    Baltimore, Md.


  • Next message: http://tinyurl.com/6r9ez: "Re: any useful information leading to the arrest of matt parker will be rewarded"

    Relevant Pages

    • Re: Official Status of SQLServer 2005 ADP
      ... I have said that the support for SQL passthrough ... queries under MDB was bad and worst than the one offered by ADP while you ... > attempt to "pass through" every Access query against a linked ODBC ...
      (microsoft.public.access.adp.sqlserver)
    • Re: "Query Too Complex" Errors
      ... few dozens of queries, in the middle of which there's a long chain of ... we've been having a lot of those "Query Too ... some of the complexity in the SQL ... SQL statement you are working on. ...
      (microsoft.public.access.forms)
    • Re: Dynamic query problem
      ... On Oct 17, 9:41 am, Andy Hull ... If we were to provide a fully featured dynamic query generator we would have ... Provided with already built queries which they can edit ... SQL and see where it is the same as for the other queries and where it ...
      (microsoft.public.access.queries)
    • Re: CONTAINS performance
      ... mark, FTS needs to be very carefully tuned to achieve second response times, ... see SQL Server 2000 BOL title "Full-text Search Recommendations" for more ... When you include the "TOP 100" in your query, you are in fact limiting the ... valid for SQL queries, they often do not apply to FTS queries because the FT ...
      (microsoft.public.sqlserver.fulltext)
    • Re: Populating a list -- learning Access
      ... It is kinda funny -- I started using databases in the early 80's with dBase and, for years, never knew that I knew SQL! ... If you are on a form or report, the most important property is the NAME, because that is how you refer to it in code. ... I don't mean to skip your responce below, but thanks to your help with SQL, I was able to get the query to pull the info the way I needed. ... Queries (just shows the QBE grid for convenience -- ...
      (microsoft.public.access.forms)