I wrote SQL::Generator some time ago. But nobody uses it, except me. Its the approach to have the SQL syntax somehow functional to perl. Example:
DESCRIPTION
  A very simple example. It instanciates the generator and creates some
  example output, which could be simply piped to an mysql database for
  testing (be careful if tables/database name is existing. I guess not !).

CODE
  my $table = 'sql_statement_construct_generator_table';

  my $database = 'sql_statement_construct_generator_db';

  my %types = ( row1 => 'VARCHAR(10) AUTO_INCREMENT PRIMARY KEY',

          row2 => 'INTEGER',

          row3 => 'VARCHAR(20)'
  );

  my %columns = ( row1 => '1', row2 => '2', row3 => '3' );

  my %alias = ( row1 => 'Name', row2 => 'Age', row3 => 'SocialID' );

          my $sql = new SQL::Generator(

                  LANG => 'MYSQL',

                  post => ";\n",

                  history => 1,

                  autoprint => 0,

                  prettyprint => 0

          ) or die 'constructor failed';

          $sql->CREATE( DATABASE => $database );

          $sql->USE( DATABASE => $database );

          $sql->CREATE( COLS => \%types, TABLE => $table );

          $sql->DESCRIBE( TABLE => $table );

          $sql->INSERT(

                  COLS =>  keys %columns ,

                  VALUES =>  values %columns ,

                  INTO => $table

                  );

          foreach (keys %columns) { $columns{$_}++ }

          $sql->INSERT( SET => \%columns , INTO => $table );

          foreach (keys %columns) { $columns{$_}++ }

          $sql->REPLACE(

                  COLS =>  keys %columns ,

                  VALUES =>  values %columns ,

                  INTO => $table,

                  );

          $sql->SELECT( ROWS => '*', FROM => $table );

          $sql->SELECT( ROWS =>  keys %types , FROM => $table );

          $sql->SELECT(

                  ROWS =>  \%alias,

                  FROM => $table,

                  WHERE => 'row1 = 1 AND row3 = 3'

                  );

          $sql->DROP( TABLE => $table );

          $sql->DROP( DATABASE => $database );

          # evocate an errormsg

          print "\nDumping sql script:\n\n";

          for( $sql->HISTORY() )
          {
                  printf "%s", $_;
          }

OUTPUT

CREATE DATABASE sql_statement_construct_db; 

USE sql_statement_construct_db; 

CREATE TABLE sql_statement_construct_table (
 row1 VARCHAR(10) AUTO_INCREMENT PRIMARY KEY, 
 row2 INTEGER, 
 row3 VARCHAR(20) 
); 

DESCRIBE sql_statement_construct_table; 

INSERT INTO sql_statement_construct_table ( row1, row2, row3 ) VALUES( 1, 2, 3 );

INSERT INTO sql_statement_construct_table SET row1='2', row2='3',
row3='4'; 

REPLACE INTO sql_statement_construct_table ( row1, row2, row3
) VALUES( 3, 4, 5 ); 

SELECT * FROM sql_statement_construct_table; 

SELECT row1, row2, row3 FROM sql_statement_construct_table; 

SELECT row1 AS 'Name', row2 AS 'Age', row3 AS 'SocialID' FROM sql_statement_construct_table WHERE row1 = 1 AND row3 = 3; 

DROP TABLE sql_statement_construct_table; 

DROP DATABASE sql_statement_construct_db;
BE WARNED: The documentation isn't that deep. You can do a lot, but its not documented. The 'AUTOLOAD' feature lets you skip the oo-interface. BTW: Currently its very msql-centric. Good Luck, Murat

In reply to Re: How do Monks programatically construct SQL selects by Anonymous Monk
in thread How do Monks programatically construct SQL selects by Cody Pendant

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.