I've been using DBI + SQL::Abstract for a lot of stuff, and one of the things I need to do now is generate concrete SQL scripts. For example, SQL::Abstract makes converting a hash into an insert extremely simple:

my $dbh = DBI->connect(@params); my $gen = SQL::Abstract->new; my ($insert, @bind) = $gen->insert(atable=>{a=>undef,b=>1,c=>'string'} +); my $sth = $dbh->prepare($insert); $sth->execute(@bind); __END__ $insert eq "INSERT INTO atable ( a, b, c) VALUES ( ?, ?, ? )" @bind contains undef, 1, "string"

But, now I have an occasion where I need to get parameter-free SQL to execute in a (My)SQL script. E.g., given the above example, I'd like to turn $insert and @bind back into:

INSERT INTO atable ( a, b, c) VALUES ( NULL, 1, 'string' )

Part of the problem is terminology. The only keywords I can think of { SQL, literal, abstract, bind, parameters, quoting } all get tons of results in the direction I've been using SQL::Abstract. (That is: ways to use tools like DBI that promote the use of placeholders, etc.)

I'm wondering whether there's a DBD driver that will do this. (e.g. change the connect string to something like 'DBI:fakesql:dialect=mysql', where 'fakesql' is the module I'm unable to find) Or is there another tool that I'm overlooking?


In reply to Concrete SQL from SQL::Abstract? by benizi

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.