Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (5)
As of 2024-03-28 16:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found