I've gotten some good feedback here and through email on my DBIx::Pretty module; the basics are fine, but I want to expand it to be extendable (see Scope of a Module?), and to handle a few more data types. I want to pass some ideas through PM as the changes are significant enough that I only want to program the bulk of this once.

First and foremost, I'm not trying to abstract away SQL; DBIx::Pretty is meant to be a cleaner SQL-in-code as opposed to replacing it. That is, DBIx::Pretty is to SQL as HTML::Template (and friends) is to HTML.

Secondly, DBIx::Pretty was renamed from DBI::Pretty due to the naming convention in the DBI:: module tree; that is, only DBI and it's directly database glue should go here, any DBI extentions should go to DBIx::.

The main goal of DBIx::Pretty is to assign names to SQL statements, then be able to call those SQL statements directly through their name in an AUTOLOAD manner; in addition, there's some variable substituion that can go on in the SQL statement for placeholders as well as other variable parts of the SQL statement. You can see more details in my original code.

Now, there are two areas that I'm trying to improve on:

First is the actually extensibility. The way I will set this up is to have DBIx::Pretty, then several subclasses, the default being DBIx::Pretty::Hash. In D:P, the three key functions than any subclass should override in my current scheme are:

The idea is that there can be static or dynamic SQL bindings. In static cases, the SQL is loaded and preparsed, with the preparse data going into an internal cache. In dynamic cases where the SQL might change, the subclass can have, for that sql, return in get_sql_properties some flag that indicates that the sql statement should be processed, but the preprocessing data is not cache and dumped away.

The suclasses are free to define additional methods; for example, I know that D:P:Hash will also have add_sql and remove_sql calls that add to it.

The second aspect is the variable interpolation. As I have it now, there's two types of variables:

I'm thinking of adding two more types: As an example of all this working together, I could define a meta-SQL set of statements as:
query => SELECT $fields FROM $table WHERE #conditions age_check => age > ?age gender_check => gender LIKE ?gender ... # actual call... $dbixprettyobj -> query ( { conditions=>"&age_check AND &gender_check", age=>18, gender=>'M', fields=> "name, id", table=>users } );

In addition, I'm considering allowing variables to have at least one addition field, that is associated with the variable in question by appending ":value" to it. The value that follows would be the default value for that variable if it is not defined in the hash that is passed to the AUTOLOAD function. So, in the above, if I has "?age:18", then if I didn't pass an age field in the hash, the code would automatically plug in 18 there.

From the coding standpoint, I know there's a lot here with regards to checking and the like (for example, avoiding infinite recursion loops in the inclusion/sql-statement variable types), but I'm more interested from here on commentary on how the user's interface is laid out. Do the variable types make sense and am I missing anything obvious that might interfere with typical SQL statements?

-----------------------------------------------------
Dr. Michael K. Neylon - mneylon-pm@masemware.com || "You've left the lens cap of your mind on again, Pinky" - The Brain

Replies are listed 'Best First'.
Re: Open for suggestions on DBIx::Pretty
by pmas (Hermit) on Jul 19, 2001 at 17:20 UTC
    My advice will be to name your functions more consistently, like: get_sql_stored, get_sql_statement, get_sql_properties, etc.
    Or, if you use object syntax, you may want to skip 'get_' part of the name altogether.

    Just my $0.02.

    pmas
    To make errors is human. But to make million errors per second, you need a computer.

Re: Open for suggestions on DBIx::Pretty
by tonyday (Scribe) on Jul 20, 2001 at 04:38 UTC
    I am wondering how the module will go about doing a straight $dbi->do() for some statements rather than a prepare/execute two-step. Will it know through a get_sql_properties call?

    tonyday