in reply to Re: Mysql templates
in thread Mysql templates

Basically a template is a file that contains one or more distinct statements ending with a ";"... at least that's what is being used by this reporting program.

In this file it would contain...

optimize table test; select * from test;

Replies are listed 'Best First'.
Re^3: Mysql templates
by graff (Chancellor) on Nov 09, 2005 at 05:07 UTC
    So the only "tricky" part is to be able to say, for each operation within a template file, whether it needs to be handled via "do", or via "fetch" -- which might not be all that tricky, really, because the latter type will generally start with "select" (or "describe", or "show") as the first word of the statement.

    In general, you just need to split the template on semicolons (though there is the obvious -- though perhaps unlikely -- risk that a semicolon might appear as data within one of the operations, meaning you have to be careful about how you do the split.

    If the files are consistently formatted as you showed in this brief example (each distinct operation / statement is on a separate line, so that statements are separated by ";\n"), then splitting is much simpler -- you could even set your input record separator like this:  $/ = ";\n"; so that you read one statement at a time from the template, check what sort of statement it is, and pass it to the appropriate DBI method.

      Well I ended up just coding in a seperate prepare/execute statement for each one. It turns out it was less work to just copy and paste than to read the template with special code... Maybe :-(

      Thanks for the help.